layer.js 30.4 KB
; !function (window, undefined) {
    "use strict"; var isLayui = window.layui && layui.define, $, win, ready = {
        getPath: function () {
            var js = document.scripts, script = js[js.length - 1], jsPath = script.src; for (var i = js.length - 1; i >= 0; i--) { if (js[i].src.indexOf('layer') != -1) { jsPath = js[i].src; break; } }
            if (script.getAttribute('merge')) return; return jsPath.substring(0, jsPath.lastIndexOf("/") + 1);
        }(), config: {}, end: {}, minIndex: 0, minLeft: [], type: ['dialog', 'page', 'iframe', 'loading', 'tips']
    }; var layer = {
        v: '3.0.1', ie: function () { var agent = navigator.userAgent.toLowerCase(); return (!!window.ActiveXObject || "ActiveXObject" in window) ? ((agent.match(/msie\s(\d+)/) || [])[1] || '11') : false; }(), index: (window.layer && window.layer.v) ? 100000 : 0, path: ready.getPath, config: function (options, fn) { options = options || {}; layer.cache = ready.config = $.extend({}, ready.config, options); layer.path = ready.config.path || layer.path; layer.lang = options.lang; typeof options.extend === 'string' && (options.extend = [options.extend]); if (ready.config.path) layer.ready(); if (!options.extend) return this; isLayui ? layui.addcss('modules/layer/' + options.extend) : layer.link('skin/' + options.extend); return this; }, link: function (href, fn, cssname) {
            if (!layer.path) return; var head = $('head')[0], link = document.createElement('link'); if (typeof fn === 'string') cssname = fn; var app = (cssname || href).replace(/\.|\//g, ''); var id = 'layuicss-' + app, timeout = 0; link.rel = 'stylesheet'; link.href = layer.path + href; link.id = id; if (!$('#' + id)[0]) { head.appendChild(link); }
            if (typeof fn !== 'function') return; (function poll() { if (++timeout > 8 * 1000 / 100) { return window.console && console.error('layer.css: Invalid'); }; parseInt($('#' + id).css('width')) === 1989 ? fn() : setTimeout(poll, 100); }());
        }, ready: function (callback) { var cssname = 'skinlayercss', ver = '1110'; isLayui ? layui.addcss('modules/layer/default/layer.css?v=' + layer.v + ver, callback, cssname) : layer.link('skin/default/layer.css?v=' + layer.v + ver, callback, cssname); return this; }, alert: function (content, options, yes) { var type = typeof options === 'function'; if (type) yes = options; return layer.open($.extend({ content: content, btn: "ok", yes: yes }, type ? {} : options)); }, confirm: function (content, options, yes, cancel) {
            var type = typeof options === 'function'; if (type) { cancel = yes; yes = options; }
            return layer.open($.extend({ content: content, btn: 'default', yes: yes, btn2: cancel }, type ? {} : options));
        }, msg: function (content, options, end) {
            var type = typeof options === 'function', rskin = ready.config.skin; var skin = (rskin ? rskin + ' ' + rskin + '-msg' : '') || 'layui-layer-msg'; var anim = doms.anim.length - 1; if (type) end = options; return layer.open($.extend({ content: content, time: 3000, shade: false, skin: skin, title: false, closeBtn: false, btn: false, resize: false, fullresize: false, end: end }, (type && !ready.config.skin) ? { skin: skin + ' layui-layer-hui', anim: anim } : function () {
                options = options || {}; if (options.icon === -1 || options.icon === undefined && !ready.config.skin) { options.skin = skin + ' ' + (options.skin || 'layui-layer-hui'); }
                return options;
            }()));
        }, load: function (icon, options) { return layer.open($.extend({ type: 3, icon: icon || 0, resize: false, fullresize: false, shade: 0.01 }, options)); }, tips: function (content, follow, options) { return layer.open($.extend({ type: 4, content: [content, follow], closeBtn: false, time: 3000, btn: false, shade: false, resize: false, fullresize: false, fixed: false, maxWidth: 210 }, options)); }
    }; var Lang = { 'zh-CN': { OK: "确定", CANCEL: "取消", INFORMATION: "信息" }, 'en': { OK: "Sure", CANCEL: "Cancel", INFORMATION: "Information" }, 'zh-TW': { OK: "確&#x5b9a", CANCEL: "取消", INFORMATION: "信息" } }; var Class = function (setings) { var that = this; that.index = ++layer.index; that.config = $.extend({}, that.config, ready.config, setings); document.body ? that.creat() : setTimeout(function () { that.creat(); }, 50); }; Class.pt = Class.prototype; var doms = ['layui-layer', '.layui-layer-title', '.layui-layer-main', '.layui-layer-dialog', 'layui-layer-iframe', 'layui-layer-content', 'layui-layer-btn', 'layui-layer-close']; doms.anim = ['layer-anim', 'layer-anim-01', 'layer-anim-02', 'layer-anim-03', 'layer-anim-04', 'layer-anim-05', 'layer-anim-06', 'layer-anim-07']; Class.pt.config = { type: 0, lang: "zh-CN", shade: 0.3, fixed: true, move: doms[1], offset: 'auto', area: 'auto', closeBtn: 1, time: 0, zIndex: 19891014, maxWidth: 360, anim: 0, moveType: 1, single: true, resize: true, fullresize: true, scrollbar: true, tips: 2, btn: 'default', icon: 'default' }; Class.pt.vessel = function (conType, callback) {
        var that = this, times = that.index, config = that.config; var isCustomZIndex = config.zIndex != 19891014; var zIndex = isCustomZIndex ? config.zIndex : config.zIndex + times, titype = typeof config.title === 'object'; var ismax = config.maxmin && (config.type === 1 || config.type === 2); var titstyle = titype ? (config.title[1] == 'center' ? 'text-align: center;' : config.title[1]) : ""; var titleHTML = (config.title ? '<div class="layui-layer-title ' + (config.icon ? 'layui-layer-icon-' + config.icon : '') + '" style="' + titstyle + '"><span>'
            + (titype ? config.title[0] : config.title)
            + '</span></div>' : ''); config.zIndex = zIndex; callback([config.shade ? ('<div class="layui-layer-shade" id="layui-layer-shade' + times + '" times="' + times + '" style="' + ('z-index:' + (zIndex - 1) + '; background-color:' + (config.shade[1] || '#000') + '; opacity:' + (config.shade[0] || config.shade) + '; filter:alpha(opacity=' + (config.shade[0] * 100 || config.shade * 100) + ');') + '"></div>') : '', '<div class="' + doms[0] + (' layui-layer-' + ready.type[config.type]) + (((config.type == 0 || config.type == 2) && !config.shade) ? ' layui-layer-border' : '') + ' ' + (config.skin || '') + " " + (config.className || '') + '" id="' + doms[0] + times + '" type="' + ready.type[config.type] + '" times="' + times + '" showtime="' + config.time + '" conType="' + (conType ? 'object' : 'string') + '" style="z-index: ' + zIndex + '; width:' + config.area[0] + ';height:' + config.area[1] + (config.fixed ? '' : ';position:absolute;') + '">'
                + (conType && config.type != 2 ? '' : titleHTML)
                + '<div id="' + (config.id || '') + '" class="layui-layer-content' + ((config.type == 0 && config.icon !== -1) ? ' layui-layer-padding' : '') + (config.closeBtn == 3 ? ' layeui-layer-inline-close' : '') + (config.type == 3 ? ' layui-layer-loading' + config.icon : '') + '">'
                + (config.type == 0 && config.icon !== -1 ? '<i class="layui-layer-ico layui-layer-ico-' + config.icon + '"></i>' : '')
                + (config.type == 1 && conType ? '' : (config.content || ''))
                + '</div>'
                + '<span class="layui-layer-setwin layui-layer-setback">' + function () { var backbtn = config.iframeBack && '<a class="layui-layer-ico layui-layer-back" href="javascript:;"></a>' || ''; return backbtn; }() + '</span>'
                + '<span class="layui-layer-setwin">' + function () {
                    var closebtn = ismax ? '<a class="layui-layer-ico layui-layer-min" href="javascript:;"></a><a class="layui-layer-ico layui-layer-max" href="javascript:;"></a>' : ''; config.refresh && (closebtn += '<a class="layui-layer-ico layui-layer-refresh" href="javascript:;">')
                    config.closeBtn && (closebtn += '<a class="layui-layer-ico ' + doms[7] + ' ' + doms[7] + (config.title ? config.closeBtn : (config.type == 4 ? '1' : '2')) + '" href="javascript:;"></a>'); return closebtn;
                }() + '</span>'
                + (config.btn ? function () {
                    var button = ''; typeof config.btn === 'string' && (config.btn = [config.btn]); for (var i = 0, len = config.btn.length; i < len; i++) { button += '<a class="' + doms[6] + '' + i + '">' + config.btn[i] + '</a>' }
                    return '<div class="' + doms[6] + ' layui-layer-btn-' + (config.btnAlign || 'c') + '">' + button + '</div>'
                }() : '')
                + (config.resize ? '<span class="layui-layer-resize"></span>' : '')
                + (config.fullresize ? function () {
                    var offset = ['top', 'right', 'bottom', 'left'], fullresize = ''; for (var i = 0, len = offset.length; i < len; i++) { fullresize += '<span class="layui-layer-fullresize layui-layer-' + offset[i] + '-resize" data-dir="' + offset[i] + '"></span>'; }
                    return fullresize;
                }() : '')
                + '</div>'], titleHTML, $('<div class="layui-layer-move"></div>')); return that;
    }; Class.pt.creat = function () {
        var that = this, config = that.config, times = that.index, nodeIndex, content = config.content, conType = typeof content === 'object', lang = Lang[config.lang], body = $('body'); if ($('#' + config.id)[0]) return; config.title = "title" in config ? config.title : lang.INFORMATION; if (typeof config.area === 'string') { config.area = config.area === 'auto' ? ['', ''] : [config.area, '']; }
        if (config.shift) { config.anim = config.shift; }
        if (layer.ie == 6) { config.fixed = false; }
        if (config.btn == 'default') { config.btn = [lang.OK, lang.CANCEL] }
        if (config.btn == 'ok') { config.btn = [lang.OK]; }
        switch (config.type) { case 0: config.btn = ('btn' in config) ? config.btn : lang.OK; config.single && layer.closeAll('dialog'); break; case 2: var content = config.content = conType ? config.content : [config.content || 'http://layer.layui.com', 'auto']; config.content = '<iframe scrolling="' + (config.content[1] || 'auto') + '" allowtransparency="true" id="' + doms[4] + '' + times + '" name="' + doms[4] + '' + times + '" onload="this.className=\'\';" class="layui-layer-load" frameborder="0" src="' + config.content[0] + '"></iframe>'; break; case 3: delete config.title; delete config.closeBtn; config.icon === -1 && (config.icon === 0); layer.closeAll('loading'); break; case 4: conType || (config.content = [config.content, 'body']); config.follow = config.content[1]; config.content = config.content[0] + '<i class="layui-layer-TipsG"></i>'; delete config.title; config.tips = typeof config.tips === 'object' ? config.tips : [config.tips, true]; config.tipsMore || layer.closeAll('tips'); break; }
        that.vessel(conType, function (html, titleHTML, moveElem) { body.append(html[0]); conType ? function () { (config.type == 2 || config.type == 4) ? function () { $('body').append(html[1]); }() : function () { if (!content.parents('.' + doms[0])[0]) { content.data('display', content.css('display')).show().addClass('layui-layer-wrap').wrap(html[1]); $('#' + doms[0] + times).find('.' + doms[5]).before(titleHTML); } }(); }() : body.append(html[1]); $('.layui-layer-move')[0] || body.append(ready.moveElem = moveElem); that.layero = $('#' + doms[0] + times); config.scrollbar || doms.html.css('overflow', 'hidden').attr('layer-full', times); }).auto(times); config.type == 2 && layer.ie == 6 && that.layero.find('iframe').attr('src', content[0]); config.type == 4 ? that.tips() : that.offset(); if (config.fixed) { win.on('resize', function () { that.offset(); (/^\d+%$/.test(config.area[0]) || /^\d+%$/.test(config.area[1])) && that.auto(times); config.type == 4 && that.tips(); }); }
        config.time <= 0 || setTimeout(function () { layer.close(that.index) }, config.time); config.type <= 2 && that.move().callback(); if (doms.anim[config.anim]) { that.layero.addClass(doms.anim[config.anim]).data('anim', true); };
    }; Class.pt.auto = function (index) {
        var that = this, config = that.config, layero = $('#' + doms[0] + index); if (config.area[0] === '' && config.maxWidth > 0) {
            if (layer.ie && layer.ie < 8 && config.btn) { layero.width(layero.innerWidth()); }
            layero.outerWidth() > config.maxWidth && layero.width(config.maxWidth);
        }
        var area = [layero.innerWidth(), layero.innerHeight()]; var titHeight = layero.find(doms[1]).outerHeight() || 0; var btnHeight = layero.find('.' + doms[6]).outerHeight() || 0; function setHeight(elem) { elem = layero.find(elem); elem.height(area[1] - titHeight - btnHeight - 2 * (parseFloat(elem.css('padding')) | 0)); }
        switch (config.type) {
            case 2: setHeight('iframe'); break; default: if (config.area[1] === '') { if (config.fixed && area[1] >= win.height()) { area[1] = win.height(); setHeight('.' + doms[5]); } } else { setHeight('.' + doms[5]); }
                break;
        }
        return that;
    }; Class.pt.offset = function () {
        var that = this, config = that.config, layero = that.layero; var area = [layero.outerWidth(), layero.outerHeight()]; var type = typeof config.offset === 'object'; that.offsetTop = (win.height() - area[1]) / 2; that.offsetLeft = (win.width() - area[0]) / 2; if (type) { that.offsetTop = config.offset[0]; that.offsetLeft = config.offset[1] || that.offsetLeft; } else if (config.offset !== 'auto') { if (config.offset === 't') { that.offsetTop = 0; } else if (config.offset === 'r') { that.offsetLeft = win.width() - area[0]; } else if (config.offset === 'b') { that.offsetTop = win.height() - area[1]; } else if (config.offset === 'l') { that.offsetLeft = 0; } else if (config.offset === 'lt') { that.offsetTop = 0; that.offsetLeft = 0; } else if (config.offset === 'lb') { that.offsetTop = win.height() - area[1]; that.offsetLeft = 0; } else if (config.offset === 'rt') { that.offsetTop = 0; that.offsetLeft = win.width() - area[0]; } else if (config.offset === 'rb') { that.offsetTop = win.height() - area[1]; that.offsetLeft = win.width() - area[0]; } else { that.offsetTop = config.offset; } }
        if (!config.fixed) { that.offsetTop = /%$/.test(that.offsetTop) ? win.height() * parseFloat(that.offsetTop) / 100 : parseFloat(that.offsetTop); that.offsetLeft = /%$/.test(that.offsetLeft) ? win.width() * parseFloat(that.offsetLeft) / 100 : parseFloat(that.offsetLeft); that.offsetTop += win.scrollTop(); that.offsetLeft += win.scrollLeft(); }
        if (layero.attr('minLeft')) { that.offsetTop = win.height() - (layero.find(doms[1]).outerHeight() || 0); that.offsetLeft = layero.css('left'); }
        layero.css({ top: that.offsetTop, left: that.offsetLeft });
    }; Class.pt.tips = function () {
        var that = this, config = that.config, layero = that.layero; var layArea = [layero.outerWidth(), layero.outerHeight()], follow = $(config.follow); if (!follow[0]) follow = $('body'); var goal = { width: follow.outerWidth(), height: follow.outerHeight(), top: follow.offset().top, left: follow.offset().left }, tipsG = layero.find('.layui-layer-TipsG'); var guide = config.tips[0]; config.tips[1] || tipsG.remove(); goal.autoLeft = function () { if (goal.left + layArea[0] - win.width() > 0) { goal.tipLeft = goal.left + goal.width - layArea[0]; tipsG.css({ right: 12, left: 'auto' }); } else { goal.tipLeft = goal.left; }; }; goal.where = [function () { goal.autoLeft(); goal.tipTop = goal.top - layArea[1] - 10; tipsG.removeClass('layui-layer-TipsB').addClass('layui-layer-TipsT').css('border-right-color', config.tips[1]); }, function () { goal.tipLeft = goal.left + goal.width + 10; goal.tipTop = goal.top + follow.height() / 2 - 8 * 2; tipsG.removeClass('layui-layer-TipsL').addClass('layui-layer-TipsR').css('border-bottom-color', config.tips[1]); }, function () { goal.autoLeft(); goal.tipTop = goal.top + goal.height + 10; tipsG.removeClass('layui-layer-TipsT').addClass('layui-layer-TipsB').css('border-right-color', config.tips[1]); }, function () { goal.tipLeft = goal.left - layArea[0] - 10; goal.tipTop = goal.top + follow.height() / 2 - 8 * 2; tipsG.removeClass('layui-layer-TipsR').addClass('layui-layer-TipsL').css('border-bottom-color', config.tips[1]); }]; goal.where[guide - 1](); if (guide === 1) { goal.top - (win.scrollTop() + layArea[1] + 8 * 2) < 0 && goal.where[2](); } else if (guide === 2) { win.width() - (goal.left + goal.width + layArea[0] + 8 * 2) > 0 || goal.where[3]() } else if (guide === 3) { (goal.top - win.scrollTop() + goal.height + layArea[1] + 8 * 2) - win.height() > 0 && goal.where[0](); } else if (guide === 4) { layArea[0] + 8 * 2 - goal.left > 0 && goal.where[1]() }
        layero.find('.' + doms[5]).css({ 'background-color': config.tips[1], 'padding-right': (config.closeBtn ? '30px' : '') }); layero.css({ left: goal.tipLeft - (config.fixed ? win.scrollLeft() : 0), top: goal.tipTop - (config.fixed ? win.scrollTop() : 0) });
    }
    Class.pt.move = function () {
        var that = this, config = that.config, _DOC = $(document), layero = that.layero, moveElem = layero.find(config.move), resizeElem = layero.find('.layui-layer-resize, .layui-layer-fullresize'), dict = {}; if (config.move) { moveElem.css('cursor', 'move'); }
        moveElem.on('mousedown', function (e) { e.preventDefault(); if (config.move) { dict.moveStart = true; dict.offset = [e.clientX - parseFloat(layero.css('left')), e.clientY - parseFloat(layero.css('top'))]; ready.moveElem.css('cursor', 'move').show(); } }); resizeElem.on('mousedown', function (e) { var that = $(this), offset = layero.offset(); e.preventDefault(); dict.resizeStart = true; dict.el = that; dict.dir = that.data('dir'); dict.dirs = [offset.top, offset.left]; dict.offset = [e.clientX, e.clientY]; dict.area = [layero.outerWidth(), layero.outerHeight()]; that.css({ width: '100%', height: '100%' }); }); _DOC.on('mousemove', function (e) {
            if (dict.moveStart) {
                var X = e.clientX - dict.offset[0], Y = e.clientY - dict.offset[1], fixed = layero.css('position') === 'fixed'; e.preventDefault(); dict.stX = fixed ? 0 : win.scrollLeft(); dict.stY = fixed ? 0 : win.scrollTop(); if (!config.moveOut) { var setRig = win.width() - layero.outerWidth() + dict.stX, setBot = win.height() - layero.outerHeight() + dict.stY; X < dict.stX && (X = dict.stX); X > setRig && (X = setRig); Y < dict.stY && (Y = dict.stY); Y > setBot && (Y = setBot); }
                layero.css({ left: X, top: Y });
            }
            if (config.resize && dict.resizeStart) {
                var X = e.clientX - dict.offset[0], Y = e.clientY - dict.offset[1]; e.preventDefault(); layer.style(that.index, { width: dict.area[0] + X, height: dict.area[1] + Y })
                dict.isResize = true;
            }
            if (config.fullresize && dict.resizeStart) { var dir = dict.dir, isleft = dir == 'left', istop = dir == 'top', X = !istop && dir != 'bottom' ? e.clientX - dict.offset[0] : 0, Y = !isleft && dir != 'right' ? e.clientY - dict.offset[1] : 0; e.preventDefault(); X = isleft ? -X : X; Y = istop ? -Y : Y; layer.style(that.index, function () { var ob = { width: dict.area[0] + X, height: dict.area[1] + Y }; isleft && (ob.left = dict.dirs[1] - X); istop && (ob.top = dict.dirs[0] - Y); return ob; }()); dict.isResize = true; }
        }).on('mouseup', function (e) {
            if (dict.moveStart) { delete dict.moveStart; ready.moveElem.hide(); config.moveEnd && config.moveEnd(); }
            if (dict.resizeStart) { delete dict.resizeStart; ready.moveElem.hide(); dict.el.removeAttr('style'); }
        }); return that;
    }; Class.pt.callback = function () {
        var that = this, layero = that.layero, config = that.config; that.openLayer(); if (config.success) { if (config.type == 2) { layero.find('iframe').on('load', function () { config.success(layero, that.index); }); } else { config.success(layero, that.index); } }
        layer.ie == 6 && that.IE6(layero); layero = that.layero = $('#' + doms[0] + that.index); layero.find('.' + doms[6]).children('a').on('click', function (e) {
            var index = $(this).index(), $target = $(e.target); if (index === 0) {
                if (config.yes) {
                    if ($target.hasClass('disabled') || $target.hasClass("btn-loading")) return; if (config.loading) { $target.addClass("btn-loading"); }
                    var isdisabled = config.yes(that.index, layero, function () { config.loading && $target.removeClass("btn-loading"); $target.removeClass("disabled"); }); isdisabled !== false && $target.addClass('disabled');
                } else if (config['btn1']) { config['btn1'](that.index, layero) } else { layer.close(that.index); }
            } else { var close = config['btn' + (index + 1)] && config['btn' + (index + 1)](that.index, layero); close === false || layer.close(that.index); }
        }); function cancel() { var close = config.cancel && config.cancel(that.index, layero); close === false || layer.close(that.index); }
        layero.find('.' + doms[7]).on('click', cancel); $('#layui-layer-shade' + that.index).on('mousedown', function (e) { if (!config.shadeClose) return e.stopPropagation();; layer.close(that.index); }); layero.find('.layui-layer-min').on('click', function () { var min = config.min && config.min(layero); min === false || layer.min(that.index, config); }); layero.find('.layui-layer-max').on('click', function () { if ($(this).hasClass('layui-layer-maxmin')) { layer.restore(that.index); config.restore && config.restore(layero); } else { layer.full(that.index, config); setTimeout(function () { config.full && config.full(layero); }, 100); } }); layero.find('.layui-layer-refresh').on('click', function () { var iframe = layero.find('iframe')[0]; iframe && (iframe.src = iframe.src); }); config.iframeBack && layero.find('.layui-layer-back').on('click', function (e) { var iframe = layero.find('iframe')[0]; config.iframeBack(iframe); })
        config.end && (ready.end[that.index] = config.end);
    }; ready.reselect = function () {
        $.each($('select'), function (index, value) {
            var sthis = $(this); if (!sthis.parents('.' + doms[0])[0]) { (sthis.attr('layer') == 1 && $('.' + doms[0]).length < 1) && sthis.removeAttr('layer').show(); }
            sthis = null;
        });
    }; Class.pt.IE6 = function (layero) {
        $('select').each(function (index, value) {
            var sthis = $(this); if (!sthis.parents('.' + doms[0])[0]) { sthis.css('display') === 'none' || sthis.attr({ 'layer': '1' }).hide(); }
            sthis = null;
        });
    }; Class.pt.openLayer = function () { var that = this; layer.zIndex = that.config.zIndex; layer.setTop = function (layero) { var setZindex = function () { layer.zIndex++; layero.css('z-index', layer.zIndex + 1); }; layer.zIndex = parseInt(layero[0].style.zIndex); layero.on('mousedown', setZindex); return layer.zIndex; }; }; ready.record = function (layero) { var area = [layero.width(), layero.height(), layero.position().top, layero.position().left + parseFloat(layero.css('margin-left'))]; layero.find('.layui-layer-max').addClass('layui-layer-maxmin'); layero.attr({ area: area }); }; ready.rescollbar = function (index) {
        if (doms.html.attr('layer-full') == index) {
            if (doms.html[0].style.removeProperty) { doms.html[0].style.removeProperty('overflow'); } else { doms.html[0].style.removeAttribute('overflow'); }
            doms.html.removeAttr('layer-full');
        }
    }; window.layer = layer; layer.getChildFrame = function (selector, index) { index = index || $('.' + doms[4]).attr('times'); return $('#' + doms[0] + index).find('iframe').contents().find(selector); }; layer.getFrameIndex = function (name) { return $('#' + name).parents('.' + doms[4]).attr('times'); }; layer.iframeAuto = function (index) { if (!index) return; var heg = layer.getChildFrame('html', index).outerHeight(); var layero = $('#' + doms[0] + index); var titHeight = layero.find(doms[1]).outerHeight() || 0; var btnHeight = layero.find('.' + doms[6]).outerHeight() || 0; layero.css({ height: heg + titHeight + btnHeight }); layero.find('iframe').css({ height: heg }); }; layer.iframeSrc = function (index, url) { $('#' + doms[0] + index).find('iframe').attr('src', url); }; layer.style = function (index, options, limit) {
        var layero = $('#' + doms[0] + index), contElem = layero.find('.layui-layer-content'), type = layero.attr('type'), titHeight = layero.find(doms[1]).outerHeight() || 0, btnHeight = layero.find('.' + doms[6]).outerHeight() || 0, minLeft = layero.attr('minLeft'), isBorderBox = contElem.css('box-sizing') === 'border-box', height; if (type === ready.type[3] || type === ready.type[4]) { return; }
        if (!limit) { if (parseFloat(options.width) <= 260) { options.width = 260; options.left && (delete options.left); }; if (parseFloat(options.height) - titHeight - btnHeight <= 64) { options.height = 64 + titHeight + btnHeight; options.top && (delete options.top); }; }
        layero.css(options); btnHeight = layero.find('.' + doms[6]).outerHeight(); height = parseFloat(options.height) - titHeight - btnHeight; if (type === ready.type[2]) { layero.find('iframe').css({ height: height }); } else {
            if (!isBorderBox) {
                height = height - parseFloat(contElem.css('padding-top'))
                - parseFloat(contElem.css('padding-bottom'))
            }
            contElem.css({ height: height });
        }
    }; layer.min = function (index, options) {
        var layero = $('#' + doms[0] + index), titHeight = layero.find(doms[1]).outerHeight() || 0, left = layero.attr('minLeft') || (181 * ready.minIndex) + 'px', position = layero.css('position'); ready.record(layero); if (ready.minLeft[0]) { left = ready.minLeft[0]; ready.minLeft.shift(); }
        layero.attr('position', position); layer.style(index, { width: 180, height: titHeight, left: left, top: win.height() - titHeight, position: 'fixed', overflow: 'hidden' }, true); layero.find('.layui-layer-min').hide(); layero.attr('type') === 'page' && layero.find(doms[4]).hide(); ready.rescollbar(index); if (!layero.attr('minLeft')) { ready.minIndex++; }
        $('#layui-layer-shade' + index).hide(); layero.attr('minLeft', left);
    }; layer.restore = function (index) { var layero = $('#' + doms[0] + index), area = layero.attr('area').split(','); var type = layero.attr('type'); layer.style(index, { width: parseFloat(area[0]), height: parseFloat(area[1]), top: parseFloat(area[2]), left: parseFloat(area[3]), position: layero.attr('position'), overflow: 'visible' }, true); layero.find('.layui-layer-max').removeClass('layui-layer-maxmin'); layero.find('.layui-layer-min').show(); layero.attr('type') === 'page' && layero.find(doms[4]).show(); ready.rescollbar(index); $('#layui-layer-shade' + index).show(); }; layer.full = function (index) {
        var layero = $('#' + doms[0] + index), timer; ready.record(layero); if (!doms.html.attr('layer-full')) { doms.html.css('overflow', 'hidden').attr('layer-full', index); }
        clearTimeout(timer); timer = setTimeout(function () { var isfix = layero.css('position') === 'fixed'; layer.style(index, { top: isfix ? 0 : win.scrollTop(), left: isfix ? 0 : win.scrollLeft(), width: win.width(), height: win.height() }, true); layero.find('.layui-layer-min').hide(); }, 100);
    }; layer.title = function (name, index) { var title = $('#' + doms[0] + (index || layer.index)).find(doms[1]); title.html(name); }; layer.close = function (index) {
        var layero = $('#' + doms[0] + index), type = layero.attr('type'), closeAnim = 'layer-anim-close'; if (!layero[0]) return; var WRAP = 'layui-layer-wrap', remove = function () {
            if (type === ready.type[1] && layero.attr('conType') === 'object') {
                layero.children(':not(.' + doms[5] + ')').remove(); var wrap = layero.find('.' + WRAP); for (var i = 0; i < 2; i++) { wrap.unwrap(); }
                wrap.css('display', wrap.data('display')).removeClass(WRAP);
            } else {
                if (type === ready.type[2]) { try { var iframe = $('#' + doms[4] + index)[0]; iframe.contentWindow.document.write(''); iframe.contentWindow.close(); layero.find('.' + doms[5])[0].removeChild(iframe); } catch (e) { } }
                layero[0].innerHTML = ''; layero.remove();
            }
            typeof ready.end[index] === 'function' && ready.end[index](); delete ready.end[index];
        }; if (layero.data('anim')) { layero.addClass(closeAnim); }
        $('#layui-layer-moves, #layui-layer-shade' + index).remove(); layer.ie == 6 && ready.reselect(); ready.rescollbar(index); if (layero.attr('minLeft')) { ready.minIndex--; ready.minLeft.push(layero.attr('minLeft')); }
        setTimeout(function () { remove(); }, ((layer.ie && layer.ie < 10) || !layero.data('anim')) ? 0 : 200);
    }; layer.closeAll = function (type) { $.each($('.' + doms[0]), function () { var othis = $(this); var is = type ? (othis.attr('type') === type) : 1; is && layer.close(othis.attr('times')); is = null; }); }; var cache = layer.cache || {}, skin = function (type) { return (cache.skin ? (' ' + cache.skin + ' ' + cache.skin + '-' + type) : ''); }; layer.prompt = function (options, yes) {
        var style = ''; options = options || {}; if (typeof options === 'function') yes = options; if (options.area) { var area = options.area; style = 'style="width: ' + area[0] + '; height: ' + area[1] + ';"'; delete options.area; }
        var prompt, content = options.formType == 2 ? '<textarea class="layui-layer-input"' + style + '>' + (options.value || '') + '</textarea>' : function () { return '<input type="' + (options.formType == 1 ? 'password' : 'text') + '" class="layui-layer-input" value="' + (options.value || '') + '">'; }(); var lang = Lang[layer.lang]; return layer.open($.extend({
            type: 1, btn: [lang.OK, lang.CANCEL], content: content, skin: 'layui-layer-prompt' + skin('prompt'), maxWidth: win.width(), success: function (layero) { prompt = layero.find('.layui-layer-input'); prompt.focus(); }, resize: false, fullresize: false, yes: function (index) {
                var value = prompt.val(); if (value === '') { prompt.focus(); } else if (value.length > (options.maxlength || 500)) { layer.tips('&#x6700;&#x591A;&#x8F93;&#x5165;' + (options.maxlength || 500) + '&#x4E2A;&#x5B57;&#x6570;', prompt, { tips: 1 }); } else if (yes) { return yes(value, index, prompt); }
                return false;
            }
        }, options));
    }; ready.run = function (_$) { $ = _$; win = $(window); doms.html = $('html'); layer.open = function (deliver) { var o = new Class(deliver); return o.index; }; }; window.layui && layui.define ? (layer.ready(), layui.define('jquery', function (exports) { layer.path = layui.cache.dir; ready.run(layui.jquery); window.layer = layer; exports('layer', layer); })) : (typeof define === 'function' ? define(['jquery'], function () { ready.run(window.jQuery); return layer; }) : function () { ready.run(window.jQuery); layer.ready(); }());
}(window);