rails-layer 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rails-layer.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 yuanchang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Rails::Layer
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails/layer`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rails-layer'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rails-layer
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails-layer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Rails::Layer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rails-layer/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails/layer"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require "rails/layer/version"
2
+
3
+ module Rails
4
+ module Layer
5
+ class Error < StandardError; end
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ # Your code goes here...
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Rails
2
+ module Layer
3
+ VERSION = "0.1.2"
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rails/layer/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails-layer"
8
+ spec.version = Rails::Layer::VERSION
9
+ spec.authors = ["yuanchang"]
10
+ spec.email = ["759337828@qq.com"]
11
+
12
+ spec.summary = %q{layer插件的gem包}
13
+ spec.description = %q{一款基于layer插件的rails assets gem 包.}
14
+ spec.homepage = "https://github.com/rubyyc/rails-layer"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/rubyyc/rails-layer"
24
+ spec.metadata["changelog_uri"] = "https://github.com/rubyyc/rails-layer/blob/master/README.md"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,1311 @@
1
+ /**
2
+
3
+ @Name:layer v3.1.1 Web弹层组件
4
+ @Author:贤心
5
+ @Site:http://layer.layui.com
6
+ @License:MIT
7
+
8
+ */
9
+
10
+ ;!function(window, undefined){
11
+ "use strict";
12
+
13
+ var isLayui = window.layui && layui.define, $, win, ready = {
14
+ getPath: function(){
15
+ var jsPath = document.currentScript ? document.currentScript.src : function(){
16
+ var js = document.scripts
17
+ ,last = js.length - 1
18
+ ,src;
19
+ for(var i = last; i > 0; i--){
20
+ if(js[i].readyState === 'interactive'){
21
+ src = js[i].src;
22
+ break;
23
+ }
24
+ }
25
+ return src || js[last].src;
26
+ }();
27
+ return jsPath.substring(0, jsPath.lastIndexOf('/') + 1);
28
+ }(),
29
+
30
+ config: {}, end: {}, minIndex: 0, minLeft: [],
31
+ btn: ['&#x786E;&#x5B9A;', '&#x53D6;&#x6D88;'],
32
+
33
+ //五种原始层模式
34
+ type: ['dialog', 'page', 'iframe', 'loading', 'tips'],
35
+
36
+ //获取节点的style属性值
37
+ getStyle: function(node, name){
38
+ var style = node.currentStyle ? node.currentStyle : window.getComputedStyle(node, null);
39
+ return style[style.getPropertyValue ? 'getPropertyValue' : 'getAttribute'](name);
40
+ },
41
+
42
+ //载入CSS配件
43
+ link: function(href, fn, cssname){
44
+
45
+ //未设置路径,则不主动加载css
46
+ if(!layer.path) return;
47
+
48
+ var head = document.getElementsByTagName("head")[0], link = document.createElement('link');
49
+ if(typeof fn === 'string') cssname = fn;
50
+ var app = (cssname || href).replace(/\.|\//g, '');
51
+ var id = 'layuicss-'+ app, timeout = 0;
52
+
53
+ link.rel = 'stylesheet';
54
+ link.href = layer.path + href;
55
+ link.id = id;
56
+
57
+ if(!document.getElementById(id)){
58
+ head.appendChild(link);
59
+ }
60
+
61
+ if(typeof fn !== 'function') return;
62
+
63
+ //轮询css是否加载完毕
64
+ (function poll() {
65
+ if(++timeout > 8 * 1000 / 100){
66
+ return window.console && console.error('layer.css: Invalid');
67
+ };
68
+ parseInt(ready.getStyle(document.getElementById(id), 'width')) === 1989 ? fn() : setTimeout(poll, 100);
69
+ }());
70
+ }
71
+ };
72
+
73
+ //默认内置方法。
74
+ var layer = {
75
+ v: '3.1.1',
76
+ ie: function(){ //ie版本
77
+ var agent = navigator.userAgent.toLowerCase();
78
+ return (!!window.ActiveXObject || "ActiveXObject" in window) ? (
79
+ (agent.match(/msie\s(\d+)/) || [])[1] || '11' //由于ie11并没有msie的标识
80
+ ) : false;
81
+ }(),
82
+ index: (window.layer && window.layer.v) ? 100000 : 0,
83
+ path: ready.getPath,
84
+ config: function(options, fn){
85
+ options = options || {};
86
+ layer.cache = ready.config = $.extend({}, ready.config, options);
87
+ layer.path = ready.config.path || layer.path;
88
+ typeof options.extend === 'string' && (options.extend = [options.extend]);
89
+
90
+ if(ready.config.path) layer.ready();
91
+
92
+ if(!options.extend) return this;
93
+
94
+ isLayui
95
+ ? layui.addcss('modules/layer/' + options.extend)
96
+ : ready.link('theme/' + options.extend);
97
+
98
+ return this;
99
+ },
100
+
101
+ //主体CSS等待事件
102
+ // ready: function(callback){
103
+ // var cssname = 'layer', ver = ''
104
+ // ,path = (isLayui ? 'modules/layer/' : 'theme/') + 'default/layer.css?v='+ layer.v + ver;
105
+ // isLayui ? layui.addcss(path, callback, cssname) : ready.link(path, callback, cssname);
106
+ // return this;
107
+ // },
108
+
109
+ ready: function(callback){
110
+ var cssname = 'layer', ver = ''
111
+ ,path = (isLayui ? 'modules/layer/' : 'layer.scss') + '?v='+ layer.v + ver;
112
+ isLayui ? layui.addcss(path, callback, cssname) : ready.link(path, callback, cssname);
113
+ return this;
114
+ },
115
+
116
+ //各种快捷引用
117
+ alert: function(content, options, yes){
118
+ var type = typeof options === 'function';
119
+ if(type) yes = options;
120
+ return layer.open($.extend({
121
+ content: content,
122
+ yes: yes
123
+ }, type ? {} : options));
124
+ },
125
+
126
+ confirm: function(content, options, yes, cancel){
127
+ var type = typeof options === 'function';
128
+ if(type){
129
+ cancel = yes;
130
+ yes = options;
131
+ }
132
+ return layer.open($.extend({
133
+ content: content,
134
+ btn: ready.btn,
135
+ yes: yes,
136
+ btn2: cancel
137
+ }, type ? {} : options));
138
+ },
139
+
140
+ msg: function(content, options, end){ //最常用提示层
141
+ var type = typeof options === 'function', rskin = ready.config.skin;
142
+ var skin = (rskin ? rskin + ' ' + rskin + '-msg' : '')||'layui-layer-msg';
143
+ var anim = doms.anim.length - 1;
144
+ if(type) end = options;
145
+ return layer.open($.extend({
146
+ content: content,
147
+ time: 3000,
148
+ shade: false,
149
+ skin: skin,
150
+ title: false,
151
+ closeBtn: false,
152
+ btn: false,
153
+ resize: false,
154
+ end: end
155
+ }, (type && !ready.config.skin) ? {
156
+ skin: skin + ' layui-layer-hui',
157
+ anim: anim
158
+ } : function(){
159
+ options = options || {};
160
+ if(options.icon === -1 || options.icon === undefined && !ready.config.skin){
161
+ options.skin = skin + ' ' + (options.skin||'layui-layer-hui');
162
+ }
163
+ return options;
164
+ }()));
165
+ },
166
+
167
+ load: function(icon, options){
168
+ return layer.open($.extend({
169
+ type: 3,
170
+ icon: icon || 0,
171
+ resize: false,
172
+ shade: 0.01
173
+ }, options));
174
+ },
175
+
176
+ tips: function(content, follow, options){
177
+ return layer.open($.extend({
178
+ type: 4,
179
+ content: [content, follow],
180
+ closeBtn: false,
181
+ time: 3000,
182
+ shade: false,
183
+ resize: false,
184
+ fixed: false,
185
+ maxWidth: 210
186
+ }, options));
187
+ }
188
+ };
189
+
190
+ var Class = function(setings){
191
+ var that = this;
192
+ that.index = ++layer.index;
193
+ that.config = $.extend({}, that.config, ready.config, setings);
194
+ document.body ? that.creat() : setTimeout(function(){
195
+ that.creat();
196
+ }, 30);
197
+ };
198
+
199
+ Class.pt = Class.prototype;
200
+
201
+ //缓存常用字符
202
+ 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'];
203
+ doms.anim = ['layer-anim-00', 'layer-anim-01', 'layer-anim-02', 'layer-anim-03', 'layer-anim-04', 'layer-anim-05', 'layer-anim-06'];
204
+
205
+ //默认配置
206
+ Class.pt.config = {
207
+ type: 0,
208
+ shade: 0.3,
209
+ fixed: true,
210
+ move: doms[1],
211
+ title: '&#x4FE1;&#x606F;',
212
+ offset: 'auto',
213
+ area: 'auto',
214
+ closeBtn: 1,
215
+ time: 0, //0表示不自动关闭
216
+ zIndex: 19891014,
217
+ maxWidth: 360,
218
+ anim: 0,
219
+ isOutAnim: true,
220
+ icon: -1,
221
+ moveType: 1,
222
+ resize: true,
223
+ scrollbar: true, //是否允许浏览器滚动条
224
+ tips: 2
225
+ };
226
+
227
+ //容器
228
+ Class.pt.vessel = function(conType, callback){
229
+ var that = this, times = that.index, config = that.config;
230
+ var zIndex = config.zIndex + times, titype = typeof config.title === 'object';
231
+ var ismax = config.maxmin && (config.type === 1 || config.type === 2);
232
+ var titleHTML = (config.title ? '<div class="layui-layer-title" style="'+ (titype ? config.title[1] : '') +'">'
233
+ + (titype ? config.title[0] : config.title)
234
+ + '</div>' : '');
235
+
236
+ config.zIndex = zIndex;
237
+ callback([
238
+ //遮罩
239
+ config.shade ? ('<div class="layui-layer-shade" id="layui-layer-shade'+ times +'" times="'+ times +'" style="'+ ('z-index:'+ (zIndex-1) +'; ') +'"></div>') : '',
240
+
241
+ //主体
242
+ '<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;') +'">'
243
+ + (conType && config.type != 2 ? '' : titleHTML)
244
+ + '<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 : '') +'">'
245
+ + (config.type == 0 && config.icon !== -1 ? '<i class="layui-layer-ico layui-layer-ico'+ config.icon +'"></i>' : '')
246
+ + (config.type == 1 && conType ? '' : (config.content||''))
247
+ + '</div>'
248
+ + '<span class="layui-layer-setwin">'+ function(){
249
+ var closebtn = ismax ? '<a class="layui-layer-min" href="javascript:;"><cite></cite></a><a class="layui-layer-ico layui-layer-max" href="javascript:;"></a>' : '';
250
+ config.closeBtn && (closebtn += '<a class="layui-layer-ico '+ doms[7] +' '+ doms[7] + (config.title ? config.closeBtn : (config.type == 4 ? '1' : '2')) +'" href="javascript:;"></a>');
251
+ return closebtn;
252
+ }() + '</span>'
253
+ + (config.btn ? function(){
254
+ var button = '';
255
+ typeof config.btn === 'string' && (config.btn = [config.btn]);
256
+ for(var i = 0, len = config.btn.length; i < len; i++){
257
+ button += '<a class="'+ doms[6] +''+ i +'">'+ config.btn[i] +'</a>'
258
+ }
259
+ return '<div class="'+ doms[6] +' layui-layer-btn-'+ (config.btnAlign||'') +'">'+ button +'</div>'
260
+ }() : '')
261
+ + (config.resize ? '<span class="layui-layer-resize"></span>' : '')
262
+ + '</div>'
263
+ ], titleHTML, $('<div class="layui-layer-move"></div>'));
264
+ return that;
265
+ };
266
+
267
+ //创建骨架
268
+ Class.pt.creat = function(){
269
+ var that = this
270
+ ,config = that.config
271
+ ,times = that.index, nodeIndex
272
+ ,content = config.content
273
+ ,conType = typeof content === 'object'
274
+ ,body = $('body');
275
+
276
+ if(config.id && $('#'+config.id)[0]) return;
277
+
278
+ if(typeof config.area === 'string'){
279
+ config.area = config.area === 'auto' ? ['', ''] : [config.area, ''];
280
+ }
281
+
282
+ //anim兼容旧版shift
283
+ if(config.shift){
284
+ config.anim = config.shift;
285
+ }
286
+
287
+ if(layer.ie == 6){
288
+ config.fixed = false;
289
+ }
290
+
291
+ switch(config.type){
292
+ case 0:
293
+ config.btn = ('btn' in config) ? config.btn : ready.btn[0];
294
+ layer.closeAll('dialog');
295
+ break;
296
+ case 2:
297
+ var content = config.content = conType ? config.content : [config.content||'http://layer.layui.com', 'auto'];
298
+ 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>';
299
+ break;
300
+ case 3:
301
+ delete config.title;
302
+ delete config.closeBtn;
303
+ config.icon === -1 && (config.icon === 0);
304
+ layer.closeAll('loading');
305
+ break;
306
+ case 4:
307
+ conType || (config.content = [config.content, 'body']);
308
+ config.follow = config.content[1];
309
+ config.content = config.content[0] + '<i class="layui-layer-TipsG"></i>';
310
+ delete config.title;
311
+ config.tips = typeof config.tips === 'object' ? config.tips : [config.tips, true];
312
+ config.tipsMore || layer.closeAll('tips');
313
+ break;
314
+ }
315
+
316
+ //建立容器
317
+ that.vessel(conType, function(html, titleHTML, moveElem){
318
+ body.append(html[0]);
319
+ conType ? function(){
320
+ (config.type == 2 || config.type == 4) ? function(){
321
+ $('body').append(html[1]);
322
+ }() : function(){
323
+ if(!content.parents('.'+doms[0])[0]){
324
+ content.data('display', content.css('display')).show().addClass('layui-layer-wrap').wrap(html[1]);
325
+ $('#'+ doms[0] + times).find('.'+doms[5]).before(titleHTML);
326
+ }
327
+ }();
328
+ }() : body.append(html[1]);
329
+ $('.layui-layer-move')[0] || body.append(ready.moveElem = moveElem);
330
+ that.layero = $('#'+ doms[0] + times);
331
+ config.scrollbar || doms.html.css('overflow', 'hidden').attr('layer-full', times);
332
+ }).auto(times);
333
+
334
+ //遮罩
335
+ $('#layui-layer-shade'+ that.index).css({
336
+ 'background-color': config.shade[1] || '#000'
337
+ ,'opacity': config.shade[0]||config.shade
338
+ });
339
+
340
+ config.type == 2 && layer.ie == 6 && that.layero.find('iframe').attr('src', content[0]);
341
+
342
+ //坐标自适应浏览器窗口尺寸
343
+ config.type == 4 ? that.tips() : that.offset();
344
+ if(config.fixed){
345
+ win.on('resize', function(){
346
+ that.offset();
347
+ (/^\d+%$/.test(config.area[0]) || /^\d+%$/.test(config.area[1])) && that.auto(times);
348
+ config.type == 4 && that.tips();
349
+ });
350
+ }
351
+
352
+ config.time <= 0 || setTimeout(function(){
353
+ layer.close(that.index)
354
+ }, config.time);
355
+ that.move().callback();
356
+
357
+ //为兼容jQuery3.0的css动画影响元素尺寸计算
358
+ if(doms.anim[config.anim]){
359
+ var animClass = 'layer-anim '+ doms.anim[config.anim];
360
+ that.layero.addClass(animClass).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
361
+ $(this).removeClass(animClass);
362
+ });
363
+ };
364
+
365
+ //记录关闭动画
366
+ if(config.isOutAnim){
367
+ that.layero.data('isOutAnim', true);
368
+ }
369
+ };
370
+
371
+ //自适应
372
+ Class.pt.auto = function(index){
373
+ var that = this, config = that.config, layero = $('#'+ doms[0] + index);
374
+
375
+ if(config.area[0] === '' && config.maxWidth > 0){
376
+ //为了修复IE7下一个让人难以理解的bug
377
+ if(layer.ie && layer.ie < 8 && config.btn){
378
+ layero.width(layero.innerWidth());
379
+ }
380
+ layero.outerWidth() > config.maxWidth && layero.width(config.maxWidth);
381
+ }
382
+
383
+ var area = [layero.innerWidth(), layero.innerHeight()]
384
+ ,titHeight = layero.find(doms[1]).outerHeight() || 0
385
+ ,btnHeight = layero.find('.'+doms[6]).outerHeight() || 0
386
+ ,setHeight = function(elem){
387
+ elem = layero.find(elem);
388
+ elem.height(area[1] - titHeight - btnHeight - 2*(parseFloat(elem.css('padding-top'))|0));
389
+ };
390
+
391
+ switch(config.type){
392
+ case 2:
393
+ setHeight('iframe');
394
+ break;
395
+ default:
396
+ if(config.area[1] === ''){
397
+ if(config.maxHeight > 0 && layero.outerHeight() > config.maxHeight){
398
+ area[1] = config.maxHeight;
399
+ setHeight('.'+doms[5]);
400
+ } else if(config.fixed && area[1] >= win.height()){
401
+ area[1] = win.height();
402
+ setHeight('.'+doms[5]);
403
+ }
404
+ } else {
405
+ setHeight('.'+doms[5]);
406
+ }
407
+ break;
408
+ };
409
+
410
+ return that;
411
+ };
412
+
413
+ //计算坐标
414
+ Class.pt.offset = function(){
415
+ var that = this, config = that.config, layero = that.layero;
416
+ var area = [layero.outerWidth(), layero.outerHeight()];
417
+ var type = typeof config.offset === 'object';
418
+ that.offsetTop = (win.height() - area[1])/2;
419
+ that.offsetLeft = (win.width() - area[0])/2;
420
+
421
+ if(type){
422
+ that.offsetTop = config.offset[0];
423
+ that.offsetLeft = config.offset[1]||that.offsetLeft;
424
+ } else if(config.offset !== 'auto'){
425
+
426
+ if(config.offset === 't'){ //上
427
+ that.offsetTop = 0;
428
+ } else if(config.offset === 'r'){ //右
429
+ that.offsetLeft = win.width() - area[0];
430
+ } else if(config.offset === 'b'){ //下
431
+ that.offsetTop = win.height() - area[1];
432
+ } else if(config.offset === 'l'){ //左
433
+ that.offsetLeft = 0;
434
+ } else if(config.offset === 'lt'){ //左上角
435
+ that.offsetTop = 0;
436
+ that.offsetLeft = 0;
437
+ } else if(config.offset === 'lb'){ //左下角
438
+ that.offsetTop = win.height() - area[1];
439
+ that.offsetLeft = 0;
440
+ } else if(config.offset === 'rt'){ //右上角
441
+ that.offsetTop = 0;
442
+ that.offsetLeft = win.width() - area[0];
443
+ } else if(config.offset === 'rb'){ //右下角
444
+ that.offsetTop = win.height() - area[1];
445
+ that.offsetLeft = win.width() - area[0];
446
+ } else {
447
+ that.offsetTop = config.offset;
448
+ }
449
+
450
+ }
451
+
452
+ if(!config.fixed){
453
+ that.offsetTop = /%$/.test(that.offsetTop) ?
454
+ win.height()*parseFloat(that.offsetTop)/100
455
+ : parseFloat(that.offsetTop);
456
+ that.offsetLeft = /%$/.test(that.offsetLeft) ?
457
+ win.width()*parseFloat(that.offsetLeft)/100
458
+ : parseFloat(that.offsetLeft);
459
+ that.offsetTop += win.scrollTop();
460
+ that.offsetLeft += win.scrollLeft();
461
+ }
462
+
463
+ if(layero.attr('minLeft')){
464
+ that.offsetTop = win.height() - (layero.find(doms[1]).outerHeight() || 0);
465
+ that.offsetLeft = layero.css('left');
466
+ }
467
+
468
+ layero.css({top: that.offsetTop, left: that.offsetLeft});
469
+ };
470
+
471
+ //Tips
472
+ Class.pt.tips = function(){
473
+ var that = this, config = that.config, layero = that.layero;
474
+ var layArea = [layero.outerWidth(), layero.outerHeight()], follow = $(config.follow);
475
+ if(!follow[0]) follow = $('body');
476
+ var goal = {
477
+ width: follow.outerWidth(),
478
+ height: follow.outerHeight(),
479
+ top: follow.offset().top,
480
+ left: follow.offset().left
481
+ }, tipsG = layero.find('.layui-layer-TipsG');
482
+
483
+ var guide = config.tips[0];
484
+ config.tips[1] || tipsG.remove();
485
+
486
+ goal.autoLeft = function(){
487
+ if(goal.left + layArea[0] - win.width() > 0){
488
+ goal.tipLeft = goal.left + goal.width - layArea[0];
489
+ tipsG.css({right: 12, left: 'auto'});
490
+ } else {
491
+ goal.tipLeft = goal.left;
492
+ };
493
+ };
494
+
495
+ //辨别tips的方位
496
+ goal.where = [function(){ //上
497
+ goal.autoLeft();
498
+ goal.tipTop = goal.top - layArea[1] - 10;
499
+ tipsG.removeClass('layui-layer-TipsB').addClass('layui-layer-TipsT').css('border-right-color', config.tips[1]);
500
+ }, function(){ //右
501
+ goal.tipLeft = goal.left + goal.width + 10;
502
+ goal.tipTop = goal.top;
503
+ tipsG.removeClass('layui-layer-TipsL').addClass('layui-layer-TipsR').css('border-bottom-color', config.tips[1]);
504
+ }, function(){ //下
505
+ goal.autoLeft();
506
+ goal.tipTop = goal.top + goal.height + 10;
507
+ tipsG.removeClass('layui-layer-TipsT').addClass('layui-layer-TipsB').css('border-right-color', config.tips[1]);
508
+ }, function(){ //左
509
+ goal.tipLeft = goal.left - layArea[0] - 10;
510
+ goal.tipTop = goal.top;
511
+ tipsG.removeClass('layui-layer-TipsR').addClass('layui-layer-TipsL').css('border-bottom-color', config.tips[1]);
512
+ }];
513
+ goal.where[guide-1]();
514
+
515
+ /* 8*2为小三角形占据的空间 */
516
+ if(guide === 1){
517
+ goal.top - (win.scrollTop() + layArea[1] + 8*2) < 0 && goal.where[2]();
518
+ } else if(guide === 2){
519
+ win.width() - (goal.left + goal.width + layArea[0] + 8*2) > 0 || goal.where[3]()
520
+ } else if(guide === 3){
521
+ (goal.top - win.scrollTop() + goal.height + layArea[1] + 8*2) - win.height() > 0 && goal.where[0]();
522
+ } else if(guide === 4){
523
+ layArea[0] + 8*2 - goal.left > 0 && goal.where[1]()
524
+ }
525
+
526
+ layero.find('.'+doms[5]).css({
527
+ 'background-color': config.tips[1],
528
+ 'padding-right': (config.closeBtn ? '30px' : '')
529
+ });
530
+ layero.css({
531
+ left: goal.tipLeft - (config.fixed ? win.scrollLeft() : 0),
532
+ top: goal.tipTop - (config.fixed ? win.scrollTop() : 0)
533
+ });
534
+ }
535
+
536
+ //拖拽层
537
+ Class.pt.move = function(){
538
+ var that = this
539
+ ,config = that.config
540
+ ,_DOC = $(document)
541
+ ,layero = that.layero
542
+ ,moveElem = layero.find(config.move)
543
+ ,resizeElem = layero.find('.layui-layer-resize')
544
+ ,dict = {};
545
+
546
+ if(config.move){
547
+ moveElem.css('cursor', 'move');
548
+ }
549
+
550
+ moveElem.on('mousedown', function(e){
551
+ e.preventDefault();
552
+ if(config.move){
553
+ dict.moveStart = true;
554
+ dict.offset = [
555
+ e.clientX - parseFloat(layero.css('left'))
556
+ ,e.clientY - parseFloat(layero.css('top'))
557
+ ];
558
+ ready.moveElem.css('cursor', 'move').show();
559
+ }
560
+ });
561
+
562
+ resizeElem.on('mousedown', function(e){
563
+ e.preventDefault();
564
+ dict.resizeStart = true;
565
+ dict.offset = [e.clientX, e.clientY];
566
+ dict.area = [
567
+ layero.outerWidth()
568
+ ,layero.outerHeight()
569
+ ];
570
+ ready.moveElem.css('cursor', 'se-resize').show();
571
+ });
572
+
573
+ _DOC.on('mousemove', function(e){
574
+
575
+ //拖拽移动
576
+ if(dict.moveStart){
577
+ var X = e.clientX - dict.offset[0]
578
+ ,Y = e.clientY - dict.offset[1]
579
+ ,fixed = layero.css('position') === 'fixed';
580
+
581
+ e.preventDefault();
582
+
583
+ dict.stX = fixed ? 0 : win.scrollLeft();
584
+ dict.stY = fixed ? 0 : win.scrollTop();
585
+
586
+ //控制元素不被拖出窗口外
587
+ if(!config.moveOut){
588
+ var setRig = win.width() - layero.outerWidth() + dict.stX
589
+ ,setBot = win.height() - layero.outerHeight() + dict.stY;
590
+ X < dict.stX && (X = dict.stX);
591
+ X > setRig && (X = setRig);
592
+ Y < dict.stY && (Y = dict.stY);
593
+ Y > setBot && (Y = setBot);
594
+ }
595
+
596
+ layero.css({
597
+ left: X
598
+ ,top: Y
599
+ });
600
+ }
601
+
602
+ //Resize
603
+ if(config.resize && dict.resizeStart){
604
+ var X = e.clientX - dict.offset[0]
605
+ ,Y = e.clientY - dict.offset[1];
606
+
607
+ e.preventDefault();
608
+
609
+ layer.style(that.index, {
610
+ width: dict.area[0] + X
611
+ ,height: dict.area[1] + Y
612
+ })
613
+ dict.isResize = true;
614
+ config.resizing && config.resizing(layero);
615
+ }
616
+ }).on('mouseup', function(e){
617
+ if(dict.moveStart){
618
+ delete dict.moveStart;
619
+ ready.moveElem.hide();
620
+ config.moveEnd && config.moveEnd(layero);
621
+ }
622
+ if(dict.resizeStart){
623
+ delete dict.resizeStart;
624
+ ready.moveElem.hide();
625
+ }
626
+ });
627
+
628
+ return that;
629
+ };
630
+
631
+ Class.pt.callback = function(){
632
+ var that = this, layero = that.layero, config = that.config;
633
+ that.openLayer();
634
+ if(config.success){
635
+ if(config.type == 2){
636
+ layero.find('iframe').on('load', function(){
637
+ config.success(layero, that.index);
638
+ });
639
+ } else {
640
+ config.success(layero, that.index);
641
+ }
642
+ }
643
+ layer.ie == 6 && that.IE6(layero);
644
+
645
+ //按钮
646
+ layero.find('.'+ doms[6]).children('a').on('click', function(){
647
+ var index = $(this).index();
648
+ if(index === 0){
649
+ if(config.yes){
650
+ config.yes(that.index, layero)
651
+ } else if(config['btn1']){
652
+ config['btn1'](that.index, layero)
653
+ } else {
654
+ layer.close(that.index);
655
+ }
656
+ } else {
657
+ var close = config['btn'+(index+1)] && config['btn'+(index+1)](that.index, layero);
658
+ close === false || layer.close(that.index);
659
+ }
660
+ });
661
+
662
+ //取消
663
+ function cancel(){
664
+ var close = config.cancel && config.cancel(that.index, layero);
665
+ close === false || layer.close(that.index);
666
+ }
667
+
668
+ //右上角关闭回调
669
+ layero.find('.'+ doms[7]).on('click', cancel);
670
+
671
+ //点遮罩关闭
672
+ if(config.shadeClose){
673
+ $('#layui-layer-shade'+ that.index).on('click', function(){
674
+ layer.close(that.index);
675
+ });
676
+ }
677
+
678
+ //最小化
679
+ layero.find('.layui-layer-min').on('click', function(){
680
+ var min = config.min && config.min(layero);
681
+ min === false || layer.min(that.index, config);
682
+ });
683
+
684
+ //全屏/还原
685
+ layero.find('.layui-layer-max').on('click', function(){
686
+ if($(this).hasClass('layui-layer-maxmin')){
687
+ layer.restore(that.index);
688
+ config.restore && config.restore(layero);
689
+ } else {
690
+ layer.full(that.index, config);
691
+ setTimeout(function(){
692
+ config.full && config.full(layero);
693
+ }, 100);
694
+ }
695
+ });
696
+
697
+ config.end && (ready.end[that.index] = config.end);
698
+ };
699
+
700
+ //for ie6 恢复select
701
+ ready.reselect = function(){
702
+ $.each($('select'), function(index , value){
703
+ var sthis = $(this);
704
+ if(!sthis.parents('.'+doms[0])[0]){
705
+ (sthis.attr('layer') == 1 && $('.'+doms[0]).length < 1) && sthis.removeAttr('layer').show();
706
+ }
707
+ sthis = null;
708
+ });
709
+ };
710
+
711
+ Class.pt.IE6 = function(layero){
712
+ //隐藏select
713
+ $('select').each(function(index , value){
714
+ var sthis = $(this);
715
+ if(!sthis.parents('.'+doms[0])[0]){
716
+ sthis.css('display') === 'none' || sthis.attr({'layer' : '1'}).hide();
717
+ }
718
+ sthis = null;
719
+ });
720
+ };
721
+
722
+ //需依赖原型的对外方法
723
+ Class.pt.openLayer = function(){
724
+ var that = this;
725
+
726
+ //置顶当前窗口
727
+ layer.zIndex = that.config.zIndex;
728
+ layer.setTop = function(layero){
729
+ var setZindex = function(){
730
+ layer.zIndex++;
731
+ layero.css('z-index', layer.zIndex + 1);
732
+ };
733
+ layer.zIndex = parseInt(layero[0].style.zIndex);
734
+ layero.on('mousedown', setZindex);
735
+ return layer.zIndex;
736
+ };
737
+ };
738
+
739
+ ready.record = function(layero){
740
+ var area = [
741
+ layero.width(),
742
+ layero.height(),
743
+ layero.position().top,
744
+ layero.position().left + parseFloat(layero.css('margin-left'))
745
+ ];
746
+ layero.find('.layui-layer-max').addClass('layui-layer-maxmin');
747
+ layero.attr({area: area});
748
+ };
749
+
750
+ ready.rescollbar = function(index){
751
+ if(doms.html.attr('layer-full') == index){
752
+ if(doms.html[0].style.removeProperty){
753
+ doms.html[0].style.removeProperty('overflow');
754
+ } else {
755
+ doms.html[0].style.removeAttribute('overflow');
756
+ }
757
+ doms.html.removeAttr('layer-full');
758
+ }
759
+ };
760
+
761
+ /** 内置成员 */
762
+
763
+ window.layer = layer;
764
+
765
+ //获取子iframe的DOM
766
+ layer.getChildFrame = function(selector, index){
767
+ index = index || $('.'+doms[4]).attr('times');
768
+ return $('#'+ doms[0] + index).find('iframe').contents().find(selector);
769
+ };
770
+
771
+ //得到当前iframe层的索引,子iframe时使用
772
+ layer.getFrameIndex = function(name){
773
+ return $('#'+ name).parents('.'+doms[4]).attr('times');
774
+ };
775
+
776
+ //iframe层自适应宽高
777
+ layer.iframeAuto = function(index){
778
+ if(!index) return;
779
+ var heg = layer.getChildFrame('html', index).outerHeight();
780
+ var layero = $('#'+ doms[0] + index);
781
+ var titHeight = layero.find(doms[1]).outerHeight() || 0;
782
+ var btnHeight = layero.find('.'+doms[6]).outerHeight() || 0;
783
+ layero.css({height: heg + titHeight + btnHeight});
784
+ layero.find('iframe').css({height: heg});
785
+ };
786
+
787
+ //重置iframe url
788
+ layer.iframeSrc = function(index, url){
789
+ $('#'+ doms[0] + index).find('iframe').attr('src', url);
790
+ };
791
+
792
+ //设定层的样式
793
+ layer.style = function(index, options, limit){
794
+ var layero = $('#'+ doms[0] + index)
795
+ ,contElem = layero.find('.layui-layer-content')
796
+ ,type = layero.attr('type')
797
+ ,titHeight = layero.find(doms[1]).outerHeight() || 0
798
+ ,btnHeight = layero.find('.'+doms[6]).outerHeight() || 0
799
+ ,minLeft = layero.attr('minLeft');
800
+
801
+ if(type === ready.type[3] || type === ready.type[4]){
802
+ return;
803
+ }
804
+
805
+ if(!limit){
806
+ if(parseFloat(options.width) <= 260){
807
+ options.width = 260;
808
+ };
809
+
810
+ if(parseFloat(options.height) - titHeight - btnHeight <= 64){
811
+ options.height = 64 + titHeight + btnHeight;
812
+ };
813
+ }
814
+
815
+ layero.css(options);
816
+ btnHeight = layero.find('.'+doms[6]).outerHeight();
817
+
818
+ if(type === ready.type[2]){
819
+ layero.find('iframe').css({
820
+ height: parseFloat(options.height) - titHeight - btnHeight
821
+ });
822
+ } else {
823
+ contElem.css({
824
+ height: parseFloat(options.height) - titHeight - btnHeight
825
+ - parseFloat(contElem.css('padding-top'))
826
+ - parseFloat(contElem.css('padding-bottom'))
827
+ })
828
+ }
829
+ };
830
+
831
+ //最小化
832
+ layer.min = function(index, options){
833
+ var layero = $('#'+ doms[0] + index)
834
+ ,titHeight = layero.find(doms[1]).outerHeight() || 0
835
+ ,left = layero.attr('minLeft') || (181*ready.minIndex)+'px'
836
+ ,position = layero.css('position');
837
+
838
+ ready.record(layero);
839
+
840
+ if(ready.minLeft[0]){
841
+ left = ready.minLeft[0];
842
+ ready.minLeft.shift();
843
+ }
844
+
845
+ layero.attr('position', position);
846
+
847
+ layer.style(index, {
848
+ width: 180
849
+ ,height: titHeight
850
+ ,left: left
851
+ ,top: win.height() - titHeight
852
+ ,position: 'fixed'
853
+ ,overflow: 'hidden'
854
+ }, true);
855
+
856
+ layero.find('.layui-layer-min').hide();
857
+ layero.attr('type') === 'page' && layero.find(doms[4]).hide();
858
+ ready.rescollbar(index);
859
+
860
+ if(!layero.attr('minLeft')){
861
+ ready.minIndex++;
862
+ }
863
+ layero.attr('minLeft', left);
864
+ };
865
+
866
+ //还原
867
+ layer.restore = function(index){
868
+ var layero = $('#'+ doms[0] + index), area = layero.attr('area').split(',');
869
+ var type = layero.attr('type');
870
+ layer.style(index, {
871
+ width: parseFloat(area[0]),
872
+ height: parseFloat(area[1]),
873
+ top: parseFloat(area[2]),
874
+ left: parseFloat(area[3]),
875
+ position: layero.attr('position'),
876
+ overflow: 'visible'
877
+ }, true);
878
+ layero.find('.layui-layer-max').removeClass('layui-layer-maxmin');
879
+ layero.find('.layui-layer-min').show();
880
+ layero.attr('type') === 'page' && layero.find(doms[4]).show();
881
+ ready.rescollbar(index);
882
+ };
883
+
884
+ //全屏
885
+ layer.full = function(index){
886
+ var layero = $('#'+ doms[0] + index), timer;
887
+ ready.record(layero);
888
+ if(!doms.html.attr('layer-full')){
889
+ doms.html.css('overflow','hidden').attr('layer-full', index);
890
+ }
891
+ clearTimeout(timer);
892
+ timer = setTimeout(function(){
893
+ var isfix = layero.css('position') === 'fixed';
894
+ layer.style(index, {
895
+ top: isfix ? 0 : win.scrollTop(),
896
+ left: isfix ? 0 : win.scrollLeft(),
897
+ width: win.width(),
898
+ height: win.height()
899
+ }, true);
900
+ layero.find('.layui-layer-min').hide();
901
+ }, 100);
902
+ };
903
+
904
+ //改变title
905
+ layer.title = function(name, index){
906
+ var title = $('#'+ doms[0] + (index||layer.index)).find(doms[1]);
907
+ title.html(name);
908
+ };
909
+
910
+ //关闭layer总方法
911
+ layer.close = function(index){
912
+ var layero = $('#'+ doms[0] + index), type = layero.attr('type'), closeAnim = 'layer-anim-close';
913
+ if(!layero[0]) return;
914
+ var WRAP = 'layui-layer-wrap', remove = function(){
915
+ if(type === ready.type[1] && layero.attr('conType') === 'object'){
916
+ layero.children(':not(.'+ doms[5] +')').remove();
917
+ var wrap = layero.find('.'+WRAP);
918
+ for(var i = 0; i < 2; i++){
919
+ wrap.unwrap();
920
+ }
921
+ wrap.css('display', wrap.data('display')).removeClass(WRAP);
922
+ } else {
923
+ //低版本IE 回收 iframe
924
+ if(type === ready.type[2]){
925
+ try {
926
+ var iframe = $('#'+doms[4]+index)[0];
927
+ iframe.contentWindow.document.write('');
928
+ iframe.contentWindow.close();
929
+ layero.find('.'+doms[5])[0].removeChild(iframe);
930
+ } catch(e){}
931
+ }
932
+ layero[0].innerHTML = '';
933
+ layero.remove();
934
+ }
935
+ typeof ready.end[index] === 'function' && ready.end[index]();
936
+ delete ready.end[index];
937
+ };
938
+
939
+ if(layero.data('isOutAnim')){
940
+ layero.addClass('layer-anim '+ closeAnim);
941
+ }
942
+
943
+ $('#layui-layer-moves, #layui-layer-shade' + index).remove();
944
+ layer.ie == 6 && ready.reselect();
945
+ ready.rescollbar(index);
946
+ if(layero.attr('minLeft')){
947
+ ready.minIndex--;
948
+ ready.minLeft.push(layero.attr('minLeft'));
949
+ }
950
+
951
+ if((layer.ie && layer.ie < 10) || !layero.data('isOutAnim')){
952
+ remove()
953
+ } else {
954
+ setTimeout(function(){
955
+ remove();
956
+ }, 200);
957
+ }
958
+ };
959
+
960
+ //关闭所有层
961
+ layer.closeAll = function(type){
962
+ $.each($('.'+doms[0]), function(){
963
+ var othis = $(this);
964
+ var is = type ? (othis.attr('type') === type) : 1;
965
+ is && layer.close(othis.attr('times'));
966
+ is = null;
967
+ });
968
+ };
969
+
970
+ /**
971
+
972
+ 拓展模块,layui开始合并在一起
973
+
974
+ */
975
+
976
+ var cache = layer.cache||{}, skin = function(type){
977
+ return (cache.skin ? (' ' + cache.skin + ' ' + cache.skin + '-'+type) : '');
978
+ };
979
+
980
+ //仿系统prompt
981
+ layer.prompt = function(options, yes){
982
+ var style = '';
983
+ options = options || {};
984
+
985
+ if(typeof options === 'function') yes = options;
986
+
987
+ if(options.area){
988
+ var area = options.area;
989
+ style = 'style="width: '+ area[0] +'; height: '+ area[1] + ';"';
990
+ delete options.area;
991
+ }
992
+ var prompt, content = options.formType == 2 ? '<textarea class="layui-layer-input"' + style +'>' + (options.value||'') +'</textarea>' : function(){
993
+ return '<input type="'+ (options.formType == 1 ? 'password' : 'text') +'" class="layui-layer-input" value="'+ (options.value||'') +'">';
994
+ }();
995
+
996
+ var success = options.success;
997
+ delete options.success;
998
+
999
+ return layer.open($.extend({
1000
+ type: 1
1001
+ ,btn: ['&#x786E;&#x5B9A;','&#x53D6;&#x6D88;']
1002
+ ,content: content
1003
+ ,skin: 'layui-layer-prompt' + skin('prompt')
1004
+ ,maxWidth: win.width()
1005
+ ,success: function(layero){
1006
+ prompt = layero.find('.layui-layer-input');
1007
+ prompt.focus();
1008
+ typeof success === 'function' && success(layero);
1009
+ }
1010
+ ,resize: false
1011
+ ,yes: function(index){
1012
+ var value = prompt.val();
1013
+ if(value === ''){
1014
+ prompt.focus();
1015
+ } else if(value.length > (options.maxlength||500)) {
1016
+ layer.tips('&#x6700;&#x591A;&#x8F93;&#x5165;'+ (options.maxlength || 500) +'&#x4E2A;&#x5B57;&#x6570;', prompt, {tips: 1});
1017
+ } else {
1018
+ yes && yes(value, index, prompt);
1019
+ }
1020
+ }
1021
+ }, options));
1022
+ };
1023
+
1024
+ //tab层
1025
+ layer.tab = function(options){
1026
+ options = options || {};
1027
+
1028
+ var tab = options.tab || {}
1029
+ ,THIS = 'layui-this'
1030
+ ,success = options.success;
1031
+
1032
+ delete options.success;
1033
+
1034
+ return layer.open($.extend({
1035
+ type: 1,
1036
+ skin: 'layui-layer-tab' + skin('tab'),
1037
+ resize: false,
1038
+ title: function(){
1039
+ var len = tab.length, ii = 1, str = '';
1040
+ if(len > 0){
1041
+ str = '<span class="'+ THIS +'">'+ tab[0].title +'</span>';
1042
+ for(; ii < len; ii++){
1043
+ str += '<span>'+ tab[ii].title +'</span>';
1044
+ }
1045
+ }
1046
+ return str;
1047
+ }(),
1048
+ content: '<ul class="layui-layer-tabmain">'+ function(){
1049
+ var len = tab.length, ii = 1, str = '';
1050
+ if(len > 0){
1051
+ str = '<li class="layui-layer-tabli '+ THIS +'">'+ (tab[0].content || 'no content') +'</li>';
1052
+ for(; ii < len; ii++){
1053
+ str += '<li class="layui-layer-tabli">'+ (tab[ii].content || 'no content') +'</li>';
1054
+ }
1055
+ }
1056
+ return str;
1057
+ }() +'</ul>',
1058
+ success: function(layero){
1059
+ var btn = layero.find('.layui-layer-title').children();
1060
+ var main = layero.find('.layui-layer-tabmain').children();
1061
+ btn.on('mousedown', function(e){
1062
+ e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
1063
+ var othis = $(this), index = othis.index();
1064
+ othis.addClass(THIS).siblings().removeClass(THIS);
1065
+ main.eq(index).show().siblings().hide();
1066
+ typeof options.change === 'function' && options.change(index);
1067
+ });
1068
+ typeof success === 'function' && success(layero);
1069
+ }
1070
+ }, options));
1071
+ };
1072
+
1073
+ //相册层
1074
+ layer.photos = function(options, loop, key){
1075
+ var dict = {};
1076
+ options = options || {};
1077
+ if(!options.photos) return;
1078
+ var type = options.photos.constructor === Object;
1079
+ var photos = type ? options.photos : {}, data = photos.data || [];
1080
+ var start = photos.start || 0;
1081
+ dict.imgIndex = (start|0) + 1;
1082
+
1083
+ options.img = options.img || 'img';
1084
+
1085
+ var success = options.success;
1086
+ delete options.success;
1087
+
1088
+ if(!type){ //页面直接获取
1089
+ var parent = $(options.photos), pushData = function(){
1090
+ data = [];
1091
+ parent.find(options.img).each(function(index){
1092
+ var othis = $(this);
1093
+ othis.attr('layer-index', index);
1094
+ data.push({
1095
+ alt: othis.attr('alt'),
1096
+ pid: othis.attr('layer-pid'),
1097
+ src: othis.attr('layer-src') || othis.attr('src'),
1098
+ thumb: othis.attr('src')
1099
+ });
1100
+ })
1101
+ };
1102
+
1103
+ pushData();
1104
+
1105
+ if (data.length === 0) return;
1106
+
1107
+ loop || parent.on('click', options.img, function(){
1108
+ var othis = $(this), index = othis.attr('layer-index');
1109
+ layer.photos($.extend(options, {
1110
+ photos: {
1111
+ start: index,
1112
+ data: data,
1113
+ tab: options.tab
1114
+ },
1115
+ full: options.full
1116
+ }), true);
1117
+ pushData();
1118
+ })
1119
+
1120
+ //不直接弹出
1121
+ if(!loop) return;
1122
+
1123
+ } else if (data.length === 0){
1124
+ return layer.msg('&#x6CA1;&#x6709;&#x56FE;&#x7247;');
1125
+ }
1126
+
1127
+ //上一张
1128
+ dict.imgprev = function(key){
1129
+ dict.imgIndex--;
1130
+ if(dict.imgIndex < 1){
1131
+ dict.imgIndex = data.length;
1132
+ }
1133
+ dict.tabimg(key);
1134
+ };
1135
+
1136
+ //下一张
1137
+ dict.imgnext = function(key,errorMsg){
1138
+ dict.imgIndex++;
1139
+ if(dict.imgIndex > data.length){
1140
+ dict.imgIndex = 1;
1141
+ if (errorMsg) {return};
1142
+ }
1143
+ dict.tabimg(key)
1144
+ };
1145
+
1146
+ //方向键
1147
+ dict.keyup = function(event){
1148
+ if(!dict.end){
1149
+ var code = event.keyCode;
1150
+ event.preventDefault();
1151
+ if(code === 37){
1152
+ dict.imgprev(true);
1153
+ } else if(code === 39) {
1154
+ dict.imgnext(true);
1155
+ } else if(code === 27) {
1156
+ layer.close(dict.index);
1157
+ }
1158
+ }
1159
+ }
1160
+
1161
+ //切换
1162
+ dict.tabimg = function(key){
1163
+ if(data.length <= 1) return;
1164
+ photos.start = dict.imgIndex - 1;
1165
+ layer.close(dict.index);
1166
+ return layer.photos(options, true, key);
1167
+ setTimeout(function(){
1168
+ layer.photos(options, true, key);
1169
+ }, 200);
1170
+ }
1171
+
1172
+ //一些动作
1173
+ dict.event = function(){
1174
+ dict.bigimg.hover(function(){
1175
+ dict.imgsee.show();
1176
+ }, function(){
1177
+ dict.imgsee.hide();
1178
+ });
1179
+
1180
+ dict.bigimg.find('.layui-layer-imgprev').on('click', function(event){
1181
+ event.preventDefault();
1182
+ dict.imgprev();
1183
+ });
1184
+
1185
+ dict.bigimg.find('.layui-layer-imgnext').on('click', function(event){
1186
+ event.preventDefault();
1187
+ dict.imgnext();
1188
+ });
1189
+
1190
+ $(document).on('keyup', dict.keyup);
1191
+ };
1192
+
1193
+ //图片预加载
1194
+ function loadImage(url, callback, error) {
1195
+ var img = new Image();
1196
+ img.src = url;
1197
+ if(img.complete){
1198
+ return callback(img);
1199
+ }
1200
+ img.onload = function(){
1201
+ img.onload = null;
1202
+ callback(img);
1203
+ };
1204
+ img.onerror = function(e){
1205
+ img.onerror = null;
1206
+ error(e);
1207
+ };
1208
+ };
1209
+
1210
+ dict.loadi = layer.load(1, {
1211
+ shade: 'shade' in options ? false : 0.9,
1212
+ scrollbar: false
1213
+ });
1214
+
1215
+ loadImage(data[start].src, function(img){
1216
+ layer.close(dict.loadi);
1217
+ dict.index = layer.open($.extend({
1218
+ type: 1,
1219
+ id: 'layui-layer-photos',
1220
+ area: function(){
1221
+ var imgarea = [img.width, img.height];
1222
+ var winarea = [$(window).width() - 100, $(window).height() - 100];
1223
+
1224
+ //如果 实际图片的宽或者高比 屏幕大(那么进行缩放)
1225
+ if(!options.full && (imgarea[0]>winarea[0]||imgarea[1]>winarea[1])){
1226
+ var wh = [imgarea[0]/winarea[0],imgarea[1]/winarea[1]];//取宽度缩放比例、高度缩放比例
1227
+ if(wh[0] > wh[1]){//取缩放比例最大的进行缩放
1228
+ imgarea[0] = imgarea[0]/wh[0];
1229
+ imgarea[1] = imgarea[1]/wh[0];
1230
+ } else if(wh[0] < wh[1]){
1231
+ imgarea[0] = imgarea[0]/wh[1];
1232
+ imgarea[1] = imgarea[1]/wh[1];
1233
+ }
1234
+ }
1235
+
1236
+ return [imgarea[0]+'px', imgarea[1]+'px'];
1237
+ }(),
1238
+ title: false,
1239
+ shade: 0.9,
1240
+ shadeClose: true,
1241
+ closeBtn: false,
1242
+ move: '.layui-layer-phimg img',
1243
+ moveType: 1,
1244
+ scrollbar: false,
1245
+ moveOut: true,
1246
+ //anim: Math.random()*5|0,
1247
+ isOutAnim: false,
1248
+ skin: 'layui-layer-photos' + skin('photos'),
1249
+ content: '<div class="layui-layer-phimg">'
1250
+ +'<img src="'+ data[start].src +'" alt="'+ (data[start].alt||'') +'" layer-pid="'+ data[start].pid +'">'
1251
+ +'<div class="layui-layer-imgsee">'
1252
+ +(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>' : '')
1253
+ +'<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>'
1254
+ +'</div>'
1255
+ +'</div>',
1256
+ success: function(layero, index){
1257
+ dict.bigimg = layero.find('.layui-layer-phimg');
1258
+ dict.imgsee = layero.find('.layui-layer-imguide,.layui-layer-imgbar');
1259
+ dict.event(layero);
1260
+ options.tab && options.tab(data[start], layero);
1261
+ typeof success === 'function' && success(layero);
1262
+ }, end: function(){
1263
+ dict.end = true;
1264
+ $(document).off('keyup', dict.keyup);
1265
+ }
1266
+ }, options));
1267
+ }, function(){
1268
+ layer.close(dict.loadi);
1269
+ layer.msg('&#x5F53;&#x524D;&#x56FE;&#x7247;&#x5730;&#x5740;&#x5F02;&#x5E38;<br>&#x662F;&#x5426;&#x7EE7;&#x7EED;&#x67E5;&#x770B;&#x4E0B;&#x4E00;&#x5F20;&#xFF1F;', {
1270
+ time: 30000,
1271
+ btn: ['&#x4E0B;&#x4E00;&#x5F20;', '&#x4E0D;&#x770B;&#x4E86;'],
1272
+ yes: function(){
1273
+ data.length > 1 && dict.imgnext(true,true);
1274
+ }
1275
+ });
1276
+ });
1277
+ };
1278
+
1279
+ //主入口
1280
+ ready.run = function(_$){
1281
+ $ = _$;
1282
+ win = $(window);
1283
+ doms.html = $('html');
1284
+ layer.open = function(deliver){
1285
+ var o = new Class(deliver);
1286
+ return o.index;
1287
+ };
1288
+ };
1289
+
1290
+ //加载方式
1291
+ window.layui && layui.define ? (
1292
+ layer.ready()
1293
+ ,layui.define('jquery', function(exports){ //layui加载
1294
+ layer.path = layui.cache.dir;
1295
+ ready.run(layui.$);
1296
+
1297
+ //暴露模块
1298
+ window.layer = layer;
1299
+ exports('layer', layer);
1300
+ })
1301
+ ) : (
1302
+ (typeof define === 'function' && define.amd) ? define(['jquery'], function(){ //requirejs加载
1303
+ ready.run(window.jQuery);
1304
+ return layer;
1305
+ }) : function(){ //普通script标签加载
1306
+ ready.run(window.jQuery);
1307
+ layer.ready();
1308
+ }()
1309
+ );
1310
+
1311
+ }(window);