酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1422 lines
42 KiB

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