新增 layer 的 `hideOnClose` 属性,用于关闭时是否隐藏弹层

pull/1253/head
贤心 2 years ago
parent 81bab8942f
commit 4bf2fccafc

@ -265,13 +265,13 @@ Class.pt.config = {
offset: 'auto', offset: 'auto',
area: 'auto', area: 'auto',
closeBtn: 1, closeBtn: 1,
icon: -1,
time: 0, // 0 表示不自动关闭 time: 0, // 0 表示不自动关闭
zIndex: 19891014, zIndex: 19891014,
maxWidth: 360, maxWidth: 360,
anim: 0, anim: 0,
isOutAnim: true, // 退出动画 isOutAnim: true, // 退出动画
minStack: true, // 最小化堆叠 minStack: true, // 最小化堆叠
icon: -1,
moveType: 1, moveType: 1,
resize: true, resize: true,
scrollbar: true, // 是否允许浏览器滚动条 scrollbar: true, // 是否允许浏览器滚动条
@ -384,18 +384,38 @@ Class.pt.vessel = function(conType, callback){
// 创建骨架 // 创建骨架
Class.pt.creat = function(){ Class.pt.creat = function(){
var that = this var that = this;
,config = that.config var config = that.config;
,times = that.index, nodeIndex var times = that.index, nodeIndex;
,content = config.content var content = config.content;
,conType = typeof content === 'object' var conType = typeof content === 'object';
,body = $('body'); var body = $('body');
// 若 id 对应的弹层已经存在,则不重新创建
if(config.id && $('.'+ doms[0]).find('#'+ config.id)[0]){
return (function(){
var layero = $('#'+ config.id).closest('.'+ doms[0]);
var index = layero.attr('times');
var options = layero.data('config');
var elemShade = $('#'+ doms.SHADE + index);
var maxminStatus = layero.data('maxminStatus') || {};
// 若弹层为最小化状态,则点击目标元素时,自动还原
if(maxminStatus === 'min'){
layer.restore(index);
} else if(options.hideOnClose){
elemShade.show();
layero.show();
};
})();
};
if(config.id && $('.'+ doms[0]).find('#'+ config.id)[0]) return; // 是否移除活动元素的焦点
if(config.removeFocus) { if(config.removeFocus) {
document.activeElement.blur(); // 将原始的聚焦节点失焦 document.activeElement.blur(); // 将原始的聚焦节点失焦
} }
// 初始化 area 属性
if(typeof config.area === 'string'){ if(typeof config.area === 'string'){
config.area = config.area === 'auto' ? ['', ''] : [config.area, '']; config.area = config.area === 'auto' ? ['', ''] : [config.area, ''];
} }
@ -1153,6 +1173,9 @@ layer.close = function(index, callback){
}(); }();
var type = layero.attr('type'); var type = layero.attr('type');
var options = layero.data('config') || {}; var options = layero.data('config') || {};
var hideOnClose = options.id && options.hideOnClose; // 是否关闭时移除弹层容器
if(!layero[0]) return;
// 关闭动画 // 关闭动画
var closeAnim = ({ var closeAnim = ({
@ -1162,9 +1185,17 @@ layer.close = function(index, callback){
slideRight: 'layer-anim-slide-right-out' slideRight: 'layer-anim-slide-right-out'
})[options.anim] || 'layer-anim-close'; })[options.anim] || 'layer-anim-close';
if(!layero[0]) return; // 移除主容器
var remove = function(){
var WRAP = 'layui-layer-wrap';
// 是否关闭时隐藏弹层容器
if(hideOnClose){
layero.removeClass('layer-anim '+ closeAnim);
return layero.hide();
}
var WRAP = 'layui-layer-wrap', remove = function(){ // 是否为页面捕获层
if(type === ready.type[1] && layero.attr('conType') === 'object'){ if(type === ready.type[1] && layero.attr('conType') === 'object'){
layero.children(':not(.'+ doms[5] +')').remove(); layero.children(':not(.'+ doms[5] +')').remove();
var wrap = layero.find('.'+WRAP); var wrap = layero.find('.'+WRAP);
@ -1196,13 +1227,18 @@ layer.close = function(index, callback){
delete ready.events.resize[index]; delete ready.events.resize[index];
} }
}; };
// 移除遮罩
var removeShade = (function fn(){
$('#'+ doms.SHADE + index)[
hideOnClose ? 'hide' : 'remove'
]();
})();
// 是否允许关闭动画 // 是否允许关闭动画
if(options.isOutAnim){ if(options.isOutAnim){
layero.addClass('layer-anim '+ closeAnim); layero.addClass('layer-anim '+ closeAnim);
} }
$('#layui-layer-moves, #'+ doms.SHADE + index).remove();
layer.ie == 6 && ready.reselect(); layer.ie == 6 && ready.reselect();
ready.rescollbar(index); ready.rescollbar(index);

Loading…
Cancel
Save