layer.js 38 KB

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