layer.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. /**
  2. @Name:layer v3.1.2 Web弹层组件
  3. @Author:贤心
  4. @Site:http://layer.layui.com
  5. @License:MIT
  6. */
  7. ;
  8. ! function(window, undefined) {
  9. "use strict";
  10. var isLayui = window.layui && layui.define,
  11. $, win, ready = {
  12. getPath: function() {
  13. var jsPath = document.currentScript ? document.currentScript.src : function() {
  14. var js = document.scripts,
  15. last = js.length - 1,
  16. src;
  17. for (var i = last; i > 0; i--) {
  18. if (js[i].readyState === 'interactive') {
  19. src = js[i].src;
  20. break;
  21. }
  22. }
  23. return src || js[last].src;
  24. }();
  25. return jsPath.substring(0, jsPath.lastIndexOf('/') + 1);
  26. }(),
  27. config: {},
  28. end: {},
  29. minIndex: 0,
  30. minLeft: [],
  31. btn: ['确定', '取消'],
  32. //五种原始层模式
  33. type: ['dialog', 'page', 'iframe', 'loading', 'tips'],
  34. //获取节点的style属性值
  35. getStyle: function(node, name) {
  36. var style = node.currentStyle ? node.currentStyle : window.getComputedStyle(node, null);
  37. return style[style.getPropertyValue ? 'getPropertyValue' : 'getAttribute'](name);
  38. },
  39. //载入CSS配件
  40. link: function(href, fn, cssname) {
  41. //未设置路径,则不主动加载css
  42. if (!layer.path) return;
  43. var head = document.getElementsByTagName("head")[0],
  44. link = document.createElement('link');
  45. if (typeof fn === 'string') cssname = fn;
  46. var app = (cssname || href).replace(/\.|\//g, '');
  47. var id = 'layuicss-' + app,
  48. timeout = 0;
  49. link.rel = 'stylesheet';
  50. link.href = layer.path + href;
  51. link.id = id;
  52. if (!document.getElementById(id)) {
  53. head.appendChild(link);
  54. }
  55. if (typeof fn !== 'function') return;
  56. //轮询css是否加载完毕
  57. (function poll() {
  58. if (++timeout > 8 * 1000 / 100) {
  59. return window.console && console.error('layer.css: Invalid');
  60. };
  61. parseInt(ready.getStyle(document.getElementById(id), 'width')) === 1989 ? fn() : setTimeout(poll, 100);
  62. }());
  63. }
  64. };
  65. //默认内置方法。
  66. var layer = {
  67. v: '3.1.1',
  68. ie: function() { //ie版本
  69. var agent = navigator.userAgent.toLowerCase();
  70. return (!!window.ActiveXObject || "ActiveXObject" in window) ? (
  71. (agent.match(/msie\s(\d+)/) || [])[1] || '11' //由于ie11并没有msie的标识
  72. ) : false;
  73. }(),
  74. index: (window.layer && window.layer.v) ? 100000 : 0,
  75. path: ready.getPath,
  76. config: function(options, fn) {
  77. options = options || {};
  78. layer.cache = ready.config = $.extend({}, ready.config, options);
  79. layer.path = ready.config.path || layer.path;
  80. typeof options.extend === 'string' && (options.extend = [options.extend]);
  81. if (ready.config.path) layer.ready();
  82. if (!options.extend) return this;
  83. isLayui
  84. ?
  85. layui.addcss('modules/layer/' + options.extend) :
  86. ready.link('theme/' + options.extend);
  87. return this;
  88. },
  89. //主体CSS等待事件
  90. ready: function(callback) {
  91. var cssname = 'layer',
  92. ver = '',
  93. path = (isLayui ? 'modules/layer/' : 'theme/') + 'default/layer.css?v=' + layer.v + ver;
  94. isLayui ? layui.addcss(path, callback, cssname) : ready.link(path, callback, cssname);
  95. return this;
  96. },
  97. //各种快捷引用
  98. alert: function(content, options, yes) {
  99. var type = typeof options === 'function';
  100. if (type) yes = options;
  101. return layer.open($.extend({
  102. content: content,
  103. yes: yes
  104. }, type ? {} : options));
  105. },
  106. confirm: function(content, options, yes, cancel) {
  107. var type = typeof options === 'function';
  108. if (type) {
  109. cancel = yes;
  110. yes = options;
  111. }
  112. return layer.open($.extend({
  113. content: content,
  114. btn: ready.btn,
  115. yes: yes,
  116. btn2: cancel
  117. }, type ? {} : options));
  118. },
  119. msg: function(content, options, end) { //最常用提示层
  120. var type = typeof options === 'function',
  121. rskin = ready.config.skin;
  122. var skin = (rskin ? rskin + ' ' + rskin + '-msg' : '') || 'layui-layer-msg';
  123. var anim = doms.anim.length - 1;
  124. if (type) end = options;
  125. return layer.open($.extend({
  126. content: content,
  127. time: 3000,
  128. shade: false,
  129. skin: skin,
  130. title: false,
  131. closeBtn: false,
  132. btn: false,
  133. resize: false,
  134. end: end
  135. }, (type && !ready.config.skin) ? {
  136. skin: skin + ' layui-layer-hui',
  137. anim: anim
  138. } : function() {
  139. options = options || {};
  140. if (options.icon === -1 || options.icon === undefined && !ready.config.skin) {
  141. options.skin = skin + ' ' + (options.skin || 'layui-layer-hui');
  142. }
  143. return options;
  144. }()));
  145. },
  146. load: function(icon, options) {
  147. return layer.open($.extend({
  148. type: 3,
  149. icon: icon || 0,
  150. resize: false,
  151. shade: 0.01
  152. }, options));
  153. },
  154. tips: function(content, follow, options) {
  155. return layer.open($.extend({
  156. type: 4,
  157. content: [content, follow],
  158. closeBtn: false,
  159. time: 3000,
  160. shade: false,
  161. resize: false,
  162. fixed: false,
  163. maxWidth: 210
  164. }, options));
  165. }
  166. };
  167. var Class = function(setings) {
  168. var that = this;
  169. that.index = ++layer.index;
  170. that.config = $.extend({}, that.config, ready.config, setings);
  171. document.body ? that.creat() : setTimeout(function() {
  172. that.creat();
  173. }, 30);
  174. };
  175. Class.pt = Class.prototype;
  176. //缓存常用字符
  177. 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'];
  178. doms.anim = ['layer-anim-00', 'layer-anim-01', 'layer-anim-02', 'layer-anim-03', 'layer-anim-04', 'layer-anim-05', 'layer-anim-06'];
  179. //默认配置
  180. Class.pt.config = {
  181. type: 0,
  182. shade: 0.3,
  183. fixed: true,
  184. move: doms[1],
  185. title: '信息',
  186. offset: 'auto',
  187. area: 'auto',
  188. closeBtn: 1,
  189. time: 0, //0表示不自动关闭
  190. zIndex: 19891014,
  191. maxWidth: 360,
  192. anim: 0,
  193. isOutAnim: true,
  194. icon: -1,
  195. moveType: 1,
  196. resize: true,
  197. scrollbar: true, //是否允许浏览器滚动条
  198. tips: 2
  199. };
  200. //容器
  201. Class.pt.vessel = function(conType, callback) {
  202. var that = this,
  203. times = that.index,
  204. config = that.config;
  205. var zIndex = config.zIndex + times,
  206. titype = typeof config.title === 'object';
  207. var ismax = config.maxmin && (config.type === 1 || config.type === 2);
  208. var titleHTML = (config.title ? '<div class="layui-layer-title" style="' + (titype ? config.title[1] : '') + '">' +
  209. (titype ? config.title[0] : config.title) +
  210. '</div>' : '');
  211. config.zIndex = zIndex;
  212. callback([
  213. //遮罩
  214. config.shade ? ('<div class="layui-layer-shade" id="layui-layer-shade' + times + '" times="' + times + '" style="' + ('z-index:' + (zIndex - 1) + '; ') + '"></div>') : '',
  215. //主体
  216. '<div class="' + doms[0] + (' layui-layer-' + ready.type[config.type]) + (((config.type == 0 || config.type == 2) && !config.shade) ? ' layui-layer-border' : '') + ' ' + (config.skin || '') + '" 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;') + '">' +
  217. (conType && config.type != 2 ? '' : titleHTML) +
  218. '<div id="' + (config.id || '') + '" class="layui-layer-content' + ((config.type == 0 && config.icon !== -1) ? ' layui-layer-padding' : '') + (config.type == 3 ? ' layui-layer-loading' + config.icon : '') + '">' +
  219. (config.type == 0 && config.icon !== -1 ? '<i class="layui-layer-ico layui-layer-ico' + config.icon + '"></i>' : '') +
  220. (config.type == 1 && conType ? '' : (config.content || '')) +
  221. '</div>' +
  222. '<span class="layui-layer-setwin">' + function() {
  223. var closebtn = ismax ? '<a class="layui-layer-min" href="javascript:;"><cite></cite></a><a class="layui-layer-ico layui-layer-max" href="javascript:;"></a>' : '';
  224. config.closeBtn && (closebtn += '<a class="layui-layer-ico ' + doms[7] + ' ' + doms[7] + (config.title ? config.closeBtn : (config.type == 4 ? '1' : '2')) + '" href="javascript:;"></a>');
  225. return closebtn;
  226. }() + '</span>' +
  227. (config.btn ? function() {
  228. var button = '';
  229. typeof config.btn === 'string' && (config.btn = [config.btn]);
  230. for (var i = 0, len = config.btn.length; i < len; i++) {
  231. button += '<a class="' + doms[6] + '' + i + '">' + config.btn[i] + '</a>'
  232. }
  233. return '<div class="' + doms[6] + ' layui-layer-btn-' + (config.btnAlign || '') + '">' + button + '</div>'
  234. }() : '') +
  235. (config.resize ? '<span class="layui-layer-resize"></span>' : '') +
  236. '</div>'
  237. ], titleHTML, $('<div class="layui-layer-move"></div>'));
  238. return that;
  239. };
  240. //创建骨架
  241. Class.pt.creat = function() {
  242. var that = this,
  243. config = that.config,
  244. times = that.index,
  245. nodeIndex, content = config.content,
  246. conType = typeof content === 'object',
  247. body = $('body');
  248. if (config.id && $('#' + config.id)[0]) return;
  249. if (typeof config.area === 'string') {
  250. config.area = config.area === 'auto' ? ['', ''] : [config.area, ''];
  251. }
  252. //anim兼容旧版shift
  253. if (config.shift) {
  254. config.anim = config.shift;
  255. }
  256. if (layer.ie == 6) {
  257. config.fixed = false;
  258. }
  259. switch (config.type) {
  260. case 0:
  261. config.btn = ('btn' in config) ? config.btn : ready.btn[0];
  262. layer.closeAll('dialog');
  263. break;
  264. case 2:
  265. var content = config.content = conType ? config.content : [config.content || '', 'auto'];
  266. 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>';
  267. break;
  268. case 3:
  269. delete config.title;
  270. delete config.closeBtn;
  271. config.icon === -1 && (config.icon === 0);
  272. layer.closeAll('loading');
  273. break;
  274. case 4:
  275. conType || (config.content = [config.content, 'body']);
  276. config.follow = config.content[1];
  277. config.content = config.content[0] + '<i class="layui-layer-TipsG"></i>';
  278. delete config.title;
  279. config.tips = typeof config.tips === 'object' ? config.tips : [config.tips, true];
  280. config.tipsMore || layer.closeAll('tips');
  281. break;
  282. }
  283. //建立容器
  284. that.vessel(conType, function(html, titleHTML, moveElem) {
  285. body.append(html[0]);
  286. conType ? function() {
  287. (config.type == 2 || config.type == 4) ? function() {
  288. $('body').append(html[1]);
  289. }() : function() {
  290. if (!content.parents('.' + doms[0])[0]) {
  291. content.data('display', content.css('display')).show().addClass('layui-layer-wrap').wrap(html[1]);
  292. $('#' + doms[0] + times).find('.' + doms[5]).before(titleHTML);
  293. }
  294. }();
  295. }() : body.append(html[1]);
  296. $('.layui-layer-move')[0] || body.append(ready.moveElem = moveElem);
  297. that.layero = $('#' + doms[0] + times);
  298. config.scrollbar || doms.html.css('overflow', 'hidden').attr('layer-full', times);
  299. }).auto(times);
  300. //遮罩
  301. $('#layui-layer-shade' + that.index).css({
  302. 'background-color': config.shade[1] || '#000',
  303. 'opacity': config.shade[0] || config.shade
  304. });
  305. config.type == 2 && layer.ie == 6 && that.layero.find('iframe').attr('src', content[0]);
  306. //坐标自适应浏览器窗口尺寸
  307. config.type == 4 ? that.tips() : that.offset();
  308. if (config.fixed) {
  309. win.on('resize', function() {
  310. that.offset();
  311. (/^\d+%$/.test(config.area[0]) || /^\d+%$/.test(config.area[1])) && that.auto(times);
  312. config.type == 4 && that.tips();
  313. });
  314. }
  315. config.time <= 0 || setTimeout(function() {
  316. layer.close(that.index)
  317. }, config.time);
  318. that.move().callback();
  319. //为兼容jQuery3.0的css动画影响元素尺寸计算
  320. if (doms.anim[config.anim]) {
  321. var animClass = 'layer-anim ' + doms.anim[config.anim];
  322. that.layero.addClass(animClass).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
  323. $(this).removeClass(animClass);
  324. });
  325. };
  326. //记录关闭动画
  327. if (config.isOutAnim) {
  328. that.layero.data('isOutAnim', true);
  329. }
  330. };
  331. //自适应
  332. Class.pt.auto = function(index) {
  333. var that = this,
  334. config = that.config,
  335. layero = $('#' + doms[0] + index);
  336. if (config.area[0] === '' && config.maxWidth > 0) {
  337. //为了修复IE7下一个让人难以理解的bug
  338. if (layer.ie && layer.ie < 8 && config.btn) {
  339. layero.width(layero.innerWidth());
  340. }
  341. layero.outerWidth() > config.maxWidth && layero.width(config.maxWidth);
  342. }
  343. var area = [layero.innerWidth(), layero.innerHeight()],
  344. titHeight = layero.find(doms[1]).outerHeight() || 0,
  345. btnHeight = layero.find('.' + doms[6]).outerHeight() || 0,
  346. setHeight = function(elem) {
  347. elem = layero.find(elem);
  348. elem.height(area[1] - titHeight - btnHeight - 2 * (parseFloat(elem.css('padding-top')) | 0));
  349. };
  350. switch (config.type) {
  351. case 2:
  352. setHeight('iframe');
  353. break;
  354. default:
  355. if (config.area[1] === '') {
  356. if (config.maxHeight > 0 && layero.outerHeight() > config.maxHeight) {
  357. area[1] = config.maxHeight;
  358. setHeight('.' + doms[5]);
  359. } else if (config.fixed && area[1] >= win.height()) {
  360. area[1] = win.height();
  361. setHeight('.' + doms[5]);
  362. }
  363. } else {
  364. setHeight('.' + doms[5]);
  365. }
  366. break;
  367. };
  368. return that;
  369. };
  370. //计算坐标
  371. Class.pt.offset = function() {
  372. var that = this,
  373. config = that.config,
  374. layero = that.layero;
  375. var area = [layero.outerWidth(), layero.outerHeight()];
  376. var type = typeof config.offset === 'object';
  377. that.offsetTop = (win.height() - area[1]) / 2;
  378. that.offsetLeft = (win.width() - area[0]) / 2;
  379. if (type) {
  380. that.offsetTop = config.offset[0];
  381. that.offsetLeft = config.offset[1] || that.offsetLeft;
  382. } else if (config.offset !== 'auto') {
  383. if (config.offset === 't') { //上
  384. that.offsetTop = 0;
  385. } else if (config.offset === 'r') { //右
  386. that.offsetLeft = win.width() - area[0];
  387. } else if (config.offset === 'b') { //下
  388. that.offsetTop = win.height() - area[1];
  389. } else if (config.offset === 'l') { //左
  390. that.offsetLeft = 0;
  391. } else if (config.offset === 'lt') { //左上角
  392. that.offsetTop = 0;
  393. that.offsetLeft = 0;
  394. } else if (config.offset === 'lb') { //左下角
  395. that.offsetTop = win.height() - area[1];
  396. that.offsetLeft = 0;
  397. } else if (config.offset === 'rt') { //右上角
  398. that.offsetTop = 0;
  399. that.offsetLeft = win.width() - area[0];
  400. } else if (config.offset === 'rb') { //右下角
  401. that.offsetTop = win.height() - area[1];
  402. that.offsetLeft = win.width() - area[0];
  403. } else {
  404. that.offsetTop = config.offset;
  405. }
  406. }
  407. if (!config.fixed) {
  408. that.offsetTop = /%$/.test(that.offsetTop) ?
  409. win.height() * parseFloat(that.offsetTop) / 100 :
  410. parseFloat(that.offsetTop);
  411. that.offsetLeft = /%$/.test(that.offsetLeft) ?
  412. win.width() * parseFloat(that.offsetLeft) / 100 :
  413. parseFloat(that.offsetLeft);
  414. that.offsetTop += win.scrollTop();
  415. that.offsetLeft += win.scrollLeft();
  416. }
  417. if (layero.attr('minLeft')) {
  418. that.offsetTop = win.height() - (layero.find(doms[1]).outerHeight() || 0);
  419. that.offsetLeft = layero.css('left');
  420. }
  421. layero.css({ top: that.offsetTop, left: that.offsetLeft });
  422. };
  423. //Tips
  424. Class.pt.tips = function() {
  425. var that = this,
  426. config = that.config,
  427. layero = that.layero;
  428. var layArea = [layero.outerWidth(), layero.outerHeight()],
  429. follow = $(config.follow);
  430. if (!follow[0]) follow = $('body');
  431. var goal = {
  432. width: follow.outerWidth(),
  433. height: follow.outerHeight(),
  434. top: follow.offset().top,
  435. left: follow.offset().left
  436. },
  437. tipsG = layero.find('.layui-layer-TipsG');
  438. var guide = config.tips[0];
  439. config.tips[1] || tipsG.remove();
  440. goal.autoLeft = function() {
  441. if (goal.left + layArea[0] - win.width() > 0) {
  442. goal.tipLeft = goal.left + goal.width - layArea[0];
  443. tipsG.css({ right: 12, left: 'auto' });
  444. } else {
  445. goal.tipLeft = goal.left;
  446. };
  447. };
  448. //辨别tips的方位
  449. goal.where = [function() { //上
  450. goal.autoLeft();
  451. goal.tipTop = goal.top - layArea[1] - 10;
  452. tipsG.removeClass('layui-layer-TipsB').addClass('layui-layer-TipsT').css('border-right-color', config.tips[1]);
  453. }, function() { //右
  454. goal.tipLeft = goal.left + goal.width + 10;
  455. goal.tipTop = goal.top;
  456. tipsG.removeClass('layui-layer-TipsL').addClass('layui-layer-TipsR').css('border-bottom-color', config.tips[1]);
  457. }, function() { //下
  458. goal.autoLeft();
  459. goal.tipTop = goal.top + goal.height + 10;
  460. tipsG.removeClass('layui-layer-TipsT').addClass('layui-layer-TipsB').css('border-right-color', config.tips[1]);
  461. }, function() { //左
  462. goal.tipLeft = goal.left - layArea[0] - 10;
  463. goal.tipTop = goal.top;
  464. tipsG.removeClass('layui-layer-TipsR').addClass('layui-layer-TipsL').css('border-bottom-color', config.tips[1]);
  465. }];
  466. goal.where[guide - 1]();
  467. /* 8*2为小三角形占据的空间 */
  468. if (guide === 1) {
  469. goal.top - (win.scrollTop() + layArea[1] + 8 * 2) < 0 && goal.where[2]();
  470. } else if (guide === 2) {
  471. win.width() - (goal.left + goal.width + layArea[0] + 8 * 2) > 0 || goal.where[3]()
  472. } else if (guide === 3) {
  473. (goal.top - win.scrollTop() + goal.height + layArea[1] + 8 * 2) - win.height() > 0 && goal.where[0]();
  474. } else if (guide === 4) {
  475. layArea[0] + 8 * 2 - goal.left > 0 && goal.where[1]()
  476. }
  477. layero.find('.' + doms[5]).css({
  478. 'background-color': config.tips[1],
  479. 'padding-right': (config.closeBtn ? '30px' : '')
  480. });
  481. layero.css({
  482. left: goal.tipLeft - (config.fixed ? win.scrollLeft() : 0),
  483. top: goal.tipTop - (config.fixed ? win.scrollTop() : 0)
  484. });
  485. }
  486. //拖拽层
  487. Class.pt.move = function() {
  488. var that = this,
  489. config = that.config,
  490. _DOC = $(document),
  491. layero = that.layero,
  492. moveElem = layero.find(config.move),
  493. resizeElem = layero.find('.layui-layer-resize'),
  494. dict = {};
  495. if (config.move) {
  496. moveElem.css('cursor', 'move');
  497. }
  498. moveElem.on('mousedown', function(e) {
  499. e.preventDefault();
  500. if (config.move) {
  501. dict.moveStart = true;
  502. dict.offset = [
  503. e.clientX - parseFloat(layero.css('left')), e.clientY - parseFloat(layero.css('top'))
  504. ];
  505. ready.moveElem.css('cursor', 'move').show();
  506. }
  507. });
  508. resizeElem.on('mousedown', function(e) {
  509. e.preventDefault();
  510. dict.resizeStart = true;
  511. dict.offset = [e.clientX, e.clientY];
  512. dict.area = [
  513. layero.outerWidth(), layero.outerHeight()
  514. ];
  515. ready.moveElem.css('cursor', 'se-resize').show();
  516. });
  517. _DOC.on('mousemove', function(e) {
  518. //拖拽移动
  519. if (dict.moveStart) {
  520. var X = e.clientX - dict.offset[0],
  521. Y = e.clientY - dict.offset[1],
  522. fixed = layero.css('position') === 'fixed';
  523. e.preventDefault();
  524. dict.stX = fixed ? 0 : win.scrollLeft();
  525. dict.stY = fixed ? 0 : win.scrollTop();
  526. //控制元素不被拖出窗口外
  527. if (!config.moveOut) {
  528. var setRig = win.width() - layero.outerWidth() + dict.stX,
  529. setBot = win.height() - layero.outerHeight() + dict.stY;
  530. X < dict.stX && (X = dict.stX);
  531. X > setRig && (X = setRig);
  532. Y < dict.stY && (Y = dict.stY);
  533. Y > setBot && (Y = setBot);
  534. }
  535. layero.css({
  536. left: X,
  537. top: Y
  538. });
  539. }
  540. //Resize
  541. if (config.resize && dict.resizeStart) {
  542. var X = e.clientX - dict.offset[0],
  543. Y = e.clientY - dict.offset[1];
  544. e.preventDefault();
  545. layer.style(that.index, {
  546. width: dict.area[0] + X,
  547. height: dict.area[1] + Y
  548. })
  549. dict.isResize = true;
  550. config.resizing && config.resizing(layero);
  551. }
  552. }).on('mouseup', function(e) {
  553. if (dict.moveStart) {
  554. delete dict.moveStart;
  555. ready.moveElem.hide();
  556. config.moveEnd && config.moveEnd(layero);
  557. }
  558. if (dict.resizeStart) {
  559. delete dict.resizeStart;
  560. ready.moveElem.hide();
  561. }
  562. });
  563. return that;
  564. };
  565. Class.pt.callback = function() {
  566. var that = this,
  567. layero = that.layero,
  568. config = that.config;
  569. that.openLayer();
  570. if (config.success) {
  571. if (config.type == 2) {
  572. layero.find('iframe').on('load', function() {
  573. config.success(layero, that.index);
  574. });
  575. } else {
  576. config.success(layero, that.index);
  577. }
  578. }
  579. layer.ie == 6 && that.IE6(layero);
  580. //按钮
  581. layero.find('.' + doms[6]).children('a').on('click', function() {
  582. var index = $(this).index();
  583. if (index === 0) {
  584. if (config.yes) {
  585. config.yes(that.index, layero)
  586. } else if (config['btn1']) {
  587. config['btn1'](that.index, layero)
  588. } else {
  589. layer.close(that.index);
  590. }
  591. } else {
  592. var close = config['btn' + (index + 1)] && config['btn' + (index + 1)](that.index, layero);
  593. close === false || layer.close(that.index);
  594. }
  595. });
  596. //取消
  597. function cancel() {
  598. var close = config.cancel && config.cancel(that.index, layero);
  599. close === false || layer.close(that.index);
  600. }
  601. //右上角关闭回调
  602. layero.find('.' + doms[7]).on('click', cancel);
  603. //点遮罩关闭
  604. if (config.shadeClose) {
  605. $('#layui-layer-shade' + that.index).on('click', function() {
  606. layer.close(that.index);
  607. });
  608. }
  609. //最小化
  610. layero.find('.layui-layer-min').on('click', function() {
  611. var min = config.min && config.min(layero);
  612. min === false || layer.min(that.index, config);
  613. });
  614. //全屏/还原
  615. layero.find('.layui-layer-max').on('click', function() {
  616. if ($(this).hasClass('layui-layer-maxmin')) {
  617. layer.restore(that.index);
  618. config.restore && config.restore(layero);
  619. } else {
  620. layer.full(that.index, config);
  621. setTimeout(function() {
  622. config.full && config.full(layero);
  623. }, 100);
  624. }
  625. });
  626. config.end && (ready.end[that.index] = config.end);
  627. };
  628. //for ie6 恢复select
  629. ready.reselect = function() {
  630. $.each($('select'), function(index, value) {
  631. var sthis = $(this);
  632. if (!sthis.parents('.' + doms[0])[0]) {
  633. (sthis.attr('layer') == 1 && $('.' + doms[0]).length < 1) && sthis.removeAttr('layer').show();
  634. }
  635. sthis = null;
  636. });
  637. };
  638. Class.pt.IE6 = function(layero) {
  639. //隐藏select
  640. $('select').each(function(index, value) {
  641. var sthis = $(this);
  642. if (!sthis.parents('.' + doms[0])[0]) {
  643. sthis.css('display') === 'none' || sthis.attr({ 'layer': '1' }).hide();
  644. }
  645. sthis = null;
  646. });
  647. };
  648. //需依赖原型的对外方法
  649. Class.pt.openLayer = function() {
  650. var that = this;
  651. //置顶当前窗口
  652. layer.zIndex = that.config.zIndex;
  653. layer.setTop = function(layero) {
  654. var setZindex = function() {
  655. layer.zIndex++;
  656. layero.css('z-index', layer.zIndex + 1);
  657. };
  658. layer.zIndex = parseInt(layero[0].style.zIndex);
  659. layero.on('mousedown', setZindex);
  660. return layer.zIndex;
  661. };
  662. };
  663. ready.record = function(layero) {
  664. var area = [
  665. layero.width(),
  666. layero.height(),
  667. layero.position().top,
  668. layero.position().left + parseFloat(layero.css('margin-left'))
  669. ];
  670. layero.find('.layui-layer-max').addClass('layui-layer-maxmin');
  671. layero.attr({ area: area });
  672. };
  673. ready.rescollbar = function(index) {
  674. if (doms.html.attr('layer-full') == index) {
  675. if (doms.html[0].style.removeProperty) {
  676. doms.html[0].style.removeProperty('overflow');
  677. } else {
  678. doms.html[0].style.removeAttribute('overflow');
  679. }
  680. doms.html.removeAttr('layer-full');
  681. }
  682. };
  683. /** 内置成员 */
  684. window.layer = layer;
  685. //获取子iframe的DOM
  686. layer.getChildFrame = function(selector, index) {
  687. index = index || $('.' + doms[4]).attr('times');
  688. return $('#' + doms[0] + index).find('iframe').contents().find(selector);
  689. };
  690. //得到当前iframe层的索引,子iframe时使用
  691. layer.getFrameIndex = function(name) {
  692. return $('#' + name).parents('.' + doms[4]).attr('times');
  693. };
  694. //iframe层自适应宽高
  695. layer.iframeAuto = function(index) {
  696. if (!index) return;
  697. var heg = layer.getChildFrame('html', index).outerHeight();
  698. var layero = $('#' + doms[0] + index);
  699. var titHeight = layero.find(doms[1]).outerHeight() || 0;
  700. var btnHeight = layero.find('.' + doms[6]).outerHeight() || 0;
  701. layero.css({ height: heg + titHeight + btnHeight });
  702. layero.find('iframe').css({ height: heg });
  703. };
  704. //重置iframe url
  705. layer.iframeSrc = function(index, url) {
  706. $('#' + doms[0] + index).find('iframe').attr('src', url);
  707. };
  708. //设定层的样式
  709. layer.style = function(index, options, limit) {
  710. var layero = $('#' + doms[0] + index),
  711. contElem = layero.find('.layui-layer-content'),
  712. type = layero.attr('type'),
  713. titHeight = layero.find(doms[1]).outerHeight() || 0,
  714. btnHeight = layero.find('.' + doms[6]).outerHeight() || 0,
  715. minLeft = layero.attr('minLeft');
  716. if (type === ready.type[3] || type === ready.type[4]) {
  717. return;
  718. }
  719. if (!limit) {
  720. if (parseFloat(options.width) <= 260) {
  721. options.width = 260;
  722. };
  723. if (parseFloat(options.height) - titHeight - btnHeight <= 64) {
  724. options.height = 64 + titHeight + btnHeight;
  725. };
  726. }
  727. layero.css(options);
  728. btnHeight = layero.find('.' + doms[6]).outerHeight();
  729. if (type === ready.type[2]) {
  730. layero.find('iframe').css({
  731. height: parseFloat(options.height) - titHeight - btnHeight
  732. });
  733. } else {
  734. contElem.css({
  735. height: parseFloat(options.height) - titHeight - btnHeight -
  736. parseFloat(contElem.css('padding-top')) -
  737. parseFloat(contElem.css('padding-bottom'))
  738. })
  739. }
  740. };
  741. //最小化
  742. layer.min = function(index, options) {
  743. var layero = $('#' + doms[0] + index),
  744. titHeight = layero.find(doms[1]).outerHeight() || 0,
  745. left = layero.attr('minLeft') || (181 * ready.minIndex) + 'px',
  746. position = layero.css('position');
  747. ready.record(layero);
  748. if (ready.minLeft[0]) {
  749. left = ready.minLeft[0];
  750. ready.minLeft.shift();
  751. }
  752. layero.attr('position', position);
  753. layer.style(index, {
  754. width: 180,
  755. height: titHeight,
  756. left: left,
  757. top: win.height() - titHeight,
  758. position: 'fixed',
  759. overflow: 'hidden'
  760. }, true);
  761. layero.find('.layui-layer-min').hide();
  762. layero.attr('type') === 'page' && layero.find(doms[4]).hide();
  763. ready.rescollbar(index);
  764. if (!layero.attr('minLeft')) {
  765. ready.minIndex++;
  766. }
  767. layero.attr('minLeft', left);
  768. };
  769. //还原
  770. layer.restore = function(index) {
  771. var layero = $('#' + doms[0] + index),
  772. area = layero.attr('area').split(',');
  773. var type = layero.attr('type');
  774. layer.style(index, {
  775. width: parseFloat(area[0]),
  776. height: parseFloat(area[1]),
  777. top: parseFloat(area[2]),
  778. left: parseFloat(area[3]),
  779. position: layero.attr('position'),
  780. overflow: 'visible'
  781. }, true);
  782. layero.find('.layui-layer-max').removeClass('layui-layer-maxmin');
  783. layero.find('.layui-layer-min').show();
  784. layero.attr('type') === 'page' && layero.find(doms[4]).show();
  785. ready.rescollbar(index);
  786. };
  787. //全屏
  788. layer.full = function(index) {
  789. var layero = $('#' + doms[0] + index),
  790. timer;
  791. ready.record(layero);
  792. if (!doms.html.attr('layer-full')) {
  793. doms.html.css('overflow', 'hidden').attr('layer-full', index);
  794. }
  795. clearTimeout(timer);
  796. timer = setTimeout(function() {
  797. var isfix = layero.css('position') === 'fixed';
  798. layer.style(index, {
  799. top: isfix ? 0 : win.scrollTop(),
  800. left: isfix ? 0 : win.scrollLeft(),
  801. width: win.width(),
  802. height: win.height()
  803. }, true);
  804. layero.find('.layui-layer-min').hide();
  805. }, 100);
  806. };
  807. //改变title
  808. layer.title = function(name, index) {
  809. var title = $('#' + doms[0] + (index || layer.index)).find(doms[1]);
  810. title.html(name);
  811. };
  812. //关闭layer总方法
  813. layer.close = function(index) {
  814. var layero = $('#' + doms[0] + index),
  815. type = layero.attr('type'),
  816. closeAnim = 'layer-anim-close';
  817. if (!layero[0]) return;
  818. var WRAP = 'layui-layer-wrap',
  819. remove = function() {
  820. if (type === ready.type[1] && layero.attr('conType') === 'object') {
  821. layero.children(':not(.' + doms[5] + ')').remove();
  822. var wrap = layero.find('.' + WRAP);
  823. for (var i = 0; i < 2; i++) {
  824. wrap.unwrap();
  825. }
  826. wrap.css('display', wrap.data('display')).removeClass(WRAP);
  827. } else {
  828. //低版本IE 回收 iframe
  829. if (type === ready.type[2]) {
  830. try {
  831. var iframe = $('#' + doms[4] + index)[0];
  832. iframe.contentWindow.document.write('');
  833. iframe.contentWindow.close();
  834. layero.find('.' + doms[5])[0].removeChild(iframe);
  835. } catch (e) {}
  836. }
  837. layero[0].innerHTML = '';
  838. layero.remove();
  839. }
  840. typeof ready.end[index] === 'function' && ready.end[index]();
  841. delete ready.end[index];
  842. };
  843. if (layero.data('isOutAnim')) {
  844. layero.addClass('layer-anim ' + closeAnim);
  845. }
  846. $('#layui-layer-moves, #layui-layer-shade' + index).remove();
  847. layer.ie == 6 && ready.reselect();
  848. ready.rescollbar(index);
  849. if (layero.attr('minLeft')) {
  850. ready.minIndex--;
  851. ready.minLeft.push(layero.attr('minLeft'));
  852. }
  853. if ((layer.ie && layer.ie < 10) || !layero.data('isOutAnim')) {
  854. remove()
  855. } else {
  856. setTimeout(function() {
  857. remove();
  858. }, 200);
  859. }
  860. };
  861. //关闭所有层
  862. layer.closeAll = function(type) {
  863. $.each($('.' + doms[0]), function() {
  864. var othis = $(this);
  865. var is = type ? (othis.attr('type') === type) : 1;
  866. is && layer.close(othis.attr('times'));
  867. is = null;
  868. });
  869. };
  870. /**
  871. 拓展模块,layui开始合并在一起
  872. */
  873. var cache = layer.cache || {},
  874. skin = function(type) {
  875. return (cache.skin ? (' ' + cache.skin + ' ' + cache.skin + '-' + type) : '');
  876. };
  877. //仿系统prompt
  878. layer.prompt = function(options, yes) {
  879. var style = '';
  880. options = options || {};
  881. if (typeof options === 'function') yes = options;
  882. if (options.area) {
  883. var area = options.area;
  884. style = 'style="width: ' + area[0] + '; height: ' + area[1] + ';"';
  885. delete options.area;
  886. }
  887. var prompt, content = options.formType == 2 ? '<textarea class="layui-layer-input"' + style + '></textarea>' : function() {
  888. return '<input type="' + (options.formType == 1 ? 'password' : 'text') + '" class="layui-layer-input">';
  889. }();
  890. var success = options.success;
  891. delete options.success;
  892. return layer.open($.extend({
  893. type: 1,
  894. btn: ['&#x786E;&#x5B9A;', '&#x53D6;&#x6D88;'],
  895. content: content,
  896. skin: 'layui-layer-prompt' + skin('prompt'),
  897. maxWidth: win.width(),
  898. success: function(layero) {
  899. prompt = layero.find('.layui-layer-input');
  900. prompt.val(options.value || '').focus();
  901. typeof success === 'function' && success(layero);
  902. },
  903. resize: false,
  904. yes: function(index) {
  905. var value = prompt.val();
  906. if (value === '') {
  907. prompt.focus();
  908. } else if (value.length > (options.maxlength || 500)) {
  909. layer.tips('&#x6700;&#x591A;&#x8F93;&#x5165;' + (options.maxlength || 500) + '&#x4E2A;&#x5B57;&#x6570;', prompt, { tips: 1 });
  910. } else {
  911. yes && yes(value, index, prompt);
  912. }
  913. }
  914. }, options));
  915. };
  916. //tab层
  917. layer.tab = function(options) {
  918. options = options || {};
  919. var tab = options.tab || {},
  920. THIS = 'layui-this',
  921. success = options.success;
  922. delete options.success;
  923. return layer.open($.extend({
  924. type: 1,
  925. skin: 'layui-layer-tab' + skin('tab'),
  926. resize: false,
  927. title: function() {
  928. var len = tab.length,
  929. ii = 1,
  930. str = '';
  931. if (len > 0) {
  932. str = '<span class="' + THIS + '">' + tab[0].title + '</span>';
  933. for (; ii < len; ii++) {
  934. str += '<span>' + tab[ii].title + '</span>';
  935. }
  936. }
  937. return str;
  938. }(),
  939. content: '<ul class="layui-layer-tabmain">' + function() {
  940. var len = tab.length,
  941. ii = 1,
  942. str = '';
  943. if (len > 0) {
  944. str = '<li class="layui-layer-tabli ' + THIS + '">' + (tab[0].content || 'no content') + '</li>';
  945. for (; ii < len; ii++) {
  946. str += '<li class="layui-layer-tabli">' + (tab[ii].content || 'no content') + '</li>';
  947. }
  948. }
  949. return str;
  950. }() + '</ul>',
  951. success: function(layero) {
  952. var btn = layero.find('.layui-layer-title').children();
  953. var main = layero.find('.layui-layer-tabmain').children();
  954. btn.on('mousedown', function(e) {
  955. e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
  956. var othis = $(this),
  957. index = othis.index();
  958. othis.addClass(THIS).siblings().removeClass(THIS);
  959. main.eq(index).show().siblings().hide();
  960. typeof options.change === 'function' && options.change(index);
  961. });
  962. typeof success === 'function' && success(layero);
  963. }
  964. }, options));
  965. };
  966. //相册层
  967. layer.photos = function(options, loop, key) {
  968. var dict = {};
  969. options = options || {};
  970. if (!options.photos) return;
  971. var type = options.photos.constructor === Object;
  972. var photos = type ? options.photos : {},
  973. data = photos.data || [];
  974. var start = photos.start || 0;
  975. dict.imgIndex = (start | 0) + 1;
  976. options.img = options.img || 'img';
  977. var success = options.success;
  978. delete options.success;
  979. if (!type) { //页面直接获取
  980. var parent = $(options.photos),
  981. pushData = function() {
  982. data = [];
  983. parent.find(options.img).each(function(index) {
  984. var othis = $(this);
  985. othis.attr('layer-index', index);
  986. data.push({
  987. alt: othis.attr('alt'),
  988. pid: othis.attr('layer-pid'),
  989. src: othis.attr('layer-src') || othis.attr('src'),
  990. thumb: othis.attr('src')
  991. });
  992. })
  993. };
  994. pushData();
  995. if (data.length === 0) return;
  996. loop || parent.on('click', options.img, function() {
  997. var othis = $(this),
  998. index = othis.attr('layer-index');
  999. layer.photos($.extend(options, {
  1000. photos: {
  1001. start: index,
  1002. data: data,
  1003. tab: options.tab
  1004. },
  1005. full: options.full
  1006. }), true);
  1007. pushData();
  1008. })
  1009. //不直接弹出
  1010. if (!loop) return;
  1011. } else if (data.length === 0) {
  1012. return layer.msg('&#x6CA1;&#x6709;&#x56FE;&#x7247;');
  1013. }
  1014. //上一张
  1015. dict.imgprev = function(key) {
  1016. dict.imgIndex--;
  1017. if (dict.imgIndex < 1) {
  1018. dict.imgIndex = data.length;
  1019. }
  1020. dict.tabimg(key);
  1021. };
  1022. //下一张
  1023. dict.imgnext = function(key, errorMsg) {
  1024. dict.imgIndex++;
  1025. if (dict.imgIndex > data.length) {
  1026. dict.imgIndex = 1;
  1027. if (errorMsg) { return };
  1028. }
  1029. dict.tabimg(key)
  1030. };
  1031. //方向键
  1032. dict.keyup = function(event) {
  1033. if (!dict.end) {
  1034. var code = event.keyCode;
  1035. event.preventDefault();
  1036. if (code === 37) {
  1037. dict.imgprev(true);
  1038. } else if (code === 39) {
  1039. dict.imgnext(true);
  1040. } else if (code === 27) {
  1041. layer.close(dict.index);
  1042. }
  1043. }
  1044. }
  1045. //切换
  1046. dict.tabimg = function(key) {
  1047. if (data.length <= 1) return;
  1048. photos.start = dict.imgIndex - 1;
  1049. layer.close(dict.index);
  1050. return layer.photos(options, true, key);
  1051. setTimeout(function() {
  1052. layer.photos(options, true, key);
  1053. }, 200);
  1054. }
  1055. //一些动作
  1056. dict.event = function() {
  1057. dict.bigimg.hover(function() {
  1058. dict.imgsee.show();
  1059. }, function() {
  1060. dict.imgsee.hide();
  1061. });
  1062. dict.bigimg.find('.layui-layer-imgprev').on('click', function(event) {
  1063. event.preventDefault();
  1064. dict.imgprev();
  1065. });
  1066. dict.bigimg.find('.layui-layer-imgnext').on('click', function(event) {
  1067. event.preventDefault();
  1068. dict.imgnext();
  1069. });
  1070. $(document).on('keyup', dict.keyup);
  1071. };
  1072. //图片预加载
  1073. function loadImage(url, callback, error) {
  1074. var img = new Image();
  1075. img.src = url;
  1076. if (img.complete) {
  1077. return callback(img);
  1078. }
  1079. img.onload = function() {
  1080. img.onload = null;
  1081. callback(img);
  1082. };
  1083. img.onerror = function(e) {
  1084. img.onerror = null;
  1085. error(e);
  1086. };
  1087. };
  1088. dict.loadi = layer.load(1, {
  1089. shade: 'shade' in options ? false : 0.9,
  1090. scrollbar: false
  1091. });
  1092. loadImage(data[start].src, function(img) {
  1093. layer.close(dict.loadi);
  1094. dict.index = layer.open($.extend({
  1095. type: 1,
  1096. id: 'layui-layer-photos',
  1097. area: function() {
  1098. var imgarea = [img.width, img.height];
  1099. var winarea = [$(window).width() - 100, $(window).height() - 100];
  1100. //如果 实际图片的宽或者高比 屏幕大(那么进行缩放)
  1101. if (!options.full && (imgarea[0] > winarea[0] || imgarea[1] > winarea[1])) {
  1102. var wh = [imgarea[0] / winarea[0], imgarea[1] / winarea[1]]; //取宽度缩放比例、高度缩放比例
  1103. if (wh[0] > wh[1]) { //取缩放比例最大的进行缩放
  1104. imgarea[0] = imgarea[0] / wh[0];
  1105. imgarea[1] = imgarea[1] / wh[0];
  1106. } else if (wh[0] < wh[1]) {
  1107. imgarea[0] = imgarea[0] / wh[1];
  1108. imgarea[1] = imgarea[1] / wh[1];
  1109. }
  1110. }
  1111. return [imgarea[0] + 'px', imgarea[1] + 'px'];
  1112. }(),
  1113. title: false,
  1114. shade: 0.9,
  1115. closeBtn: false,
  1116. move: '.layui-layer-phimg img',
  1117. moveType: 1,
  1118. scrollbar: false,
  1119. moveOut: true,
  1120. //anim: Math.random()*5|0,
  1121. isOutAnim: false,
  1122. skin: 'layui-layer-photos' + skin('photos'),
  1123. content: '<div class="layui-layer-phimg">' +
  1124. '<img src="' + data[start].src + '" alt="' + (data[start].alt || '') + '" layer-pid="' + data[start].pid + '">' +
  1125. '<div class="layui-layer-imgsee">' +
  1126. (data.length > 1 ? '<span class="layui-layer-imguide"><a href="javascript:;" class="layui-layer-iconext layui-layer-imgprev"></a><a href="javascript:;" class="layui-layer-iconext layui-layer-imgnext"></a></span>' : '') +
  1127. '<div class="layui-layer-imgbar" style="display:' + (key ? 'block' : '') + '"><span class="layui-layer-imgtit"><a href="javascript:;">' + (data[start].alt || '') + '</a><em>' + dict.imgIndex + '/' + data.length + '</em></span></div>' +
  1128. '</div>' +
  1129. '</div>',
  1130. success: function(layero, index) {
  1131. dict.bigimg = layero.find('.layui-layer-phimg');
  1132. dict.imgsee = layero.find('.layui-layer-imguide,.layui-layer-imgbar');
  1133. dict.event(layero);
  1134. options.tab && options.tab(data[start], layero);
  1135. typeof success === 'function' && success(layero);
  1136. },
  1137. end: function() {
  1138. dict.end = true;
  1139. $(document).off('keyup', dict.keyup);
  1140. }
  1141. }, options));
  1142. }, function() {
  1143. layer.close(dict.loadi);
  1144. layer.msg('&#x5F53;&#x524D;&#x56FE;&#x7247;&#x5730;&#x5740;&#x5F02;&#x5E38;<br>&#x662F;&#x5426;&#x7EE7;&#x7EED;&#x67E5;&#x770B;&#x4E0B;&#x4E00;&#x5F20;&#xFF1F;', {
  1145. time: 30000,
  1146. btn: ['&#x4E0B;&#x4E00;&#x5F20;', '&#x4E0D;&#x770B;&#x4E86;'],
  1147. yes: function() {
  1148. data.length > 1 && dict.imgnext(true, true);
  1149. }
  1150. });
  1151. });
  1152. };
  1153. //主入口
  1154. ready.run = function(_$) {
  1155. $ = _$;
  1156. win = $(window);
  1157. doms.html = $('html');
  1158. layer.open = function(deliver) {
  1159. var o = new Class(deliver);
  1160. return o.index;
  1161. };
  1162. };
  1163. //加载方式
  1164. window.layui && layui.define ? (
  1165. layer.ready(), layui.define('jquery', function(exports) { //layui加载
  1166. layer.path = layui.cache.dir;
  1167. ready.run(layui.$);
  1168. //暴露模块
  1169. window.layer = layer;
  1170. exports('layer', layer);
  1171. })
  1172. ) : (
  1173. (typeof define === 'function' && define.amd) ? define(['jquery'], function() { //requirejs加载
  1174. ready.run(window.jQuery);
  1175. return layer;
  1176. }) : function() { //普通script标签加载
  1177. ready.run(window.jQuery);
  1178. layer.ready();
  1179. }()
  1180. );
  1181. }(window);