layer.js 39 KB

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