/************************************************************** @Name: layer v1.7.0 弹层组件压缩版 @Author: 贤心 @Date: 2013-12-16 @Blog: http://sentsin.com @微博:http://weibo.com/SentsinXu @QQ群:176047238(一群)、218604143(若一群已满,可加此群) @Copyright: Sentsin Xu(贤心) @官网说明:http://sentsin.com/jquery/layer @赞助layer: https://me.alipay.com/sentsin *************************************************************/ ;!function(a,b){ "use strict"; var e,f,h,i, c=!0, //是否采用自动获取绝对路径。!1:将采用下述变量中的配置 d="lily/lib/layer/", //上述变量为false才有效,当前layerjs所在目录(不用填写host,相对站点的根目录即可)。 g = { hosts: function() { var a = location.href.match(/\:\d+/); return a = a ? a[0] : "", "http://" + document.domain + a + "/" } (), getPath: function() { var a = document.scripts || e("script"), b = a[a.length - 1].src; return c ? b.substring(0, b.lastIndexOf("/") + 1) : this.hosts + d } }; a.layer = { v: "1.7.0", ie6: !-[1, ] && !a.XMLHttpRequest, index: 0, path: g.getPath(), use: function(a, b) { var f, g, h, d = e("head")[0]; a = a.replace(/\s/g, ""), f = /\.css$/.test(a), g = document.createElement(f ? "link": "script"), h = a.replace(/\.|\//g, ""), f && (g.setAttribute("type", "text/css"), g.setAttribute("rel", "stylesheet")), g.setAttribute(f ? "href": "src", layer.path + a), g.setAttribute("id", h), e("#" + h)[0] || d.appendChild(g), e(g).ready(function() { b && b() }) }, ready: function(a) { return layer.use("skin/layer.css", a) }, alert: function(a, b, c, d) { return e.layer({ dialog: { msg: a, type: b, yes: d }, title: c, area: ["auto", "auto"] }) }, confirm: function(a, b, c, d) { return e.layer({ dialog: { msg: a, type: 4, btns: 2, yes: b, no: d }, title: c }) }, msg: function(a, c, d, f) { var g, h = { title: !1, closeBtn: !1 }; return ("" == a || a == b) && (a = " "), c === b && (c = 2), "number" == typeof d ? g = d: (d = d || {}, g = d.type, h.success = function() { layer.shift(d.rate) }, h.shade = d.shade), h.time = c, h.dialog = { msg: a, type: g }, h.end = "function" == typeof d ? d: f, e.layer(h) }, load: function(a, b) { return "string" == typeof a ? this.msg(a, 0, 16) : e.layer({ time: a, loading: { type: b }, bgcolor: b ? "#fff": "", shade: [.1, "#000", b ? !0 : !1], border: [7, .3, "#000", 3 !== b && b ? !0 : !1], type: 3, title: ["", !1], closeBtn: [0, !1] }) }, tips: function(a, b, c, d, f, g) { var h = { type: 4, shade: !1, success: function(a) { this.closeBtn || a.find(".xubox_tips").css({ "padding-right": 10 }) }, bgcolor: "", tips: { msg: a, follow: b } }; return c = c || {}, h.time = c.time || c, h.closeBtn = c.closeBtn || !1, h.maxWidth = c.maxWidth || d, h.tips.guide = c.guide || f, h.tips.style = c.style || g, e.layer(h) } }, h = function(a) { var b = this.config; layer.index++, this.index = layer.index, this.config = e.extend({}, b, a), this.config.dialog = e.extend({}, b.dialog, a.dialog), this.config.page = e.extend({}, b.page, a.page), this.config.iframe = e.extend({}, b.iframe, a.iframe), this.config.loading = e.extend({}, b.loading, a.loading), this.config.tips = e.extend({}, b.tips, a.tips), this.creat() }, h.pt = h.prototype, h.pt.config = { type: 0, shade: [.3, "#000", !0], shadeClose: !1, fix: !0, move: [".xubox_title", !0], moveOut: !1, title: ["信息", !0], offset: ["200px", "50%"], area: ["310px", "auto"], closeBtn: [0, !0], time: 0, bgcolor: "#fff", border: [8, .3, "#000", !0], zIndex: 19891014, maxWidth: 400, dialog: { btns: 1, btn: ["确定", "取消"], type: 3, msg: "", yes: function(a) { layer.close(a) }, no: function(a) { layer.close(a) } }, page: { dom: "#xulayer", html: "", url: "" }, iframe: { src: "http://sentsin.com" }, loading: { type: 0 }, tips: { msg: "", follow: "", guide: 0, isGuide: !0, style: ["background-color:#FF9900; color:#fff;", "#FF9900"] }, success: function() {}, close: function(a) { layer.close(a) }, end: function() {} }, h.pt.type = ["dialog", "page", "iframe", "loading", "tips"], h.pt.space = function(a) { var b, c, d, e, f, g, h, i, j, k, l, m, n, o; return a = a || "", b = this.index, c = this.config, d = c.dialog, e = this.dom, f = -1 === d.type ? "": '<span class="xubox_msg xulayer_png32 xubox_msgico xubox_msgtype' + d.type + '"></span>', g = ['<div class="xubox_dialog">' + f + '<span class="xubox_msg xubox_text" style="' + (f ? "": "padding-left:20px") + '">' + d.msg + "</span></div>", '<div class="xubox_page">' + a + "</div>", '<iframe allowtransparency="true" id="' + e.ifr + b + '" name="' + e.ifr + b + '" onload="$(this).removeClass(\'xubox_load\');" class="' + e.ifr + '" frameborder="0" src="' + c.iframe.src + '"></iframe>', '<span class="xubox_loading xubox_loading_' + c.loading.type + '"></span>', '<div class="xubox_tips" style="' + c.tips.style[0] + '"><div class="xubox_tipsMsg">' + c.tips.msg + '</div><i class="layerTipsG"></i></div>'], h = "", i = "", j = c.zIndex + b, k = "z-index:" + j + "; background-color:" + c.shade[1] + "; opacity:" + c.shade[0] + "; filter:alpha(opacity=" + 100 * c.shade[0] + ");", c.shade[2] && (h = '<div times="' + b + '" id="xubox_shade' + b + '" class="xubox_shade" style="' + k + '"></div>'), c.zIndex = j, l = "", m = "", n = "z-index:" + (j - 1) + "; background-color: " + c.border[2] + "; opacity:" + c.border[1] + "; filter:alpha(opacity=" + 100 * c.border[1] + "); top:-" + c.border[0] + "px; left:-" + c.border[0] + "px;", c.border[3] && (i = '<iframe id="xubox_border' + b + '" class="xubox_border" style="' + n + '"></iframe>'), c.closeBtn[1] && (m = '<a class="xubox_close xulayer_png32 xubox_close' + c.closeBtn[0] + '" href="javascript:;"></a>'), c.title[1] && (l = '<h2 class="xubox_title"><em>' + c.title[0] + "</em></h2>"), o = '<div times="' + b + '" showtime="' + c.time + '" style="z-index:' + j + '" id="' + e.lay + b + '" class="' + e.lay + '">' + '<div style="background-color:' + c.bgcolor + "; z-index:" + j + '" class="xubox_main">' + g[c.type] + l + m + '<span class="xubox_botton"></span>' + "</div>" + i + "</div>", [h, o] }, h.pt.dom = { lay: "xubox_layer", ifr: "xubox_iframe" }, h.pt.creat = function() { var j, k, l, m, n, a = this, b = "", c = this.config, d = c.dialog, g = a.config.title, h = a.dom, i = a.index; switch (g.constructor === Array || (a.config.title = [g, !0]), g === !1 && (a.config.title = [g, !1]), j = c.page, k = e("body"), l = function(c) { var c = c || ""; b = a.space(c), k.append(b[0]) }, c.type) { case 1: if ("" !== j.html) l('<div class="xuboxPageHtml">' + j.html + "</div>"), k.append(b[1]); else if ("" !== j.url) l('<div class="xuboxPageHtml" id="xuboxPageHtml' + i + '">' + j.html + "</div>"), k.append(b[1]), e.get(j.url, function(a) { e("#xuboxPageHtml" + i).html(a), j.ok && j.ok(a) }); else { if (0 != e(j.dom).parents(".xubox_page").length) return; l(), e(j.dom).show().wrap(b[1]) } break; case 2: l(), k.append(b[1]); break; case 3: c.title = ["", !1], c.area = ["auto", "auto"], c.closeBtn = ["", !1], e(".xubox_loading")[0] && layer.close(e(".xubox_loading").parents("." + h.lay).attr("times")), l(), k.append(b[1]); break; case 4: c.title = ["", !1], c.area = ["auto", "auto"], c.fix = !1, c.border = !1, e(".xubox_tips")[0] && layer.close(e(".xubox_tips").parents("." + h.lay).attr("times")), l(), k.append(b[1]), e("#" + h.lay + i).find(".xubox_close").css({ top: 6, right: 7 }); break; default: c.title[1] || (c.area = ["auto", "auto"]), e(".xubox_dialog")[0] && layer.close(e(".xubox_dialog").parents("." + h.lay).attr("times")), l(), k.append(b[1]) } if (this.layerS = e("#xubox_shade" + i), this.layerB = e("#xubox_border" + i), this.layerE = e("#" + h.lay + i), m = this.layerE, this.layerMian = m.find(".xubox_main"), this.layerTitle = m.find(".xubox_title"), this.layerText = m.find(".xubox_text"), this.layerPage = m.find(".xubox_page"), this.layerBtn = m.find(".xubox_botton"), n = -1 != c.offset[1].indexOf("px") ? parseInt(c.offset[1]) : "50%" == c.offset[1] ? c.offset[1] : parseInt(c.offset[1]) / 100 * f.width(), m.css({ left: n + c.border[0], width: c.area[0], height: c.area[1] }), c.fix ? m.css({ top: parseInt(c.offset[0]) + c.border[0] }) : m.css({ top: parseInt(c.offset[0]) + f.scrollTop() + c.border[0], position: "absolute" }), 0 == c.type && c.title[1]) switch (d.btns) { case 0: a.layerBtn.html("").hide(); break; case 2: a.layerBtn.html('<a href="javascript:;" class="xubox_yes xubox_botton2">' + d.btn[0] + "</a>" + '<a href="javascript:;" class="xubox_no xubox_botton3">' + d.btn[1] + "</a>"); break; default: a.layerBtn.html('<a href="javascript:;" class="xubox_yes xubox_botton1">' + d.btn[0] + "</a>") } "auto" === m.css("left") ? (m.hide(), setTimeout(function() { m.show(), a.set(i) }, 500)) : a.set(i), c.time <= 0 || a.autoclose(), this.callback() }, h.pt.set = function(a) { var k, l, m, n, o, p, b = this, c = b.layerE, d = b.config, h = (d.dialog, d.page), j = (d.loading, b.dom); switch (b.autoArea(a), d.title[1] ? layer.ie6 && b.layerTitle.css({ width: c.outerWidth() }) : 4 != d.type && c.find(".xubox_close").addClass("xubox_close1"), c.attr({ type: b.type[d.type] }), d.type) { case 1: c.find(h.dom).addClass("layer_pageContent"), d.shade[2] && c.css({ zIndex: d.zIndex + 1 }), d.title[1] && b.layerPage.css({ top: b.layerTitle.outerHeight() }); break; case 2: k = c.find("." + j.ifr), l = c.height(), k.addClass("xubox_load").css({ width: c.width() }), d.title[1] ? k.css({ top: b.layerTitle.height(), height: l - b.layerTitle.height() }) : k.css({ top: 0, height: l }), layer.ie6 && k.attr("src", d.iframe.src); break; case 3: break; case 4: m = [0, c.outerHeight()], n = e(d.tips.follow), o = { width: n.outerWidth(), height: n.outerHeight(), top: n.offset().top, left: n.offset().left }, p = c.find(".layerTipsG"), d.tips.isGuide || p.remove(), c.outerWidth() > d.maxWidth && c.width(d.maxWidth), o.tipColor = d.tips.style[1], m[0] = c.outerWidth(), o.where = [function() { o.tipLeft = o.left, o.tipTop = o.top - m[1] - 10, p.removeClass("layerTipsB").addClass("layerTipsT").css({ "border-right-color": o.tipColor }) }, function() { o.tipLeft = o.left + o.width + 10, o.tipTop = o.top, p.removeClass("layerTipsL").addClass("layerTipsR").css({ "border-bottom-color": o.tipColor }) }, function() { o.tipLeft = o.left, o.tipTop = o.top + o.height + 10, p.removeClass("layerTipsT").addClass("layerTipsB").css({ "border-right-color": o.tipColor }) }, function() { o.tipLeft = o.left - m[0] + 10, o.tipTop = o.top, p.removeClass("layerTipsR").addClass("layerTipsL").css({ "border-bottom-color": o.tipColor }) }], o.where[d.tips.guide](), 0 === d.tips.guide ? o.top - (f.scrollTop() + m[1] + 16) < 0 && o.where[2]() : 1 === d.tips.guide ? f.width() - (o.left + o.width + m[0] + 16) > 0 || o.where[3]() : 2 === d.tips.guide ? o.top - f.scrollTop() + o.height + m[1] + 16 - f.height() > 0 && o.where[0]() : 3 === d.tips.guide && m[0] + 16 - o.left > 0 && o.where[1](), c.css({ left: o.tipLeft, top: o.tipTop }); break; default: b.layerMian.css({ "background-color": "#fff" }), d.title[1] ? b.layerText.css({ paddingTop: 18 + b.layerTitle.outerHeight() }) : (c.find(".xubox_msgico").css({ top: 8 }), b.layerText.css({ marginTop: 11 })) } d.fadeIn && c.css({ opacity: 0 }).animate({ opacity: 1 }, d.fadeIn), b.move() }, h.pt.autoArea = function() { var l, m, p, b = this, c = b.layerE, d = b.config, f = d.page, g = b.layerMian, h = b.layerBtn, i = b.layerText, j = b.layerPage, k = b.layerB, n = 0, o = e(".xubox_loading"); switch ("auto" === d.area[0] && g.outerWidth() >= d.maxWidth && c.css({ width: d.maxWidth }), l = d.title[1] ? b.layerTitle.innerHeight() : 0, d.type) { case 0: p = h.find("a"), m = i.outerHeight() + 20, p.length > 0 && (n = p.outerHeight() + 20); break; case 1: m = e(f.dom).outerHeight(), "auto" === d.area[0] && c.css({ width: j.outerWidth() }), ("" !== f.html || "" !== f.url) && (m = j.outerHeight()); break; case 3: m = o.outerHeight(), g.css({ width: o.width() }) } "auto" === d.area[1] && g.css({ height: l + m + n }), k.css({ width: c.outerWidth() + 2 * d.border[0], height: c.outerHeight() + 2 * d.border[0] }), layer.ie6 && "auto" != d.area[0] && g.css({ width: c.outerWidth() }), "50%" !== d.offset[1] && "" != d.offset[1] || 4 === d.type ? c.css({ marginLeft: 0 }) : c.css({ marginLeft: -c.outerWidth() / 2 }) }, h.pt.move = function() { var a = this, b = this.config, c = a.dom, d = { setY: 0, moveLayer: function() { var a; a = 0 == parseInt(d.layerE.css("margin-left")) ? parseInt(d.move.css("left")) : parseInt(d.move.css("left")) + -parseInt(d.layerE.css("margin-left")), "fixed" !== d.layerE.css("position") && (a -= d.layerE.parent().offset().left, d.setY = 0), d.layerE.css({ left: a, top: parseInt(d.move.css("top")) - d.setY }) } }; b.move[1] && a.layerE.find(b.move[0]).attr("move", "ok"), b.move[1] ? a.layerE.find(b.move[0]).css({ cursor: "move" }) : a.layerE.find(b.move[0]).css({ cursor: "auto" }), e(b.move[0]).on("mousedown", function(a) { if (a.preventDefault(), "ok" === e(this).attr("move")) { d.ismove = !0, d.layerE = e(this).parents("." + c.lay); var g = d.layerE.offset().left, h = d.layerE.offset().top, i = d.layerE.width() - 6, j = d.layerE.height() - 6; e("#xubox_moves")[0] || e("body").append('<div id="xubox_moves" class="xubox_moves" style="left:' + g + "px; top:" + h + "px; width:" + i + "px; height:" + j + 'px; z-index:2147483584"></div>'), d.move = e("#xubox_moves"), b.moveType && d.move.css({ opacity: 0 }), d.moveX = a.pageX - d.move.position().left, d.moveY = a.pageY - d.move.position().top, "fixed" !== d.layerE.css("position") || (d.setY = f.scrollTop()) } }), e(document).mousemove(function(a) { var c, e, g, h; d.ismove && (c = a.pageX - d.moveX, e = a.pageY - d.moveY, a.preventDefault(), b.moveOut || (d.setY = f.scrollTop(), g = f.width() - d.move.outerWidth() - b.border[0], h = b.border[0] + d.setY, c < b.border[0] && (c = b.border[0]), c > g && (c = g), h > e && (e = h), e > f.height() - d.move.outerHeight() - b.border[0] + d.setY && (e = f.height() - d.move.outerHeight() - b.border[0] + d.setY)), d.move.css({ left: c, top: e }), b.moveType && d.moveLayer(), c = null, e = null, g = null, h = null) }).mouseup(function() { try { d.ismove && (d.moveLayer(), d.move.remove()), d.ismove = !1 } catch(a) { d.ismove = !1 } b.moveEnd && b.moveEnd() }) }, h.pt.autoclose = function() { var a = this, b = this.config.time, c = function() { b--, 0 === b && (layer.close(a.index), clearInterval(a.autotime)) }; this.autotime = setInterval(c, 1e3) }, g.config = { end: {} }, h.pt.callback = function() { var a = this, b = a.layerE, c = a.config, d = c.dialog; a.openLayer(), a.config.success(b), layer.ie6 && a.IE6(), b.find(".xubox_close").off("click").on("click", function(b) { b.preventDefault(), c.close(a.index) }), b.find(".xubox_yes").off("click").on("click", function(b) { b.preventDefault(), d.yes(a.index) }), b.find(".xubox_no").off("click").on("click", function(b) { b.preventDefault(), d.no(a.index) }), this.layerS.off("click").on("click", function(b) { b.preventDefault(), a.config.shadeClose && layer.close(a.index) }), g.config.end[a.index] = c.end }, h.pt.IE6 = function() { var h, a = this, b = a.layerE, c = e("select"), d = a.dom, g = b.offset().top; h = a.config.fix ? function() { b.css({ top: e(document).scrollTop() + g }) }: function() { b.css({ top: g }) }, h(), f.scroll(h), e.each(c, function() { var c = e(this); c.parents("." + d.lay)[0] || "none" == c.css("display") || c.attr({ layer: "1" }).hide(), c = null }), a.reselect = function() { e.each(c, function() { var c = e(this); c.parents("." + d.lay)[0] || 1 == c.attr("layer") && e("." + d.lay).length < 1 && c.removeAttr("layer").show(), c = null }) } }, h.pt.openLayer = function() { var a = this, b = a.dom; layer.autoArea = function(b) { return a.autoArea(b) }, layer.getIndex = function(a) { return e(a).parents("." + b.lay).attr("times") }, layer.getChildFrame = function(a, c) { return c = c || e("." + b.ifr).parents("." + b.lay).attr("times"), e("#" + b.lay + c).find("." + b.ifr).contents().find(a) }, layer.getFrameIndex = function(a) { return e(a ? "#" + a: "." + b.ifr).parents("." + b.lay).attr("times") }, layer.iframeAuto = function(a) { var c, d, f, g, h; a = a || e("." + b.ifr).parents("." + b.lay).attr("times"), c = this.getChildFrame("body", a).outerHeight(), d = e("#" + b.lay + a), f = d.find(".xubox_title"), g = 0, !f || (g = f.height()), d.css({ height: c + g }), h = -parseInt(e("#xubox_border" + a).css("top")), e("#xubox_border" + a).css({ height: c + 2 * h + g }), e("#" + b.ifr + a).css({ height: c }) }, layer.close = function(c) { var h, d = e("#" + b.lay + c), f = e("#xubox_moves, #xubox_shade" + c); if (d.attr("type") == a.type[1]) if (d.find(".xuboxPageHtml")[0]) d.remove(); else for (d.find(".xubox_close,.xubox_botton,.xubox_title,.xubox_border").remove(), h = 0; 3 > h; h++) d.find(".layer_pageContent").unwrap().hide(); else document.all && d.find("#" + b.ifr + c).remove(), d.remove(); f.remove(), layer.ie6 && a.reselect(), "function" == typeof g.config.end[c] && g.config.end[c](), delete g.config.end[c] }, layer.loadClose = function() { var a = e(".xubox_loading").parents("." + b.lay), c = a.attr("times"); layer.close(c) }, layer.shift = function(b, c) { var k, d = a.config, e = layer.ie6, g = a.layerE, h = 0, i = f.width(), j = f.height(); switch (h = "50%" == d.offset[1] || "" == d.offset[1] ? g.outerWidth() / 2 : g.outerWidth(), k = { t: { top: d.border[0] }, b: { top: j - g.outerHeight() - d.border[0] }, cl: h + d.border[0], ct: -g.outerHeight(), cr: i - h - d.border[0], fn: function() { e && a.IE6() } }, b) { case "left-top": g.css({ left: k.cl, top: k.ct }).animate(k.t, c, k.fn); break; case "top": g.css({ top: k.ct }).animate(k.t, c, k.fn); break; case "right-top": g.css({ left: k.cr, top: k.ct }).animate(k.t, c, k.fn); break; case "right-bottom": g.css({ left: k.cr, top: j }).animate(k.b, c, k.fn); break; case "bottom": g.css({ top: j }).animate(k.b, c, k.fn); break; case "left-bottom": g.css({ left: k.cl, top: j }).animate(k.b, c, k.fn); break; case "left": g.css({ left: -g.outerWidth(), marginLeft: 0 }).animate({ left: k.t.top }, c, k.fn) } }, layer.setMove = function() { return a.move() }, layer.area = function(c, d) { var j, f = [e("#" + b.lay + c), e("#xubox_border" + c)], g = f[0].attr("type"), h = f[0].find(".xubox_main"), i = f[0].find(".xubox_title"); (g === a.type[1] || g === a.type[2]) && (f[0].css(d), f[1][0] && f[1].css({ width: d.width - 2 * parseInt(f[1].css("left")), height: d.height - 2 * parseInt(f[1].css("top")) }), h.css({ height: d.height }), g === a.type[2] && (j = f[0].find("iframe"), j.css({ width: d.width, height: i ? d.height - i.outerHeight() : d.height })), "0px" !== f[0].css("margin-left") && (d.hasOwnProperty("top") && f[0].css({ top: d.top - (f[1][0] && parseInt(f[1].css("top"))) }), d.hasOwnProperty("left") && f[0].css({ left: d.left + f[0].outerWidth() / 2 - (f[1][0] && parseInt(f[1].css("left"))) }), f[0].css({ marginLeft: -f[0].outerWidth() / 2 }))) }, layer.closeAll = function() { var a = e("." + b.lay); e.each(a, function() { var a = e(this).attr("times"); layer.close(a) }) }, layer.zIndex = a.config.zIndex, layer.setTop = function(a) { var b = function() { layer.zIndex++, a.css("z-index", layer.zIndex + 1) }; return layer.zIndex = parseInt(a[0].style.zIndex), a.on("mousedown", b), layer.zIndex } }, g.run = function() { e = jQuery, f = e(a), layer.use("skin/layer.css"), e.layer = function(a) { var b = new h(a); return b.index } }, i = "../../init/jquery", a.seajs ? define([i], function(b, c) { g.run(), c.layer = [a.layer, a.$.layer] }) : g.run() } (window);