layer.js 47 KB

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