layer.min.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*! layer-v2.0 弹层组件 License LGPL http://layer.layui.com/ By 贤心 */
  2. ;!function (a, b) {
  3. "use strict";
  4. var c, d, e = {
  5. getPath: function () {
  6. var a = document.scripts, b = a[a.length - 1], c = b.src;
  7. if (!b.getAttribute("merge")) return c.substring(0, c.lastIndexOf("/") + 1)
  8. }(),
  9. enter: function (a) {
  10. 13 === a.keyCode && a.preventDefault()
  11. },
  12. config: {},
  13. end: {},
  14. btn: ["确定", "取消"],
  15. type: ["dialog", "page", "iframe", "loading", "tips"]
  16. }, f = {
  17. v: "2.0", ie6: !!a.ActiveXObject && !a.XMLHttpRequest, index: 0, path: e.getPath, config: function (a, b) {
  18. var d = 0;
  19. return a = a || {}, f.cache = e.config = c.extend(e.config, a), f.path = e.config.path || f.path, "string" == typeof a.extend && (a.extend = [a.extend]), f.use("skin/layer.css", a.extend && a.extend.length > 0 ? function g() {
  20. var c = a.extend;
  21. f.use(c[c[d] ? d : d - 1], d < c.length ? function () {
  22. return ++d, g
  23. }() : b)
  24. }() : b), this
  25. }, use: function (a, b, d) {
  26. var e = c("head")[0], a = a.replace(/\s/g, ""), g = /\.css$/.test(a),
  27. h = document.createElement(g ? "link" : "script"), i = "layui_layer_" + a.replace(/\.|\//g, "");
  28. return f.path ? (g && (h.rel = "stylesheet"), h[g ? "href" : "src"] = /^http:\/\//.test(a) ? a : f.path + a, h.id = i, c("#" + i)[0] || e.appendChild(h), function j() {
  29. (g ? 1989 === parseInt(c("#" + i).css("width")) : f[d || i]) ? function () {
  30. b && b();
  31. try {
  32. g || e.removeChild(h)
  33. } catch (a) {
  34. }
  35. }() : setTimeout(j, 100)
  36. }(), this) : void 0
  37. }, ready: function (a, b) {
  38. var d = "function" == typeof a;
  39. return d && (b = a), f.config(c.extend(e.config, function () {
  40. return d ? {} : {path: a}
  41. }()), b), this
  42. }, alert: function (a, b, d) {
  43. var e = "function" == typeof b;
  44. return e && (d = b), f.open(c.extend({content: a, yes: d}, e ? {} : b))
  45. }, confirm: function (a, b, d, g) {
  46. var h = "function" == typeof b;
  47. return h && (g = d, d = b), f.open(c.extend({content: a, btn: e.btn, yes: d, cancel: g}, h ? {} : b))
  48. }, msg: function (a, d, g) {
  49. var i = "function" == typeof d, j = e.config.skin, k = (j ? j + " " + j + "-msg" : "") || "layui-layer-msg",
  50. l = h.anim.length - 1;
  51. return i && (g = d), f.open(c.extend({
  52. content: a,
  53. time: 3e3,
  54. shade: !1,
  55. skin: k,
  56. title: !1,
  57. closeBtn: !1,
  58. btn: !1,
  59. end: g
  60. }, i && !e.config.skin ? {skin: k + " layui-layer-hui", shift: l} : function () {
  61. return d = d || {}, (-1 === d.icon || d.icon === b && !e.config.skin) && (d.skin = k + " " + (d.skin || "layui-layer-hui")), d
  62. }()))
  63. }, load: function (a, b) {
  64. return f.open(c.extend({type: 3, icon: a || 0, shade: .01}, b))
  65. }, tips: function (a, b, d) {
  66. return f.open(c.extend({type: 4, content: [a, b], closeBtn: !1, time: 3e3, maxWidth: 210}, d))
  67. }
  68. }, g = function (a) {
  69. var b = this;
  70. b.index = ++f.index, b.config = c.extend({}, b.config, e.config, a), b.creat()
  71. };
  72. g.pt = g.prototype;
  73. var h = ["layui-layer", ".layui-layer-title", ".layui-layer-main", ".layui-layer-dialog", "layui-layer-iframe", "layui-layer-content", "layui-layer-btn", "layui-layer-close"];
  74. h.anim = ["layui-anim", "layui-anim-01", "layui-anim-02", "layui-anim-03", "layui-anim-04", "layui-anim-05", "layui-anim-06"], g.pt.config = {
  75. type: 0,
  76. shade: .3,
  77. fix: !0,
  78. move: h[1],
  79. title: "&#x4FE1;&#x606F;",
  80. offset: "auto",
  81. area: "auto",
  82. closeBtn: 1,
  83. time: 0,
  84. zIndex: 19891014,
  85. maxWidth: 360,
  86. shift: 0,
  87. icon: -1,
  88. scrollbar: !0,
  89. tips: 2
  90. }, g.pt.vessel = function (a, b) {
  91. var c = this, d = c.index, f = c.config, g = f.zIndex + d, i = "object" == typeof f.title,
  92. j = f.maxmin && (1 === f.type || 2 === f.type),
  93. k = f.title ? '<div class="layui-layer-title" style="' + (i ? f.title[1] : "") + '">' + (i ? f.title[0] : f.title) + "</div>" : "";
  94. return f.zIndex = g, b([f.shade ? '<div class="layui-layer-shade" id="layui-layer-shade' + d + '" times="' + d + '" style="' + ("z-index:" + (g - 1) + "; background-color:" + (f.shade[1] || "#000") + "; opacity:" + (f.shade[0] || f.shade) + "; filter:alpha(opacity=" + (100 * f.shade[0] || 100 * f.shade) + ");") + '"></div>' : "", '<div class="' + h[0] + " " + (h.anim[f.shift] || "") + (" layui-layer-" + e.type[f.type]) + (0 != f.type && 2 != f.type || f.shade ? "" : " layui-layer-border") + " " + (f.skin || "") + '" id="' + h[0] + d + '" type="' + e.type[f.type] + '" times="' + d + '" showtime="' + f.time + '" conType="' + (a ? "object" : "string") + '" style="z-index: ' + g + "; width:" + f.area[0] + ";height:" + f.area[1] + (f.fix ? "" : ";position:absolute;") + '">' + (a && 2 != f.type ? "" : k) + '<div class="layui-layer-content' + (0 == f.type && -1 !== f.icon ? " layui-layer-padding" : "") + (3 == f.type ? " layui-layer-loading" + f.icon : "") + '">' + (0 == f.type && -1 !== f.icon ? '<i class="layui-layer-ico layui-layer-ico' + f.icon + '"></i>' : "") + (1 == f.type && a ? "" : f.content || "") + '</div><span class="layui-layer-setwin">' + function () {
  95. var a = j ? '<a class="layui-layer-min" href="javascript:;"><cite></cite></a><a class="layui-layer-ico layui-layer-max" href="javascript:;"></a>' : "";
  96. return f.closeBtn && (a += '<a class="layui-layer-ico ' + h[7] + " " + h[7] + (f.title ? f.closeBtn : 4 == f.type ? "1" : "2") + '" href="javascript:;"></a>'), a
  97. }() + "</span>" + (f.btn ? function () {
  98. var a = "";
  99. "string" == typeof f.btn && (f.btn = [f.btn]);
  100. for (var b = 0, c = f.btn.length; c > b; b++) a += '<a class="' + h[6] + b + '">' + f.btn[b] + "</a>";
  101. return '<div class="' + h[6] + '">' + a + "</div>"
  102. }() : "") + "</div>"], k), c
  103. }, g.pt.creat = function () {
  104. var a = this, b = a.config, g = a.index, i = b.content, j = "object" == typeof i;
  105. switch ("string" == typeof b.area && (b.area = "auto" === b.area ? ["", ""] : [b.area, ""]), b.type) {
  106. case 0:
  107. b.btn = "btn" in b ? b.btn : e.btn[0], f.closeAll("dialog");
  108. break;
  109. case 2:
  110. var i = b.content = j ? b.content : [b.content || "http://sentsin.com?from=layer", "auto"];
  111. b.content = '<iframe scrolling="' + (b.content[1] || "auto") + '" allowtransparency="true" id="' + h[4] + g + '" name="' + h[4] + g + '" onload="this.className=\'\';" class="layui-layer-load" frameborder="0" src="' + b.content[0] + '"></iframe>';
  112. break;
  113. case 3:
  114. b.title = !1, b.closeBtn = !1, -1 === b.icon && 0 === b.icon, f.closeAll("loading");
  115. break;
  116. case 4:
  117. j || (b.content = [b.content, "body"]), b.follow = b.content[1], b.content = b.content[0] + '<i class="layui-layer-TipsG"></i>', b.title = !1, b.shade = !1, b.fix = !1, b.tips = "object" == typeof b.tips ? b.tips : [b.tips, !0], b.tipsMore || f.closeAll("tips")
  118. }
  119. a.vessel(j, function (d, e) {
  120. c("body").append(d[0]), j ? function () {
  121. 2 == b.type || 4 == b.type ? function () {
  122. c("body").append(d[1])
  123. }() : function () {
  124. i.parents("." + h[0])[0] || (i.show().addClass("layui-layer-wrap").wrap(d[1]), c("#" + h[0] + g).find("." + h[5]).before(e))
  125. }()
  126. }() : c("body").append(d[1]), a.layero = c("#" + h[0] + g), b.scrollbar || h.html.css("overflow", "hidden").attr("layer-full", g)
  127. }).auto(g), 2 == b.type && f.ie6 && a.layero.find("iframe").attr("src", i[0]), c(document).off("keydown", e.enter).on("keydown", e.enter), 4 == b.type ? a.tips() : a.offset(), b.fix && d.on("resize", function () {
  128. a.offset(), (/^\d+%$/.test(b.area[0]) || /^\d+%$/.test(b.area[1])) && a.auto(g), 4 == b.type && a.tips()
  129. }), b.time <= 0 || setTimeout(function () {
  130. f.close(a.index)
  131. }, b.time), a.move().callback()
  132. }, g.pt.auto = function (a) {
  133. function b(a) {
  134. a = g.find(a), a.height(i[1] - j - k - 2 * (0 | parseFloat(a.css("padding"))))
  135. }
  136. var e = this, f = e.config, g = c("#" + h[0] + a);
  137. "" === f.area[0] && f.maxWidth > 0 && (/MSIE 7/.test(navigator.userAgent) && f.btn && g.width(g.innerWidth()), g.outerWidth() > f.maxWidth && g.width(f.maxWidth));
  138. var i = [g.innerWidth(), g.innerHeight()], j = g.find(h[1]).outerHeight() || 0,
  139. k = g.find("." + h[6]).outerHeight() || 0;
  140. switch (f.type) {
  141. case 2:
  142. b("iframe");
  143. break;
  144. default:
  145. "" === f.area[1] ? f.fix && i[1] >= d.height() && (i[1] = d.height(), b("." + h[5])) : b("." + h[5])
  146. }
  147. return e
  148. }, g.pt.offset = function () {
  149. var a = this, b = a.config, c = a.layero, e = [c.outerWidth(), c.outerHeight()], f = "object" == typeof b.offset;
  150. a.offsetTop = (d.height() - e[1]) / 2, a.offsetLeft = (d.width() - e[0]) / 2, f ? (a.offsetTop = b.offset[0], a.offsetLeft = b.offset[1] || a.offsetLeft) : "auto" !== b.offset && (a.offsetTop = b.offset, "rb" === b.offset && (a.offsetTop = d.height() - e[1], a.offsetLeft = d.width() - e[0])), b.fix || (a.offsetTop = /%$/.test(a.offsetTop) ? d.height() * parseFloat(a.offsetTop) / 100 : parseFloat(a.offsetTop), a.offsetLeft = /%$/.test(a.offsetLeft) ? d.width() * parseFloat(a.offsetLeft) / 100 : parseFloat(a.offsetLeft), a.offsetTop += d.scrollTop(), a.offsetLeft += d.scrollLeft()), c.css({
  151. top: a.offsetTop,
  152. left: a.offsetLeft
  153. })
  154. }, g.pt.tips = function () {
  155. var a = this, b = a.config, e = a.layero, f = [e.outerWidth(), e.outerHeight()], g = c(b.follow);
  156. g[0] || (g = c("body"));
  157. var i = {width: g.outerWidth(), height: g.outerHeight(), top: g.offset().top, left: g.offset().left},
  158. j = e.find(".layui-layer-TipsG"), k = b.tips[0];
  159. b.tips[1] || j.remove(), i.autoLeft = function () {
  160. i.left + f[0] - d.width() > 0 ? (i.tipLeft = i.left + i.width - f[0], j.css({
  161. right: 12,
  162. left: "auto"
  163. })) : i.tipLeft = i.left
  164. }, i.where = [function () {
  165. i.autoLeft(), i.tipTop = i.top - f[1] - 10, j.removeClass("layui-layer-TipsB").addClass("layui-layer-TipsT").css("border-right-color", b.tips[1])
  166. }, function () {
  167. i.tipLeft = i.left + i.width + 10, i.tipTop = i.top, j.removeClass("layui-layer-TipsL").addClass("layui-layer-TipsR").css("border-bottom-color", b.tips[1])
  168. }, function () {
  169. i.autoLeft(), i.tipTop = i.top + i.height + 10, j.removeClass("layui-layer-TipsT").addClass("layui-layer-TipsB").css("border-right-color", b.tips[1])
  170. }, function () {
  171. i.tipLeft = i.left - f[0] - 10, i.tipTop = i.top, j.removeClass("layui-layer-TipsR").addClass("layui-layer-TipsL").css("border-bottom-color", b.tips[1])
  172. }], i.where[k - 1](), 1 === k ? i.top - (d.scrollTop() + f[1] + 16) < 0 && i.where[2]() : 2 === k ? d.width() - (i.left + i.width + f[0] + 16) > 0 || i.where[3]() : 3 === k ? i.top - d.scrollTop() + i.height + f[1] + 16 - d.height() > 0 && i.where[0]() : 4 === k && f[0] + 16 - i.left > 0 && i.where[1](), e.find("." + h[5]).css({
  173. "background-color": b.tips[1],
  174. "padding-right": b.closeBtn ? "30px" : ""
  175. }), e.css({left: i.tipLeft, top: i.tipTop})
  176. }, g.pt.move = function () {
  177. var a = this, b = a.config, e = {
  178. setY: 0, moveLayer: function () {
  179. var a = e.layero, b = parseInt(a.css("margin-left")), c = parseInt(e.move.css("left"));
  180. 0 === b || (c -= b), "fixed" !== a.css("position") && (c -= a.parent().offset().left, e.setY = 0), a.css({
  181. left: c,
  182. top: parseInt(e.move.css("top")) - e.setY
  183. })
  184. }
  185. }, f = a.layero.find(b.move);
  186. return b.move && f.attr("move", "ok"), f.css({cursor: b.move ? "move" : "auto"}), c(b.move).on("mousedown", function (a) {
  187. if (a.preventDefault(), "ok" === c(this).attr("move")) {
  188. e.ismove = !0, e.layero = c(this).parents("." + h[0]);
  189. var f = e.layero.offset().left, g = e.layero.offset().top, i = e.layero.outerWidth() - 6,
  190. j = e.layero.outerHeight() - 6;
  191. c("#layui-layer-moves")[0] || c("body").append('<div id="layui-layer-moves" class="layui-layer-moves" style="left:' + f + "px; top:" + g + "px; width:" + i + "px; height:" + j + 'px; z-index:2147483584"></div>'), e.move = c("#layui-layer-moves"), b.moveType && e.move.css({visibility: "hidden"}), e.moveX = a.pageX - e.move.position().left, e.moveY = a.pageY - e.move.position().top, "fixed" !== e.layero.css("position") || (e.setY = d.scrollTop())
  192. }
  193. }), c(document).mousemove(function (a) {
  194. if (e.ismove) {
  195. var c = a.pageX - e.moveX, f = a.pageY - e.moveY;
  196. if (a.preventDefault(), !b.moveOut) {
  197. e.setY = d.scrollTop();
  198. var g = d.width() - e.move.outerWidth(), h = e.setY;
  199. 0 > c && (c = 0), c > g && (c = g), h > f && (f = h), f > d.height() - e.move.outerHeight() + e.setY && (f = d.height() - e.move.outerHeight() + e.setY)
  200. }
  201. e.move.css({left: c, top: f}), b.moveType && e.moveLayer(), c = f = g = h = null
  202. }
  203. }).mouseup(function () {
  204. try {
  205. e.ismove && (e.moveLayer(), e.move.remove(), b.moveEnd && b.moveEnd()), e.ismove = !1
  206. } catch (a) {
  207. e.ismove = !1
  208. }
  209. }), a
  210. }, g.pt.callback = function () {
  211. function a() {
  212. var a = g.cancel && g.cancel(b.index);
  213. a === !1 || f.close(b.index)
  214. }
  215. var b = this, d = b.layero, g = b.config;
  216. b.openLayer(), g.success && (2 == g.type ? d.find("iframe")[0].onload = function () {
  217. this.className = "", g.success(d, b.index)
  218. } : g.success(d, b.index)), f.ie6 && b.IE6(d), d.find("." + h[6]).children("a").on("click", function () {
  219. var e = c(this).index();
  220. g["btn" + (e + 1)] && g["btn" + (e + 1)](b.index, d), 0 === e ? g.yes ? g.yes(b.index, d) : f.close(b.index) : 1 === e ? a() : g["btn" + (e + 1)] || f.close(b.index)
  221. }), d.find("." + h[7]).on("click", a), g.shadeClose && c("#layui-layer-shade" + b.index).on("click", function () {
  222. f.close(b.index)
  223. }), d.find(".layui-layer-min").on("click", function () {
  224. f.min(b.index, g), g.min && g.min(d)
  225. }), d.find(".layui-layer-max").on("click", function () {
  226. c(this).hasClass("layui-layer-maxmin") ? (f.restore(b.index), g.restore && g.restore(d)) : (f.full(b.index, g), g.full && g.full(d))
  227. }), g.end && (e.end[b.index] = g.end)
  228. }, e.reselect = function () {
  229. c.each(c("select"), function (a, b) {
  230. var d = c(this);
  231. d.parents("." + h[0])[0] || 1 == d.attr("layer") && c("." + h[0]).length < 1 && d.removeAttr("layer").show(), d = null
  232. })
  233. }, g.pt.IE6 = function (a) {
  234. function b() {
  235. a.css({top: f + (e.config.fix ? d.scrollTop() : 0)})
  236. }
  237. var e = this, f = a.offset().top;
  238. b(), d.scroll(b), c("select").each(function (a, b) {
  239. var d = c(this);
  240. d.parents("." + h[0])[0] || "none" === d.css("display") || d.attr({layer: "1"}).hide(), d = null
  241. })
  242. }, g.pt.openLayer = function () {
  243. var a = this;
  244. f.zIndex = a.config.zIndex, f.setTop = function (a) {
  245. var b = function () {
  246. f.zIndex++, a.css("z-index", f.zIndex + 1)
  247. };
  248. return f.zIndex = parseInt(a[0].style.zIndex), a.on("mousedown", b), f.zIndex
  249. }
  250. }, e.record = function (a) {
  251. var b = [a.outerWidth(), a.outerHeight(), a.position().top, a.position().left + parseFloat(a.css("margin-left"))];
  252. a.find(".layui-layer-max").addClass("layui-layer-maxmin"), a.attr({area: b})
  253. }, e.rescollbar = function (a) {
  254. h.html.attr("layer-full") == a && (h.html[0].style.removeProperty ? h.html[0].style.removeProperty("overflow") : h.html[0].style.removeAttribute("overflow"), h.html.removeAttr("layer-full"))
  255. }, f.getChildFrame = function (a, b) {
  256. return b = b || c("." + h[4]).attr("times"), c("#" + h[0] + b).find("iframe").contents().find(a)
  257. }, f.getFrameIndex = function (a) {
  258. return c("#" + a).parents("." + h[4]).attr("times")
  259. }, f.iframeAuto = function (a) {
  260. if (a) {
  261. var b = f.getChildFrame("body", a).outerHeight(), d = c("#" + h[0] + a), e = d.find(h[1]).outerHeight() || 0,
  262. g = d.find("." + h[6]).outerHeight() || 0;
  263. d.css({height: b + e + g}), d.find("iframe").css({height: b})
  264. }
  265. }, f.iframeSrc = function (a, b) {
  266. c("#" + h[0] + a).find("iframe").attr("src", b)
  267. }, f.style = function (a, b) {
  268. var d = c("#" + h[0] + a), f = d.attr("type"), g = d.find(h[1]).outerHeight() || 0,
  269. i = d.find("." + h[6]).outerHeight() || 0;
  270. (f === e.type[1] || f === e.type[2]) && (d.css(b), f === e.type[2] && d.find("iframe").css({height: parseFloat(b.height) - g - i}))
  271. }, f.min = function (a, b) {
  272. var d = c("#" + h[0] + a), g = d.find(h[1]).outerHeight() || 0;
  273. e.record(d), f.style(a, {
  274. width: 180,
  275. height: g,
  276. overflow: "hidden"
  277. }), d.find(".layui-layer-min").hide(), "page" === d.attr("type") && d.find(h[4]).hide(), e.rescollbar(a)
  278. }, f.restore = function (a) {
  279. var b = c("#" + h[0] + a), d = b.attr("area").split(",");
  280. b.attr("type");
  281. f.style(a, {
  282. width: parseFloat(d[0]),
  283. height: parseFloat(d[1]),
  284. top: parseFloat(d[2]),
  285. left: parseFloat(d[3]),
  286. overflow: "visible"
  287. }), b.find(".layui-layer-max").removeClass("layui-layer-maxmin"), b.find(".layui-layer-min").show(), "page" === b.attr("type") && b.find(h[4]).show(), e.rescollbar(a)
  288. }, f.full = function (a) {
  289. var b, g = c("#" + h[0] + a);
  290. e.record(g), h.html.attr("layer-full") || h.html.css("overflow", "hidden").attr("layer-full", a), clearTimeout(b), b = setTimeout(function () {
  291. var b = "fixed" === g.css("position");
  292. f.style(a, {
  293. top: b ? 0 : d.scrollTop(),
  294. left: b ? 0 : d.scrollLeft(),
  295. width: d.width(),
  296. height: d.height()
  297. }), g.find(".layui-layer-min").hide()
  298. }, 100)
  299. }, f.title = function (a, b) {
  300. var d = c("#" + h[0] + (b || f.index)).find(h[1]);
  301. d.html(a)
  302. }, f.close = function (a) {
  303. var b = c("#" + h[0] + a), d = b.attr("type");
  304. if (b[0]) {
  305. if (d === e.type[1] && "object" === b.attr("conType")) {
  306. b.children(":not(." + h[5] + ")").remove();
  307. for (var g = 0; 2 > g; g++) b.find(".layui-layer-wrap").unwrap().hide()
  308. } else {
  309. if (d === e.type[2]) try {
  310. var i = c("#" + h[4] + a)[0];
  311. i.contentWindow.document.write(""), i.contentWindow.close(), b.find("." + h[5])[0].removeChild(i)
  312. } catch (j) {
  313. }
  314. b[0].innerHTML = "", b.remove()
  315. }
  316. c("#layui-layer-moves, #layui-layer-shade" + a).remove(), f.ie6 && e.reselect(), e.rescollbar(a), c(document).off("keydown", e.enter), "function" == typeof e.end[a] && e.end[a](), delete e.end[a]
  317. }
  318. }, f.closeAll = function (a) {
  319. c.each(c("." + h[0]), function () {
  320. var b = c(this), d = a ? b.attr("type") === a : 1;
  321. d && f.close(b.attr("times")), d = null
  322. })
  323. }, e.run = function () {
  324. c = jQuery, d = c(a), h.html = c("html"), f.open = function (a) {
  325. var b = new g(a);
  326. return b.index
  327. }
  328. }, "function" == typeof define ? define(function () {
  329. return e.run(), f
  330. }) : function () {
  331. a.layer = f, e.run(), f.use("skin/layer.css")
  332. }()
  333. }(window);