artdialog4 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/artdialog4.gemspec +28 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/artdialog4/version.rb +3 -0
- data/lib/artdialog4.rb +6 -0
- data/vendor/assets/javascripts/artdialog.js +2078 -0
- data/vendor/assets/javascripts/jquery.artDialog.js +1261 -0
- data/vendor/assets/stylesheets/artdialog/aero/aero_s.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/aero_s2.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_close.hover.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_close.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_e.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_n.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_ne.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_nw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_s.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_se.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_sw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_title_icon.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_w.png +0 -0
- data/vendor/assets/stylesheets/artdialog/aero.css +61 -0
- data/vendor/assets/stylesheets/artdialog/black/bg.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/bg2.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/bg_css3.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/bg_css3_2.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/ie6/close.hover.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/ie6/close.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/ie6/e.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/ie6/n.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/ie6/ne.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/ie6/nw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/ie6/s.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/ie6/se.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/ie6/sw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black/ie6/w.png +0 -0
- data/vendor/assets/stylesheets/artdialog/black.css +79 -0
- data/vendor/assets/stylesheets/artdialog/blue/bg.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/bg2.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/bg_css3.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/bg_css3_2.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/ie6/close.hover.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/ie6/close.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/ie6/e.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/ie6/n.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/ie6/ne.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/ie6/nw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/ie6/s.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/ie6/se.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/ie6/sw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue/ie6/w.png +0 -0
- data/vendor/assets/stylesheets/artdialog/blue.css +79 -0
- data/vendor/assets/stylesheets/artdialog/chrome/border.png +0 -0
- data/vendor/assets/stylesheets/artdialog/chrome/chrome_s.png +0 -0
- data/vendor/assets/stylesheets/artdialog/chrome.css +61 -0
- data/vendor/assets/stylesheets/artdialog/default.css +67 -0
- data/vendor/assets/stylesheets/artdialog/green/bg.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/bg2.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/bg_css3.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/bg_css3_2.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/color_bg.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/ie6/close.hover.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/ie6/close.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/ie6/e.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/ie6/n.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/ie6/ne.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/ie6/nw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/ie6/s.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/ie6/se.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/ie6/sw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green/ie6/w.png +0 -0
- data/vendor/assets/stylesheets/artdialog/green.css +79 -0
- data/vendor/assets/stylesheets/artdialog/icons/error.png +0 -0
- data/vendor/assets/stylesheets/artdialog/icons/face-sad.png +0 -0
- data/vendor/assets/stylesheets/artdialog/icons/face-smile.png +0 -0
- data/vendor/assets/stylesheets/artdialog/icons/loading.gif +0 -0
- data/vendor/assets/stylesheets/artdialog/icons/question.png +0 -0
- data/vendor/assets/stylesheets/artdialog/icons/succeed.png +0 -0
- data/vendor/assets/stylesheets/artdialog/icons/warning.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/idialog_s.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/idialog_s2.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_close.hover.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_close.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_e.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_n.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_ne.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_nw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_s.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_se.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_sw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_w.png +0 -0
- data/vendor/assets/stylesheets/artdialog/idialog.css +71 -0
- data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_close.hover.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_close.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_e.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_n.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_ne.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_nw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_s.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_se.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_sw.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_w.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera/s1.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera/s2.png +0 -0
- data/vendor/assets/stylesheets/artdialog/opera.css +62 -0
- data/vendor/assets/stylesheets/artdialog/simple.css +55 -0
- data/vendor/assets/stylesheets/artdialog/twitter.css +59 -0
- data/vendor/assets/stylesheets/simple.css +55 -0
- metadata +184 -0
@@ -0,0 +1,2078 @@
|
|
1
|
+
/*!
|
2
|
+
* artDialog 4.1.7
|
3
|
+
* Date: 2013-03-03 08:04
|
4
|
+
* http://code.google.com/p/artdialog/
|
5
|
+
* (c) 2009-2012 TangBin, http://www.planeArt.cn
|
6
|
+
*
|
7
|
+
* This is licensed under the GNU LGPL, version 2.1 or later.
|
8
|
+
* For details, see: http://creativecommons.org/licenses/LGPL/2.1/
|
9
|
+
*/
|
10
|
+
|
11
|
+
;(function (window, undefined) {
|
12
|
+
//if (window.jQuery) return jQuery;
|
13
|
+
|
14
|
+
var $ = window.art = function (selector, context) {
|
15
|
+
return new $.fn.init(selector, context);
|
16
|
+
},
|
17
|
+
readyBound = false,
|
18
|
+
readyList = [],
|
19
|
+
DOMContentLoaded,
|
20
|
+
isOpacity = 'opacity' in document.documentElement.style,
|
21
|
+
quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,
|
22
|
+
rclass = /[\n\t]/g,
|
23
|
+
ralpha = /alpha\([^)]*\)/i,
|
24
|
+
ropacity = /opacity=([^)]*)/,
|
25
|
+
rfxnum = /^([+-]=)?([\d+-.]+)(.*)$/;
|
26
|
+
|
27
|
+
if (window.$ === undefined) window.$ = $;
|
28
|
+
$.fn = $.prototype = {
|
29
|
+
constructor: $,
|
30
|
+
|
31
|
+
/**
|
32
|
+
* DOM 就绪
|
33
|
+
* @param {Function} 回调函数
|
34
|
+
*/
|
35
|
+
ready: function (callback) {
|
36
|
+
$.bindReady();
|
37
|
+
|
38
|
+
if ($.isReady) {
|
39
|
+
callback.call(document, $);
|
40
|
+
} else if (readyList) {
|
41
|
+
readyList.push(callback);
|
42
|
+
};
|
43
|
+
|
44
|
+
return this;
|
45
|
+
},
|
46
|
+
|
47
|
+
/**
|
48
|
+
* 判断样式类是否存在
|
49
|
+
* @param {String} 名称
|
50
|
+
* @return {Boolean}
|
51
|
+
*/
|
52
|
+
hasClass: function (name) {
|
53
|
+
var className = ' ' + name + ' ';
|
54
|
+
if ((' ' + this[0].className + ' ').replace(rclass, ' ')
|
55
|
+
.indexOf(className) > -1) return true;
|
56
|
+
|
57
|
+
return false;
|
58
|
+
},
|
59
|
+
|
60
|
+
/**
|
61
|
+
* 添加样式类
|
62
|
+
* @param {String} 名称
|
63
|
+
*/
|
64
|
+
addClass: function (name) {
|
65
|
+
if (!this.hasClass(name)) this[0].className += ' ' + name;
|
66
|
+
|
67
|
+
return this;
|
68
|
+
},
|
69
|
+
|
70
|
+
/**
|
71
|
+
* 移除样式类
|
72
|
+
* @param {String} 名称
|
73
|
+
*/
|
74
|
+
removeClass: function (name) {
|
75
|
+
var elem = this[0];
|
76
|
+
|
77
|
+
if (!name) {
|
78
|
+
elem.className = '';
|
79
|
+
} else
|
80
|
+
if (this.hasClass(name)) {
|
81
|
+
elem.className = elem.className.replace(name, ' ');
|
82
|
+
};
|
83
|
+
|
84
|
+
return this;
|
85
|
+
},
|
86
|
+
|
87
|
+
/**
|
88
|
+
* 读写样式<br />
|
89
|
+
* css(name) 访问第一个匹配元素的样式属性<br />
|
90
|
+
* css(properties) 把一个"名/值对"对象设置为所有匹配元素的样式属性<br />
|
91
|
+
* css(name, value) 在所有匹配的元素中,设置一个样式属性的值<br />
|
92
|
+
*/
|
93
|
+
css: function (name, value) {
|
94
|
+
var i, elem = this[0], obj = arguments[0];
|
95
|
+
|
96
|
+
if (typeof name === 'string') {
|
97
|
+
if (value === undefined) {
|
98
|
+
return $.css(elem, name);
|
99
|
+
} else {
|
100
|
+
name === 'opacity' ?
|
101
|
+
$.opacity.set(elem, value) :
|
102
|
+
elem.style[name] = value;
|
103
|
+
};
|
104
|
+
} else {
|
105
|
+
for (i in obj) {
|
106
|
+
i === 'opacity' ?
|
107
|
+
$.opacity.set(elem, obj[i]) :
|
108
|
+
elem.style[i] = obj[i];
|
109
|
+
};
|
110
|
+
};
|
111
|
+
|
112
|
+
return this;
|
113
|
+
},
|
114
|
+
|
115
|
+
/** 显示元素 */
|
116
|
+
show: function () {
|
117
|
+
return this.css('display', 'block');
|
118
|
+
},
|
119
|
+
|
120
|
+
/** 隐藏元素 */
|
121
|
+
hide: function () {
|
122
|
+
return this.css('display', 'none');
|
123
|
+
},
|
124
|
+
|
125
|
+
/**
|
126
|
+
* 获取相对文档的坐标
|
127
|
+
* @return {Object} 返回left、top的数值
|
128
|
+
*/
|
129
|
+
offset: function () {
|
130
|
+
var elem = this[0],
|
131
|
+
box = elem.getBoundingClientRect(),
|
132
|
+
doc = elem.ownerDocument,
|
133
|
+
body = doc.body,
|
134
|
+
docElem = doc.documentElement,
|
135
|
+
clientTop = docElem.clientTop || body.clientTop || 0,
|
136
|
+
clientLeft = docElem.clientLeft || body.clientLeft || 0,
|
137
|
+
top = box.top + (self.pageYOffset || docElem.scrollTop) - clientTop,
|
138
|
+
left = box.left + (self.pageXOffset || docElem.scrollLeft) - clientLeft;
|
139
|
+
|
140
|
+
return {
|
141
|
+
left: left,
|
142
|
+
top: top
|
143
|
+
};
|
144
|
+
},
|
145
|
+
|
146
|
+
/**
|
147
|
+
* 读写HTML - (不支持文本框)
|
148
|
+
* @param {String} 内容
|
149
|
+
*/
|
150
|
+
html: function (content) {
|
151
|
+
var elem = this[0];
|
152
|
+
|
153
|
+
if (content === undefined) return elem.innerHTML;
|
154
|
+
$.cleanData(elem.getElementsByTagName('*'));
|
155
|
+
elem.innerHTML = content;
|
156
|
+
|
157
|
+
return this;
|
158
|
+
},
|
159
|
+
|
160
|
+
/**
|
161
|
+
* 移除节点
|
162
|
+
*/
|
163
|
+
remove: function () {
|
164
|
+
var elem = this[0];
|
165
|
+
|
166
|
+
$.cleanData(elem.getElementsByTagName('*'));
|
167
|
+
$.cleanData([elem]);
|
168
|
+
elem.parentNode.removeChild(elem);
|
169
|
+
|
170
|
+
return this;
|
171
|
+
},
|
172
|
+
|
173
|
+
/**
|
174
|
+
* 事件绑定
|
175
|
+
* @param {String} 类型
|
176
|
+
* @param {Function} 要绑定的函数
|
177
|
+
*/
|
178
|
+
bind: function (type, callback) {
|
179
|
+
$.event.add(this[0], type, callback);
|
180
|
+
return this;
|
181
|
+
},
|
182
|
+
|
183
|
+
/**
|
184
|
+
* 移除事件
|
185
|
+
* @param {String} 类型
|
186
|
+
* @param {Function} 要卸载的函数
|
187
|
+
*/
|
188
|
+
unbind: function(type, callback) {
|
189
|
+
$.event.remove(this[0], type, callback);
|
190
|
+
return this;
|
191
|
+
}
|
192
|
+
|
193
|
+
};
|
194
|
+
|
195
|
+
$.fn.init = function (selector, context) {
|
196
|
+
var match, elem;
|
197
|
+
context = context || document;
|
198
|
+
|
199
|
+
if (!selector) return this;
|
200
|
+
|
201
|
+
if (selector.nodeType) {
|
202
|
+
this[0] = selector;
|
203
|
+
return this;
|
204
|
+
};
|
205
|
+
|
206
|
+
if (selector === 'body' && context.body) {
|
207
|
+
this[0] = context.body;
|
208
|
+
return this;
|
209
|
+
};
|
210
|
+
|
211
|
+
if (selector === 'head' || selector === 'html') {
|
212
|
+
this[0] = context.getElementsByTagName(selector)[0];
|
213
|
+
return this;
|
214
|
+
};
|
215
|
+
|
216
|
+
if (typeof selector === 'string') {
|
217
|
+
match = quickExpr.exec(selector);
|
218
|
+
|
219
|
+
if (match && match[2]) {
|
220
|
+
elem = context.getElementById(match[2]);
|
221
|
+
if (elem && elem.parentNode) this[0] = elem;
|
222
|
+
return this;
|
223
|
+
};
|
224
|
+
};
|
225
|
+
|
226
|
+
if (typeof selector === 'function') return $(document).ready(selector);
|
227
|
+
|
228
|
+
this[0] = selector;
|
229
|
+
|
230
|
+
return this;
|
231
|
+
};
|
232
|
+
$.fn.init.prototype = $.fn;
|
233
|
+
|
234
|
+
/** 空函数 */
|
235
|
+
$.noop = function () {};
|
236
|
+
|
237
|
+
/** 检测window */
|
238
|
+
$.isWindow = function (obj) {
|
239
|
+
return obj && typeof obj === 'object' && 'setInterval' in obj;
|
240
|
+
};
|
241
|
+
|
242
|
+
/** 数组判定 */
|
243
|
+
$.isArray = function (obj) {
|
244
|
+
return Object.prototype.toString.call(obj) === '[object Array]';
|
245
|
+
};
|
246
|
+
|
247
|
+
/**
|
248
|
+
* 搜索子元素
|
249
|
+
* 注意:只支持nodeName或.className的形式,并且只返回第一个元素
|
250
|
+
* @param {String}
|
251
|
+
*/
|
252
|
+
$.fn.find = function (expr) {
|
253
|
+
var value, elem = this[0],
|
254
|
+
className = expr.split('.')[1];
|
255
|
+
|
256
|
+
if (className) {
|
257
|
+
if (document.getElementsByClassName) {
|
258
|
+
value = elem.getElementsByClassName(className);
|
259
|
+
} else {
|
260
|
+
value = getElementsByClassName(className, elem);
|
261
|
+
};
|
262
|
+
} else {
|
263
|
+
value = elem.getElementsByTagName(expr);
|
264
|
+
};
|
265
|
+
|
266
|
+
return $(value[0]);
|
267
|
+
};
|
268
|
+
function getElementsByClassName (className, node, tag) {
|
269
|
+
node = node || document;
|
270
|
+
tag = tag || '*';
|
271
|
+
var i = 0,
|
272
|
+
j = 0,
|
273
|
+
classElements = [],
|
274
|
+
els = node.getElementsByTagName(tag),
|
275
|
+
elsLen = els.length,
|
276
|
+
pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
|
277
|
+
|
278
|
+
for (; i < elsLen; i ++) {
|
279
|
+
if (pattern.test(els[i].className)) {
|
280
|
+
classElements[j] = els[i];
|
281
|
+
j ++;
|
282
|
+
};
|
283
|
+
};
|
284
|
+
return classElements;
|
285
|
+
};
|
286
|
+
|
287
|
+
/**
|
288
|
+
* 遍历
|
289
|
+
* @param {Object}
|
290
|
+
* @param {Function}
|
291
|
+
*/
|
292
|
+
$.each = function (obj, callback) {
|
293
|
+
var name, i = 0,
|
294
|
+
length = obj.length,
|
295
|
+
isObj = length === undefined;
|
296
|
+
|
297
|
+
if (isObj) {
|
298
|
+
for (name in obj) {
|
299
|
+
if (callback.call(obj[name], name, obj[name]) === false) break;
|
300
|
+
};
|
301
|
+
} else {
|
302
|
+
for (var value = obj[0];
|
303
|
+
i < length && callback.call(value, i, value) !== false;
|
304
|
+
value = obj[++i]) {};
|
305
|
+
};
|
306
|
+
|
307
|
+
return obj;
|
308
|
+
};
|
309
|
+
|
310
|
+
/**
|
311
|
+
* 读写缓存
|
312
|
+
* @param {HTMLElement} 元素
|
313
|
+
* @param {String} 缓存名称
|
314
|
+
* @param {Any} 数据
|
315
|
+
* @return {Any} 如果无参数data则返回缓存数据
|
316
|
+
*/
|
317
|
+
$.data = function (elem, name, data) {
|
318
|
+
var cache = $.cache,
|
319
|
+
id = uuid(elem);
|
320
|
+
|
321
|
+
if (name === undefined) return cache[id];
|
322
|
+
if (!cache[id]) cache[id] = {};
|
323
|
+
if (data !== undefined) cache[id][name] = data;
|
324
|
+
|
325
|
+
return cache[id][name];
|
326
|
+
};
|
327
|
+
|
328
|
+
/**
|
329
|
+
* 删除缓存
|
330
|
+
* @param {HTMLElement} 元素
|
331
|
+
* @param {String} 缓存名称
|
332
|
+
*/
|
333
|
+
$.removeData = function (elem, name) {
|
334
|
+
var empty = true,
|
335
|
+
expando = $.expando,
|
336
|
+
cache = $.cache,
|
337
|
+
id = uuid(elem),
|
338
|
+
thisCache = id && cache[id];
|
339
|
+
|
340
|
+
if (!thisCache) return;
|
341
|
+
if (name) {
|
342
|
+
delete thisCache[name];
|
343
|
+
for (var n in thisCache) empty = false;
|
344
|
+
if (empty) delete $.cache[id];
|
345
|
+
} else {
|
346
|
+
delete cache[id];
|
347
|
+
if (elem.removeAttribute) {
|
348
|
+
elem.removeAttribute(expando);
|
349
|
+
} else {
|
350
|
+
elem[expando] = null;
|
351
|
+
};
|
352
|
+
};
|
353
|
+
};
|
354
|
+
|
355
|
+
$.uuid = 0;
|
356
|
+
$.cache = {};
|
357
|
+
$.expando = '@cache' + + new Date
|
358
|
+
|
359
|
+
// 标记元素唯一身份
|
360
|
+
function uuid (elem) {
|
361
|
+
var expando = $.expando,
|
362
|
+
id = elem === window ? 0 : elem[expando];
|
363
|
+
if (id === undefined) elem[expando] = id = ++ $.uuid;
|
364
|
+
return id;
|
365
|
+
};
|
366
|
+
|
367
|
+
|
368
|
+
/**
|
369
|
+
* 事件机制
|
370
|
+
* @namespace
|
371
|
+
* @requires [$.data, $.removeData]
|
372
|
+
*/
|
373
|
+
$.event = {
|
374
|
+
|
375
|
+
/**
|
376
|
+
* 添加事件
|
377
|
+
* @param {HTMLElement} 元素
|
378
|
+
* @param {String} 事件类型
|
379
|
+
* @param {Function} 要添加的函数
|
380
|
+
*/
|
381
|
+
add: function (elem, type, callback) {
|
382
|
+
var cache, listeners,
|
383
|
+
that = $.event,
|
384
|
+
data = $.data(elem, '@events') || $.data(elem, '@events', {});
|
385
|
+
|
386
|
+
cache = data[type] = data[type] || {};
|
387
|
+
listeners = cache.listeners = cache.listeners || [];
|
388
|
+
listeners.push(callback);
|
389
|
+
|
390
|
+
if (!cache.handler) {
|
391
|
+
cache.elem = elem;
|
392
|
+
cache.handler = that.handler(cache);
|
393
|
+
|
394
|
+
elem.addEventListener
|
395
|
+
? elem.addEventListener(type, cache.handler, false)
|
396
|
+
: elem.attachEvent('on' + type, cache.handler);
|
397
|
+
};
|
398
|
+
},
|
399
|
+
|
400
|
+
/**
|
401
|
+
* 卸载事件
|
402
|
+
* @param {HTMLElement} 元素
|
403
|
+
* @param {String} 事件类型
|
404
|
+
* @param {Function} 要卸载的函数
|
405
|
+
*/
|
406
|
+
remove: function (elem, type, callback) {
|
407
|
+
var i, cache, listeners,
|
408
|
+
that = $.event,
|
409
|
+
empty = true,
|
410
|
+
data = $.data(elem, '@events');
|
411
|
+
|
412
|
+
if (!data) return;
|
413
|
+
if (!type) {
|
414
|
+
for (i in data) that.remove(elem, i);
|
415
|
+
return;
|
416
|
+
};
|
417
|
+
|
418
|
+
cache = data[type];
|
419
|
+
if (!cache) return;
|
420
|
+
|
421
|
+
listeners = cache.listeners;
|
422
|
+
if (callback) {
|
423
|
+
for (i = 0; i < listeners.length; i ++) {
|
424
|
+
listeners[i] === callback && listeners.splice(i--, 1);
|
425
|
+
};
|
426
|
+
} else {
|
427
|
+
cache.listeners = [];
|
428
|
+
};
|
429
|
+
|
430
|
+
if (cache.listeners.length === 0) {
|
431
|
+
elem.removeEventListener
|
432
|
+
? elem.removeEventListener(type, cache.handler, false)
|
433
|
+
: elem.detachEvent('on' + type, cache.handler);
|
434
|
+
|
435
|
+
delete data[type];
|
436
|
+
cache = $.data(elem, '@events');
|
437
|
+
for (var n in cache) empty = false;
|
438
|
+
if (empty) $.removeData(elem, '@events');
|
439
|
+
};
|
440
|
+
},
|
441
|
+
|
442
|
+
/** @inner 事件句柄 */
|
443
|
+
handler: function (cache) {
|
444
|
+
return function (event) {
|
445
|
+
event = $.event.fix(event || window.event);
|
446
|
+
for (var i = 0, list = cache.listeners, fn; fn = list[i++];) {
|
447
|
+
if (fn.call(cache.elem, event) === false) {
|
448
|
+
event.preventDefault();
|
449
|
+
event.stopPropagation();
|
450
|
+
};
|
451
|
+
};
|
452
|
+
};
|
453
|
+
},
|
454
|
+
|
455
|
+
/** @inner Event对象兼容处理 */
|
456
|
+
fix: function (event) {
|
457
|
+
if (event.target) return event;
|
458
|
+
|
459
|
+
var event2 = {
|
460
|
+
target: event.srcElement || document,
|
461
|
+
preventDefault: function () {event.returnValue = false},
|
462
|
+
stopPropagation: function () {event.cancelBubble = true}
|
463
|
+
};
|
464
|
+
// IE6/7/8 在原生window.event对象写入数据会导致内存无法回收,应当采用拷贝
|
465
|
+
for (var i in event) event2[i] = event[i];
|
466
|
+
return event2;
|
467
|
+
}
|
468
|
+
|
469
|
+
};
|
470
|
+
|
471
|
+
/**
|
472
|
+
* 清理元素集的事件与缓存
|
473
|
+
* @requires [$.removeData, $.event]
|
474
|
+
* @param {HTMLCollection} 元素集
|
475
|
+
*/
|
476
|
+
$.cleanData = function (elems) {
|
477
|
+
var i = 0, elem,
|
478
|
+
len = elems.length,
|
479
|
+
removeEvent = $.event.remove,
|
480
|
+
removeData = $.removeData;
|
481
|
+
|
482
|
+
for (; i < len; i ++) {
|
483
|
+
elem = elems[i];
|
484
|
+
removeEvent(elem);
|
485
|
+
removeData(elem);
|
486
|
+
};
|
487
|
+
};
|
488
|
+
|
489
|
+
// DOM就绪事件
|
490
|
+
$.isReady = false;
|
491
|
+
$.ready = function () {
|
492
|
+
if (!$.isReady) {
|
493
|
+
if (!document.body) return setTimeout($.ready, 13);
|
494
|
+
$.isReady = true;
|
495
|
+
|
496
|
+
if (readyList) {
|
497
|
+
var fn, i = 0;
|
498
|
+
while ((fn = readyList[i++])) {
|
499
|
+
fn.call(document, $);
|
500
|
+
};
|
501
|
+
readyList = null;
|
502
|
+
};
|
503
|
+
};
|
504
|
+
};
|
505
|
+
$.bindReady = function () {
|
506
|
+
if (readyBound) return;
|
507
|
+
|
508
|
+
readyBound = true;
|
509
|
+
|
510
|
+
if (document.readyState === 'complete') {
|
511
|
+
return $.ready();
|
512
|
+
};
|
513
|
+
|
514
|
+
if (document.addEventListener) {
|
515
|
+
document.addEventListener('DOMContentLoaded', DOMContentLoaded, false);
|
516
|
+
window.addEventListener('load', $.ready, false);
|
517
|
+
} else if (document.attachEvent) {
|
518
|
+
document.attachEvent('onreadystatechange', DOMContentLoaded);
|
519
|
+
window.attachEvent('onload', $.ready);
|
520
|
+
var toplevel = false;
|
521
|
+
try {
|
522
|
+
toplevel = window.frameElement == null;
|
523
|
+
} catch (e) {};
|
524
|
+
|
525
|
+
if (document.documentElement.doScroll && toplevel) {
|
526
|
+
doScrollCheck();
|
527
|
+
};
|
528
|
+
};
|
529
|
+
};
|
530
|
+
|
531
|
+
if (document.addEventListener) {
|
532
|
+
DOMContentLoaded = function () {
|
533
|
+
document.removeEventListener('DOMContentLoaded', DOMContentLoaded, false);
|
534
|
+
$.ready();
|
535
|
+
};
|
536
|
+
} else if (document.attachEvent) {
|
537
|
+
DOMContentLoaded = function () {
|
538
|
+
if (document.readyState === 'complete') {
|
539
|
+
document.detachEvent('onreadystatechange', DOMContentLoaded);
|
540
|
+
$.ready();
|
541
|
+
};
|
542
|
+
};
|
543
|
+
};
|
544
|
+
|
545
|
+
function doScrollCheck () {
|
546
|
+
if ($.isReady) return;
|
547
|
+
|
548
|
+
try {
|
549
|
+
document.documentElement.doScroll('left');
|
550
|
+
} catch (e) {
|
551
|
+
setTimeout(doScrollCheck, 1);
|
552
|
+
return;
|
553
|
+
};
|
554
|
+
$.ready();
|
555
|
+
};
|
556
|
+
|
557
|
+
// 获取css
|
558
|
+
$.css = 'defaultView' in document && 'getComputedStyle' in document.defaultView ?
|
559
|
+
function (elem, name) {
|
560
|
+
return document.defaultView.getComputedStyle(elem, false)[name];
|
561
|
+
} :
|
562
|
+
function (elem, name) {
|
563
|
+
var ret = name === 'opacity' ? $.opacity.get(elem) : elem.currentStyle[name];
|
564
|
+
return ret || '';
|
565
|
+
};
|
566
|
+
|
567
|
+
// 跨浏览器处理opacity
|
568
|
+
$.opacity = {
|
569
|
+
get: function (elem) {
|
570
|
+
return isOpacity ?
|
571
|
+
document.defaultView.getComputedStyle(elem, false).opacity :
|
572
|
+
ropacity.test((elem.currentStyle
|
573
|
+
? elem.currentStyle.filter
|
574
|
+
: elem.style.filter) || '')
|
575
|
+
? (parseFloat(RegExp.$1) / 100) + ''
|
576
|
+
: 1;
|
577
|
+
},
|
578
|
+
set: function (elem, value) {
|
579
|
+
if (isOpacity) return elem.style.opacity = value;
|
580
|
+
var style = elem.style;
|
581
|
+
style.zoom = 1;
|
582
|
+
|
583
|
+
var opacity = 'alpha(opacity=' + value * 100 + ')',
|
584
|
+
filter = style.filter || '';
|
585
|
+
|
586
|
+
style.filter = ralpha.test(filter) ?
|
587
|
+
filter.replace(ralpha, opacity) :
|
588
|
+
style.filter + ' ' + opacity;
|
589
|
+
}
|
590
|
+
};
|
591
|
+
|
592
|
+
/**
|
593
|
+
* 获取滚动条位置 - [不支持写入]
|
594
|
+
* $.fn.scrollLeft, $.fn.scrollTop
|
595
|
+
* @example 获取文档垂直滚动条:$(document).scrollTop()
|
596
|
+
* @return {Number} 返回滚动条位置
|
597
|
+
*/
|
598
|
+
$.each(['Left', 'Top'], function (i, name) {
|
599
|
+
var method = 'scroll' + name;
|
600
|
+
|
601
|
+
$.fn[method] = function () {
|
602
|
+
var elem = this[0], win;
|
603
|
+
|
604
|
+
win = getWindow(elem);
|
605
|
+
return win ?
|
606
|
+
('pageXOffset' in win) ?
|
607
|
+
win[i ? 'pageYOffset' : 'pageXOffset'] :
|
608
|
+
win.document.documentElement[method] || win.document.body[method] :
|
609
|
+
elem[method];
|
610
|
+
};
|
611
|
+
});
|
612
|
+
|
613
|
+
function getWindow (elem) {
|
614
|
+
return $.isWindow(elem) ?
|
615
|
+
elem :
|
616
|
+
elem.nodeType === 9 ?
|
617
|
+
elem.defaultView || elem.parentWindow :
|
618
|
+
false;
|
619
|
+
};
|
620
|
+
|
621
|
+
/**
|
622
|
+
* 获取窗口或文档尺寸 - [只支持window与document读取]
|
623
|
+
* @example
|
624
|
+
获取文档宽度:$(document).width()
|
625
|
+
获取可视范围:$(window).width()
|
626
|
+
* @return {Number}
|
627
|
+
*/
|
628
|
+
$.each(['Height', 'Width'], function (i, name) {
|
629
|
+
var type = name.toLowerCase();
|
630
|
+
|
631
|
+
$.fn[type] = function (size) {
|
632
|
+
var elem = this[0];
|
633
|
+
if (!elem) {
|
634
|
+
return size == null ? null : this;
|
635
|
+
};
|
636
|
+
|
637
|
+
return $.isWindow(elem) ?
|
638
|
+
elem.document.documentElement['client' + name] || elem.document.body['client' + name] :
|
639
|
+
(elem.nodeType === 9) ?
|
640
|
+
Math.max(
|
641
|
+
elem.documentElement['client' + name],
|
642
|
+
elem.body['scroll' + name], elem.documentElement['scroll' + name],
|
643
|
+
elem.body['offset' + name], elem.documentElement['offset' + name]
|
644
|
+
) : null;
|
645
|
+
};
|
646
|
+
|
647
|
+
});
|
648
|
+
|
649
|
+
/**
|
650
|
+
* 简单ajax支持
|
651
|
+
* @example
|
652
|
+
* $.ajax({
|
653
|
+
* url: url,
|
654
|
+
* success: callback,
|
655
|
+
* cache: cache
|
656
|
+
* });
|
657
|
+
*/
|
658
|
+
$.ajax = function (config) {
|
659
|
+
var ajax = window.XMLHttpRequest ?
|
660
|
+
new XMLHttpRequest() :
|
661
|
+
new ActiveXObject('Microsoft.XMLHTTP'),
|
662
|
+
url = config.url;
|
663
|
+
|
664
|
+
if (config.cache === false) {
|
665
|
+
var ts = + new Date,
|
666
|
+
ret = url.replace(/([?&])_=[^&]*/, "$1_=" + ts );
|
667
|
+
url = ret + ((ret === url) ? (/\?/.test(url) ? "&" : "?") + "_=" + ts : "");
|
668
|
+
};
|
669
|
+
|
670
|
+
ajax.onreadystatechange = function() {
|
671
|
+
if (ajax.readyState === 4 && ajax.status === 200) {
|
672
|
+
config.success && config.success(ajax.responseText);
|
673
|
+
ajax.onreadystatechange = $.noop;
|
674
|
+
};
|
675
|
+
};
|
676
|
+
ajax.open('GET', url, 1);
|
677
|
+
ajax.send(null);
|
678
|
+
};
|
679
|
+
|
680
|
+
/** 动画引擎 - [不支持链式列队操作] */
|
681
|
+
$.fn.animate = function (prop, speed, easing, callback) {
|
682
|
+
|
683
|
+
speed = speed || 400;
|
684
|
+
if (typeof easing === 'function') callback = easing;
|
685
|
+
easing = easing && $.easing[easing] ? easing : 'swing';
|
686
|
+
|
687
|
+
var elem = this[0], overflow,
|
688
|
+
fx, parts, start, end, unit,
|
689
|
+
opt = {
|
690
|
+
speed: speed,
|
691
|
+
easing: easing,
|
692
|
+
callback: function () {
|
693
|
+
if (overflow != null) elem.style.overflow = '';
|
694
|
+
callback && callback();
|
695
|
+
}
|
696
|
+
};
|
697
|
+
|
698
|
+
opt.curAnim = {};
|
699
|
+
$.each(prop, function (name, val) {
|
700
|
+
opt.curAnim[name] = val;
|
701
|
+
});
|
702
|
+
|
703
|
+
$.each(prop, function (name, val) {
|
704
|
+
fx = new $.fx(elem, opt, name);
|
705
|
+
parts = rfxnum.exec(val);
|
706
|
+
start = parseFloat(name === 'opacity'
|
707
|
+
|| (elem.style && elem.style[name] != null) ?
|
708
|
+
$.css(elem, name) :
|
709
|
+
elem[name]);
|
710
|
+
end = parseFloat(parts[2]);
|
711
|
+
unit = parts[3];
|
712
|
+
if (name === 'height' || name === 'width') {
|
713
|
+
end = Math.max(0, end);
|
714
|
+
overflow = [elem.style.overflow,
|
715
|
+
elem.style.overflowX, elem.style.overflowY];
|
716
|
+
};
|
717
|
+
|
718
|
+
fx.custom(start, end, unit);
|
719
|
+
});
|
720
|
+
|
721
|
+
if (overflow != null) elem.style.overflow = 'hidden';
|
722
|
+
|
723
|
+
return this;
|
724
|
+
};
|
725
|
+
|
726
|
+
$.timers = [];
|
727
|
+
$.fx = function (elem, options, prop) {
|
728
|
+
this.elem = elem;
|
729
|
+
this.options = options;
|
730
|
+
this.prop = prop;
|
731
|
+
};
|
732
|
+
|
733
|
+
$.fx.prototype = {
|
734
|
+
custom: function (from, to, unit) {
|
735
|
+
var that = this;
|
736
|
+
that.startTime = $.fx.now();
|
737
|
+
that.start = from;
|
738
|
+
that.end = to;
|
739
|
+
that.unit = unit;
|
740
|
+
that.now = that.start;
|
741
|
+
that.state = that.pos = 0;
|
742
|
+
|
743
|
+
function t() {
|
744
|
+
return that.step();
|
745
|
+
};
|
746
|
+
t.elem = that.elem;
|
747
|
+
t();
|
748
|
+
$.timers.push(t);
|
749
|
+
if (!$.timerId) $.timerId = setInterval($.fx.tick, 13);
|
750
|
+
},
|
751
|
+
step: function () {
|
752
|
+
var that = this, t = $.fx.now(), done = true;
|
753
|
+
|
754
|
+
if (t >= that.options.speed + that.startTime) {
|
755
|
+
that.now = that.end;
|
756
|
+
that.state = that.pos = 1;
|
757
|
+
that.update();
|
758
|
+
|
759
|
+
that.options.curAnim[that.prop] = true;
|
760
|
+
for (var i in that.options.curAnim) {
|
761
|
+
if (that.options.curAnim[i] !== true) {
|
762
|
+
done = false;
|
763
|
+
};
|
764
|
+
};
|
765
|
+
|
766
|
+
if (done) that.options.callback.call(that.elem);
|
767
|
+
|
768
|
+
return false;
|
769
|
+
} else {
|
770
|
+
var n = t - that.startTime;
|
771
|
+
that.state = n / that.options.speed;
|
772
|
+
that.pos = $.easing[that.options.easing](that.state, n, 0, 1, that.options.speed);
|
773
|
+
that.now = that.start + ((that.end - that.start) * that.pos);
|
774
|
+
that.update();
|
775
|
+
return true;
|
776
|
+
};
|
777
|
+
},
|
778
|
+
update: function () {
|
779
|
+
var that = this;
|
780
|
+
if (that.prop === 'opacity') {
|
781
|
+
$.opacity.set(that.elem, that.now);
|
782
|
+
} else
|
783
|
+
if (that.elem.style && that.elem.style[that.prop] != null) {
|
784
|
+
that.elem.style[that.prop] = that.now + that.unit;
|
785
|
+
} else {
|
786
|
+
that.elem[that.prop] = that.now;
|
787
|
+
};
|
788
|
+
}
|
789
|
+
};
|
790
|
+
|
791
|
+
$.fx.now = function () {
|
792
|
+
return + new Date;
|
793
|
+
};
|
794
|
+
|
795
|
+
$.easing = {
|
796
|
+
linear: function (p, n, firstNum, diff) {
|
797
|
+
return firstNum + diff * p;
|
798
|
+
},
|
799
|
+
swing: function (p, n, firstNum, diff) {
|
800
|
+
return ((-Math.cos(p * Math.PI) / 2) + 0.5) * diff + firstNum;
|
801
|
+
}
|
802
|
+
};
|
803
|
+
|
804
|
+
$.fx.tick = function () {
|
805
|
+
var timers = $.timers;
|
806
|
+
for (var i = 0; i < timers.length; i++) {
|
807
|
+
!timers[i]() && timers.splice(i--, 1);
|
808
|
+
};
|
809
|
+
!timers.length && $.fx.stop();
|
810
|
+
};
|
811
|
+
|
812
|
+
$.fx.stop = function () {
|
813
|
+
clearInterval($.timerId);
|
814
|
+
$.timerId = null;
|
815
|
+
};
|
816
|
+
|
817
|
+
$.fn.stop = function () {
|
818
|
+
var timers = $.timers;
|
819
|
+
for (var i = timers.length - 1; i >= 0; i--) {
|
820
|
+
if (timers[i].elem === this[0]) timers.splice(i, 1);
|
821
|
+
};
|
822
|
+
return this;
|
823
|
+
};
|
824
|
+
|
825
|
+
//-------------end
|
826
|
+
return $}(window));
|
827
|
+
|
828
|
+
|
829
|
+
|
830
|
+
|
831
|
+
//------------------------------------------------
|
832
|
+
// 对话框模块
|
833
|
+
//------------------------------------------------
|
834
|
+
;(function ($, window, undefined) {
|
835
|
+
|
836
|
+
$.noop = $.noop || function () {}; // jQuery 1.3.2
|
837
|
+
var _box, _thisScript, _skin, _path,
|
838
|
+
_count = 0,
|
839
|
+
_$window = $(window),
|
840
|
+
_$document = $(document),
|
841
|
+
_$html = $('html'),
|
842
|
+
_elem = document.documentElement,
|
843
|
+
_isIE6 = window.VBArray && !window.XMLHttpRequest,
|
844
|
+
_isMobile = 'createTouch' in document && !('onmousemove' in _elem)
|
845
|
+
|| /(iPhone|iPad|iPod)/i.test(navigator.userAgent),
|
846
|
+
_expando = 'artDialog' + + new Date;
|
847
|
+
|
848
|
+
var artDialog = function (config, ok, cancel) {
|
849
|
+
config = config || {};
|
850
|
+
|
851
|
+
if (typeof config === 'string' || config.nodeType === 1) {
|
852
|
+
config = {content: config, fixed: !_isMobile};
|
853
|
+
};
|
854
|
+
|
855
|
+
var api,
|
856
|
+
defaults = artDialog.defaults,
|
857
|
+
elem = config.follow = this.nodeType === 1 && this || config.follow;
|
858
|
+
|
859
|
+
// 合并默认配置
|
860
|
+
for (var i in defaults) {
|
861
|
+
if (config[i] === undefined) config[i] = defaults[i];
|
862
|
+
};
|
863
|
+
|
864
|
+
// 兼容v4.1.0之前的参数,未来版本将删除此
|
865
|
+
$.each({ok:"yesFn",cancel:"noFn",close:"closeFn",init:"initFn",okVal:"yesText",cancelVal:"noText"},
|
866
|
+
function(i,o){config[i]=config[i]!==undefined?config[i]:config[o]});
|
867
|
+
|
868
|
+
// 返回跟随模式或重复定义的ID
|
869
|
+
if (typeof elem === 'string') elem = $(elem)[0];
|
870
|
+
config.id = elem && elem[_expando + 'follow'] || config.id || _expando + _count;
|
871
|
+
api = artDialog.list[config.id];
|
872
|
+
if (elem && api) return api.follow(elem).zIndex().focus();
|
873
|
+
if (api) return api.zIndex().focus();
|
874
|
+
|
875
|
+
// 目前主流移动设备对fixed支持不好
|
876
|
+
if (_isMobile) config.fixed = false;
|
877
|
+
|
878
|
+
// 按钮队列
|
879
|
+
if (!$.isArray(config.button)) {
|
880
|
+
config.button = config.button ? [config.button] : [];
|
881
|
+
};
|
882
|
+
if (ok !== undefined) config.ok = ok;
|
883
|
+
if (cancel !== undefined) config.cancel = cancel;
|
884
|
+
config.ok && config.button.push({
|
885
|
+
name: config.okVal,
|
886
|
+
callback: config.ok,
|
887
|
+
focus: true
|
888
|
+
});
|
889
|
+
config.cancel && config.button.push({
|
890
|
+
name: config.cancelVal,
|
891
|
+
callback: config.cancel
|
892
|
+
});
|
893
|
+
|
894
|
+
// zIndex全局配置
|
895
|
+
artDialog.defaults.zIndex = config.zIndex;
|
896
|
+
|
897
|
+
_count ++;
|
898
|
+
|
899
|
+
return artDialog.list[config.id] = _box ?
|
900
|
+
_box._init(config) : new artDialog.fn._init(config);
|
901
|
+
};
|
902
|
+
|
903
|
+
artDialog.fn = artDialog.prototype = {
|
904
|
+
|
905
|
+
version: '4.1.7',
|
906
|
+
|
907
|
+
closed: true,
|
908
|
+
|
909
|
+
_init: function (config) {
|
910
|
+
var that = this, DOM,
|
911
|
+
icon = config.icon,
|
912
|
+
iconBg = icon && (_isIE6 ? {png: 'icons/' + icon + '.png'}
|
913
|
+
: {backgroundImage: 'url(\'' + config.path + '/skins/icons/' + icon + '.png\')'});
|
914
|
+
|
915
|
+
that.closed = false;
|
916
|
+
that.config = config;
|
917
|
+
that.DOM = DOM = that.DOM || that._getDOM();
|
918
|
+
|
919
|
+
DOM.wrap.addClass(config.skin);
|
920
|
+
DOM.close[config.cancel === false ? 'hide' : 'show']();
|
921
|
+
DOM.icon[0].style.display = icon ? '' : 'none';
|
922
|
+
DOM.iconBg.css(iconBg || {background: 'none'});
|
923
|
+
DOM.se.css('cursor', config.resize ? 'se-resize' : 'auto');
|
924
|
+
DOM.title.css('cursor', config.drag ? 'move' : 'auto');
|
925
|
+
DOM.content.css('padding', config.padding);
|
926
|
+
|
927
|
+
that[config.show ? 'show' : 'hide'](true)
|
928
|
+
that.button(config.button)
|
929
|
+
.title(config.title)
|
930
|
+
.content(config.content, true)
|
931
|
+
.size(config.width, config.height)
|
932
|
+
.time(config.time);
|
933
|
+
|
934
|
+
config.follow
|
935
|
+
? that.follow(config.follow)
|
936
|
+
: that.position(config.left, config.top);
|
937
|
+
|
938
|
+
that.zIndex().focus();
|
939
|
+
config.lock && that.lock();
|
940
|
+
|
941
|
+
that._addEvent();
|
942
|
+
that._ie6PngFix();
|
943
|
+
_box = null;
|
944
|
+
|
945
|
+
config.init && config.init.call(that, window);
|
946
|
+
return that;
|
947
|
+
},
|
948
|
+
|
949
|
+
/**
|
950
|
+
* 设置内容
|
951
|
+
* @param {String, HTMLElement} 内容 (可选)
|
952
|
+
* @return {this, HTMLElement} 如果无参数则返回内容容器DOM对象
|
953
|
+
*/
|
954
|
+
content: function (msg) {
|
955
|
+
var prev, next, parent, display,
|
956
|
+
that = this,
|
957
|
+
DOM = that.DOM,
|
958
|
+
wrap = DOM.wrap[0],
|
959
|
+
width = wrap.offsetWidth,
|
960
|
+
height = wrap.offsetHeight,
|
961
|
+
left = parseInt(wrap.style.left),
|
962
|
+
top = parseInt(wrap.style.top),
|
963
|
+
cssWidth = wrap.style.width,
|
964
|
+
$content = DOM.content,
|
965
|
+
content = $content[0];
|
966
|
+
|
967
|
+
that._elemBack && that._elemBack();
|
968
|
+
wrap.style.width = 'auto';
|
969
|
+
|
970
|
+
if (msg === undefined) return content;
|
971
|
+
if (typeof msg === 'string') {
|
972
|
+
$content.html(msg);
|
973
|
+
} else if (msg && msg.nodeType === 1) {
|
974
|
+
|
975
|
+
// 让传入的元素在对话框关闭后可以返回到原来的地方
|
976
|
+
display = msg.style.display;
|
977
|
+
prev = msg.previousSibling;
|
978
|
+
next = msg.nextSibling;
|
979
|
+
parent = msg.parentNode;
|
980
|
+
that._elemBack = function () {
|
981
|
+
if (prev && prev.parentNode) {
|
982
|
+
prev.parentNode.insertBefore(msg, prev.nextSibling);
|
983
|
+
} else if (next && next.parentNode) {
|
984
|
+
next.parentNode.insertBefore(msg, next);
|
985
|
+
} else if (parent) {
|
986
|
+
parent.appendChild(msg);
|
987
|
+
};
|
988
|
+
msg.style.display = display;
|
989
|
+
that._elemBack = null;
|
990
|
+
};
|
991
|
+
|
992
|
+
$content.html('');
|
993
|
+
content.appendChild(msg);
|
994
|
+
msg.style.display = 'block';
|
995
|
+
|
996
|
+
};
|
997
|
+
|
998
|
+
// 新增内容后调整位置
|
999
|
+
if (!arguments[1]) {
|
1000
|
+
if (that.config.follow) {
|
1001
|
+
that.follow(that.config.follow);
|
1002
|
+
} else {
|
1003
|
+
width = wrap.offsetWidth - width;
|
1004
|
+
height = wrap.offsetHeight - height;
|
1005
|
+
left = left - width / 2;
|
1006
|
+
top = top - height / 2;
|
1007
|
+
wrap.style.left = Math.max(left, 0) + 'px';
|
1008
|
+
wrap.style.top = Math.max(top, 0) + 'px';
|
1009
|
+
};
|
1010
|
+
if (cssWidth && cssWidth !== 'auto') {
|
1011
|
+
wrap.style.width = wrap.offsetWidth + 'px';
|
1012
|
+
};
|
1013
|
+
that._autoPositionType();
|
1014
|
+
};
|
1015
|
+
|
1016
|
+
that._ie6SelectFix();
|
1017
|
+
that._runScript(content);
|
1018
|
+
|
1019
|
+
return that;
|
1020
|
+
},
|
1021
|
+
|
1022
|
+
/**
|
1023
|
+
* 设置标题
|
1024
|
+
* @param {String, Boolean} 标题内容. 为false则隐藏标题栏
|
1025
|
+
* @return {this, HTMLElement} 如果无参数则返回内容器DOM对象
|
1026
|
+
*/
|
1027
|
+
title: function (text) {
|
1028
|
+
var DOM = this.DOM,
|
1029
|
+
wrap = DOM.wrap,
|
1030
|
+
title = DOM.title,
|
1031
|
+
className = 'aui_state_noTitle';
|
1032
|
+
|
1033
|
+
if (text === undefined) return title[0];
|
1034
|
+
if (text === false) {
|
1035
|
+
title.hide().html('');
|
1036
|
+
wrap.addClass(className);
|
1037
|
+
} else {
|
1038
|
+
title.show().html(text || '');
|
1039
|
+
wrap.removeClass(className);
|
1040
|
+
};
|
1041
|
+
|
1042
|
+
return this;
|
1043
|
+
},
|
1044
|
+
|
1045
|
+
/**
|
1046
|
+
* 位置(相对于可视区域)
|
1047
|
+
* @param {Number, String}
|
1048
|
+
* @param {Number, String}
|
1049
|
+
*/
|
1050
|
+
position: function (left, top) {
|
1051
|
+
var that = this,
|
1052
|
+
config = that.config,
|
1053
|
+
wrap = that.DOM.wrap[0],
|
1054
|
+
isFixed = _isIE6 ? false : config.fixed,
|
1055
|
+
ie6Fixed = _isIE6 && that.config.fixed,
|
1056
|
+
docLeft = _$document.scrollLeft(),
|
1057
|
+
docTop = _$document.scrollTop(),
|
1058
|
+
dl = isFixed ? 0 : docLeft,
|
1059
|
+
dt = isFixed ? 0 : docTop,
|
1060
|
+
ww = _$window.width(),
|
1061
|
+
wh = _$window.height(),
|
1062
|
+
ow = wrap.offsetWidth,
|
1063
|
+
oh = wrap.offsetHeight,
|
1064
|
+
style = wrap.style;
|
1065
|
+
|
1066
|
+
if (left || left === 0) {
|
1067
|
+
that._left = left.toString().indexOf('%') !== -1 ? left : null;
|
1068
|
+
left = that._toNumber(left, ww - ow);
|
1069
|
+
|
1070
|
+
if (typeof left === 'number') {
|
1071
|
+
left = ie6Fixed ? (left += docLeft) : left + dl;
|
1072
|
+
style.left = Math.max(left, dl) + 'px';
|
1073
|
+
} else if (typeof left === 'string') {
|
1074
|
+
style.left = left;
|
1075
|
+
};
|
1076
|
+
};
|
1077
|
+
|
1078
|
+
if (top || top === 0) {
|
1079
|
+
that._top = top.toString().indexOf('%') !== -1 ? top : null;
|
1080
|
+
top = that._toNumber(top, wh - oh);
|
1081
|
+
|
1082
|
+
if (typeof top === 'number') {
|
1083
|
+
top = ie6Fixed ? (top += docTop) : top + dt;
|
1084
|
+
style.top = Math.max(top, dt) + 'px';
|
1085
|
+
} else if (typeof top === 'string') {
|
1086
|
+
style.top = top;
|
1087
|
+
};
|
1088
|
+
};
|
1089
|
+
|
1090
|
+
if (left !== undefined && top !== undefined) {
|
1091
|
+
that._follow = null;
|
1092
|
+
that._autoPositionType();
|
1093
|
+
};
|
1094
|
+
|
1095
|
+
return that;
|
1096
|
+
},
|
1097
|
+
|
1098
|
+
/**
|
1099
|
+
* 尺寸
|
1100
|
+
* @param {Number, String} 宽度
|
1101
|
+
* @param {Number, String} 高度
|
1102
|
+
*/
|
1103
|
+
size: function (width, height) {
|
1104
|
+
var maxWidth, maxHeight, scaleWidth, scaleHeight,
|
1105
|
+
that = this,
|
1106
|
+
config = that.config,
|
1107
|
+
DOM = that.DOM,
|
1108
|
+
wrap = DOM.wrap,
|
1109
|
+
main = DOM.main,
|
1110
|
+
wrapStyle = wrap[0].style,
|
1111
|
+
style = main[0].style;
|
1112
|
+
|
1113
|
+
if (width) {
|
1114
|
+
that._width = width.toString().indexOf('%') !== -1 ? width : null;
|
1115
|
+
maxWidth = _$window.width() - wrap[0].offsetWidth + main[0].offsetWidth;
|
1116
|
+
scaleWidth = that._toNumber(width, maxWidth);
|
1117
|
+
width = scaleWidth;
|
1118
|
+
|
1119
|
+
if (typeof width === 'number') {
|
1120
|
+
wrapStyle.width = 'auto';
|
1121
|
+
style.width = Math.max(that.config.minWidth, width) + 'px';
|
1122
|
+
wrapStyle.width = wrap[0].offsetWidth + 'px'; // 防止未定义宽度的表格遇到浏览器右边边界伸缩
|
1123
|
+
} else if (typeof width === 'string') {
|
1124
|
+
style.width = width;
|
1125
|
+
width === 'auto' && wrap.css('width', 'auto');
|
1126
|
+
};
|
1127
|
+
};
|
1128
|
+
|
1129
|
+
if (height) {
|
1130
|
+
that._height = height.toString().indexOf('%') !== -1 ? height : null;
|
1131
|
+
maxHeight = _$window.height() - wrap[0].offsetHeight + main[0].offsetHeight;
|
1132
|
+
scaleHeight = that._toNumber(height, maxHeight);
|
1133
|
+
height = scaleHeight;
|
1134
|
+
|
1135
|
+
if (typeof height === 'number') {
|
1136
|
+
style.height = Math.max(that.config.minHeight, height) + 'px';
|
1137
|
+
} else if (typeof height === 'string') {
|
1138
|
+
style.height = height;
|
1139
|
+
};
|
1140
|
+
};
|
1141
|
+
|
1142
|
+
that._ie6SelectFix();
|
1143
|
+
|
1144
|
+
return that;
|
1145
|
+
},
|
1146
|
+
|
1147
|
+
/**
|
1148
|
+
* 跟随元素
|
1149
|
+
* @param {HTMLElement, String}
|
1150
|
+
*/
|
1151
|
+
follow: function (elem) {
|
1152
|
+
var $elem, that = this, config = that.config;
|
1153
|
+
|
1154
|
+
if (typeof elem === 'string' || elem && elem.nodeType === 1) {
|
1155
|
+
$elem = $(elem);
|
1156
|
+
elem = $elem[0];
|
1157
|
+
};
|
1158
|
+
|
1159
|
+
// 隐藏元素不可用
|
1160
|
+
if (!elem || !elem.offsetWidth && !elem.offsetHeight) {
|
1161
|
+
return that.position(that._left, that._top);
|
1162
|
+
};
|
1163
|
+
|
1164
|
+
var expando = _expando + 'follow',
|
1165
|
+
winWidth = _$window.width(),
|
1166
|
+
winHeight = _$window.height(),
|
1167
|
+
docLeft = _$document.scrollLeft(),
|
1168
|
+
docTop = _$document.scrollTop(),
|
1169
|
+
offset = $elem.offset(),
|
1170
|
+
width = elem.offsetWidth,
|
1171
|
+
height = elem.offsetHeight,
|
1172
|
+
isFixed = _isIE6 ? false : config.fixed,
|
1173
|
+
left = isFixed ? offset.left - docLeft : offset.left,
|
1174
|
+
top = isFixed ? offset.top - docTop : offset.top,
|
1175
|
+
wrap = that.DOM.wrap[0],
|
1176
|
+
style = wrap.style,
|
1177
|
+
wrapWidth = wrap.offsetWidth,
|
1178
|
+
wrapHeight = wrap.offsetHeight,
|
1179
|
+
setLeft = left - (wrapWidth - width) / 2,
|
1180
|
+
setTop = top + height,
|
1181
|
+
dl = isFixed ? 0 : docLeft,
|
1182
|
+
dt = isFixed ? 0 : docTop;
|
1183
|
+
|
1184
|
+
setLeft = setLeft < dl ? left :
|
1185
|
+
(setLeft + wrapWidth > winWidth) && (left - wrapWidth > dl)
|
1186
|
+
? left - wrapWidth + width
|
1187
|
+
: setLeft;
|
1188
|
+
|
1189
|
+
setTop = (setTop + wrapHeight > winHeight + dt)
|
1190
|
+
&& (top - wrapHeight > dt)
|
1191
|
+
? top - wrapHeight
|
1192
|
+
: setTop;
|
1193
|
+
|
1194
|
+
style.left = setLeft + 'px';
|
1195
|
+
style.top = setTop + 'px';
|
1196
|
+
|
1197
|
+
that._follow && that._follow.removeAttribute(expando);
|
1198
|
+
that._follow = elem;
|
1199
|
+
elem[expando] = config.id;
|
1200
|
+
that._autoPositionType();
|
1201
|
+
return that;
|
1202
|
+
},
|
1203
|
+
|
1204
|
+
/**
|
1205
|
+
* 自定义按钮
|
1206
|
+
* @example
|
1207
|
+
button({
|
1208
|
+
name: 'login',
|
1209
|
+
callback: function () {},
|
1210
|
+
disabled: false,
|
1211
|
+
focus: true
|
1212
|
+
}, .., ..)
|
1213
|
+
*/
|
1214
|
+
button: function () {
|
1215
|
+
var that = this,
|
1216
|
+
ags = arguments,
|
1217
|
+
DOM = that.DOM,
|
1218
|
+
buttons = DOM.buttons,
|
1219
|
+
elem = buttons[0],
|
1220
|
+
strongButton = 'aui_state_highlight',
|
1221
|
+
listeners = that._listeners = that._listeners || {},
|
1222
|
+
list = $.isArray(ags[0]) ? ags[0] : [].slice.call(ags);
|
1223
|
+
|
1224
|
+
if (ags[0] === undefined) return elem;
|
1225
|
+
$.each(list, function (i, val) {
|
1226
|
+
var name = val.name,
|
1227
|
+
isNewButton = !listeners[name],
|
1228
|
+
button = !isNewButton ?
|
1229
|
+
listeners[name].elem :
|
1230
|
+
document.createElement('button');
|
1231
|
+
|
1232
|
+
if (!listeners[name]) listeners[name] = {};
|
1233
|
+
if (val.callback) listeners[name].callback = val.callback;
|
1234
|
+
if (val.className) button.className = val.className;
|
1235
|
+
if (val.focus) {
|
1236
|
+
that._focus && that._focus.removeClass(strongButton);
|
1237
|
+
that._focus = $(button).addClass(strongButton);
|
1238
|
+
that.focus();
|
1239
|
+
};
|
1240
|
+
|
1241
|
+
// Internet Explorer 的默认类型是 "button",
|
1242
|
+
// 而其他浏览器中(包括 W3C 规范)的默认值是 "submit"
|
1243
|
+
// @see http://www.w3school.com.cn/tags/att_button_type.asp
|
1244
|
+
button.setAttribute('type', 'button');
|
1245
|
+
|
1246
|
+
button[_expando + 'callback'] = name;
|
1247
|
+
button.disabled = !!val.disabled;
|
1248
|
+
|
1249
|
+
if (isNewButton) {
|
1250
|
+
button.innerHTML = name;
|
1251
|
+
listeners[name].elem = button;
|
1252
|
+
elem.appendChild(button);
|
1253
|
+
};
|
1254
|
+
});
|
1255
|
+
|
1256
|
+
buttons[0].style.display = list.length ? '' : 'none';
|
1257
|
+
|
1258
|
+
that._ie6SelectFix();
|
1259
|
+
return that;
|
1260
|
+
},
|
1261
|
+
|
1262
|
+
/** 显示对话框 */
|
1263
|
+
show: function () {
|
1264
|
+
this.DOM.wrap.show();
|
1265
|
+
!arguments[0] && this._lockMaskWrap && this._lockMaskWrap.show();
|
1266
|
+
return this;
|
1267
|
+
},
|
1268
|
+
|
1269
|
+
/** 隐藏对话框 */
|
1270
|
+
hide: function () {
|
1271
|
+
this.DOM.wrap.hide();
|
1272
|
+
!arguments[0] && this._lockMaskWrap && this._lockMaskWrap.hide();
|
1273
|
+
return this;
|
1274
|
+
},
|
1275
|
+
|
1276
|
+
/** 关闭对话框 */
|
1277
|
+
close: function () {
|
1278
|
+
if (this.closed) return this;
|
1279
|
+
|
1280
|
+
var that = this,
|
1281
|
+
DOM = that.DOM,
|
1282
|
+
wrap = DOM.wrap,
|
1283
|
+
list = artDialog.list,
|
1284
|
+
fn = that.config.close,
|
1285
|
+
follow = that.config.follow;
|
1286
|
+
|
1287
|
+
that.time();
|
1288
|
+
if (typeof fn === 'function' && fn.call(that, window) === false) {
|
1289
|
+
return that;
|
1290
|
+
};
|
1291
|
+
|
1292
|
+
that.unlock();
|
1293
|
+
|
1294
|
+
// 置空内容
|
1295
|
+
that._elemBack && that._elemBack();
|
1296
|
+
wrap[0].className = wrap[0].style.cssText = '';
|
1297
|
+
DOM.title.html('');
|
1298
|
+
DOM.content.html('');
|
1299
|
+
DOM.buttons.html('');
|
1300
|
+
|
1301
|
+
if (artDialog.focus === that) artDialog.focus = null;
|
1302
|
+
if (follow) follow.removeAttribute(_expando + 'follow');
|
1303
|
+
delete list[that.config.id];
|
1304
|
+
that._removeEvent();
|
1305
|
+
that.hide(true)._setAbsolute();
|
1306
|
+
|
1307
|
+
// 清空除this.DOM之外临时对象,恢复到初始状态,以便使用单例模式
|
1308
|
+
for (var i in that) {
|
1309
|
+
if (that.hasOwnProperty(i) && i !== 'DOM') delete that[i];
|
1310
|
+
};
|
1311
|
+
|
1312
|
+
// 移除HTMLElement或重用
|
1313
|
+
_box ? wrap.remove() : _box = that;
|
1314
|
+
|
1315
|
+
return that;
|
1316
|
+
},
|
1317
|
+
|
1318
|
+
/**
|
1319
|
+
* 定时关闭
|
1320
|
+
* @param {Number} 单位为秒, 无参数则停止计时器
|
1321
|
+
*/
|
1322
|
+
time: function (second) {
|
1323
|
+
var that = this,
|
1324
|
+
cancel = that.config.cancelVal,
|
1325
|
+
timer = that._timer;
|
1326
|
+
|
1327
|
+
timer && clearTimeout(timer);
|
1328
|
+
|
1329
|
+
if (second) {
|
1330
|
+
that._timer = setTimeout(function(){
|
1331
|
+
that._click(cancel);
|
1332
|
+
}, 1000 * second);
|
1333
|
+
};
|
1334
|
+
|
1335
|
+
return that;
|
1336
|
+
},
|
1337
|
+
|
1338
|
+
/** 设置焦点 */
|
1339
|
+
focus: function () {
|
1340
|
+
try {
|
1341
|
+
if (this.config.focus) {
|
1342
|
+
var elem = this._focus && this._focus[0] || this.DOM.close[0];
|
1343
|
+
elem && elem.focus();
|
1344
|
+
}
|
1345
|
+
} catch (e) {}; // IE对不可见元素设置焦点会报错
|
1346
|
+
return this;
|
1347
|
+
},
|
1348
|
+
|
1349
|
+
/** 置顶对话框 */
|
1350
|
+
zIndex: function () {
|
1351
|
+
var that = this,
|
1352
|
+
DOM = that.DOM,
|
1353
|
+
wrap = DOM.wrap,
|
1354
|
+
top = artDialog.focus,
|
1355
|
+
index = artDialog.defaults.zIndex ++;
|
1356
|
+
|
1357
|
+
// 设置叠加高度
|
1358
|
+
wrap.css('zIndex', index);
|
1359
|
+
that._lockMask && that._lockMask.css('zIndex', index - 1);
|
1360
|
+
|
1361
|
+
// 设置最高层的样式
|
1362
|
+
top && top.DOM.wrap.removeClass('aui_state_focus');
|
1363
|
+
artDialog.focus = that;
|
1364
|
+
wrap.addClass('aui_state_focus');
|
1365
|
+
|
1366
|
+
return that;
|
1367
|
+
},
|
1368
|
+
|
1369
|
+
/** 设置屏锁 */
|
1370
|
+
lock: function () {
|
1371
|
+
if (this._lock) return this;
|
1372
|
+
|
1373
|
+
var that = this,
|
1374
|
+
index = artDialog.defaults.zIndex - 1,
|
1375
|
+
wrap = that.DOM.wrap,
|
1376
|
+
config = that.config,
|
1377
|
+
docWidth = _$document.width(),
|
1378
|
+
docHeight = _$document.height(),
|
1379
|
+
lockMaskWrap = that._lockMaskWrap || $(document.body.appendChild(document.createElement('div'))),
|
1380
|
+
lockMask = that._lockMask || $(lockMaskWrap[0].appendChild(document.createElement('div'))),
|
1381
|
+
domTxt = '(document).documentElement',
|
1382
|
+
sizeCss = _isMobile ? 'width:' + docWidth + 'px;height:' + docHeight
|
1383
|
+
+ 'px' : 'width:100%;height:100%',
|
1384
|
+
ie6Css = _isIE6 ?
|
1385
|
+
'position:absolute;left:expression(' + domTxt + '.scrollLeft);top:expression('
|
1386
|
+
+ domTxt + '.scrollTop);width:expression(' + domTxt
|
1387
|
+
+ '.clientWidth);height:expression(' + domTxt + '.clientHeight)'
|
1388
|
+
: '';
|
1389
|
+
|
1390
|
+
that.zIndex();
|
1391
|
+
wrap.addClass('aui_state_lock');
|
1392
|
+
|
1393
|
+
lockMaskWrap[0].style.cssText = sizeCss + ';position:fixed;z-index:'
|
1394
|
+
+ index + ';top:0;left:0;overflow:hidden;' + ie6Css;
|
1395
|
+
lockMask[0].style.cssText = 'height:100%;background:' + config.background
|
1396
|
+
+ ';filter:alpha(opacity=0);opacity:0';
|
1397
|
+
|
1398
|
+
// 让IE6锁屏遮罩能够盖住下拉控件
|
1399
|
+
if (_isIE6) lockMask.html(
|
1400
|
+
'<iframe src="about:blank" style="width:100%;height:100%;position:absolute;' +
|
1401
|
+
'top:0;left:0;z-index:-1;filter:alpha(opacity=0)"></iframe>');
|
1402
|
+
|
1403
|
+
lockMask.stop();
|
1404
|
+
lockMask.bind('click', function () {
|
1405
|
+
that._reset();
|
1406
|
+
}).bind('dblclick', function () {
|
1407
|
+
that._click(that.config.cancelVal);
|
1408
|
+
});
|
1409
|
+
|
1410
|
+
if (config.duration === 0) {
|
1411
|
+
lockMask.css({opacity: config.opacity});
|
1412
|
+
} else {
|
1413
|
+
lockMask.animate({opacity: config.opacity}, config.duration);
|
1414
|
+
};
|
1415
|
+
|
1416
|
+
that._lockMaskWrap = lockMaskWrap;
|
1417
|
+
that._lockMask = lockMask;
|
1418
|
+
|
1419
|
+
that._lock = true;
|
1420
|
+
return that;
|
1421
|
+
},
|
1422
|
+
|
1423
|
+
/** 解开屏锁 */
|
1424
|
+
unlock: function () {
|
1425
|
+
var that = this,
|
1426
|
+
lockMaskWrap = that._lockMaskWrap,
|
1427
|
+
lockMask = that._lockMask;
|
1428
|
+
|
1429
|
+
if (!that._lock) return that;
|
1430
|
+
var style = lockMaskWrap[0].style;
|
1431
|
+
var un = function () {
|
1432
|
+
if (_isIE6) {
|
1433
|
+
style.removeExpression('width');
|
1434
|
+
style.removeExpression('height');
|
1435
|
+
style.removeExpression('left');
|
1436
|
+
style.removeExpression('top');
|
1437
|
+
};
|
1438
|
+
style.cssText = 'display:none';
|
1439
|
+
|
1440
|
+
_box && lockMaskWrap.remove();
|
1441
|
+
};
|
1442
|
+
|
1443
|
+
lockMask.stop().unbind();
|
1444
|
+
that.DOM.wrap.removeClass('aui_state_lock');
|
1445
|
+
if (!that.config.duration) {// 取消动画,快速关闭
|
1446
|
+
un();
|
1447
|
+
} else {
|
1448
|
+
lockMask.animate({opacity: 0}, that.config.duration, un);
|
1449
|
+
};
|
1450
|
+
|
1451
|
+
that._lock = false;
|
1452
|
+
return that;
|
1453
|
+
},
|
1454
|
+
|
1455
|
+
// 获取元素
|
1456
|
+
_getDOM: function () {
|
1457
|
+
var wrap = document.createElement('div'),
|
1458
|
+
body = document.body;
|
1459
|
+
wrap.style.cssText = 'position:absolute;left:0;top:0';
|
1460
|
+
wrap.innerHTML = artDialog._templates;
|
1461
|
+
body.insertBefore(wrap, body.firstChild);
|
1462
|
+
|
1463
|
+
var name, i = 0,
|
1464
|
+
DOM = {wrap: $(wrap)},
|
1465
|
+
els = wrap.getElementsByTagName('*'),
|
1466
|
+
elsLen = els.length;
|
1467
|
+
|
1468
|
+
for (; i < elsLen; i ++) {
|
1469
|
+
name = els[i].className.split('aui_')[1];
|
1470
|
+
if (name) DOM[name] = $(els[i]);
|
1471
|
+
};
|
1472
|
+
|
1473
|
+
return DOM;
|
1474
|
+
},
|
1475
|
+
|
1476
|
+
// px与%单位转换成数值 (百分比单位按照最大值换算)
|
1477
|
+
// 其他的单位返回原值
|
1478
|
+
_toNumber: function (thisValue, maxValue) {
|
1479
|
+
if (!thisValue && thisValue !== 0 || typeof thisValue === 'number') {
|
1480
|
+
return thisValue;
|
1481
|
+
};
|
1482
|
+
|
1483
|
+
var last = thisValue.length - 1;
|
1484
|
+
if (thisValue.lastIndexOf('px') === last) {
|
1485
|
+
thisValue = parseInt(thisValue);
|
1486
|
+
} else if (thisValue.lastIndexOf('%') === last) {
|
1487
|
+
thisValue = parseInt(maxValue * thisValue.split('%')[0] / 100);
|
1488
|
+
};
|
1489
|
+
|
1490
|
+
return thisValue;
|
1491
|
+
},
|
1492
|
+
|
1493
|
+
// 让IE6 CSS支持PNG背景
|
1494
|
+
_ie6PngFix: _isIE6 ? function () {
|
1495
|
+
var i = 0, elem, png, pngPath, runtimeStyle,
|
1496
|
+
path = artDialog.defaults.path + '/skins/',
|
1497
|
+
list = this.DOM.wrap[0].getElementsByTagName('*');
|
1498
|
+
|
1499
|
+
for (; i < list.length; i ++) {
|
1500
|
+
elem = list[i];
|
1501
|
+
png = elem.currentStyle['png'];
|
1502
|
+
if (png) {
|
1503
|
+
pngPath = path + png;
|
1504
|
+
runtimeStyle = elem.runtimeStyle;
|
1505
|
+
runtimeStyle.backgroundImage = 'none';
|
1506
|
+
runtimeStyle.filter = "progid:DXImageTransform.Microsoft." +
|
1507
|
+
"AlphaImageLoader(src='" + pngPath + "',sizingMethod='crop')";
|
1508
|
+
};
|
1509
|
+
};
|
1510
|
+
} : $.noop,
|
1511
|
+
|
1512
|
+
// 强制覆盖IE6下拉控件
|
1513
|
+
_ie6SelectFix: _isIE6 ? function () {
|
1514
|
+
var $wrap = this.DOM.wrap,
|
1515
|
+
wrap = $wrap[0],
|
1516
|
+
expando = _expando + 'iframeMask',
|
1517
|
+
iframe = $wrap[expando],
|
1518
|
+
width = wrap.offsetWidth,
|
1519
|
+
height = wrap.offsetHeight;
|
1520
|
+
|
1521
|
+
width = width + 'px';
|
1522
|
+
height = height + 'px';
|
1523
|
+
if (iframe) {
|
1524
|
+
iframe.style.width = width;
|
1525
|
+
iframe.style.height = height;
|
1526
|
+
} else {
|
1527
|
+
iframe = wrap.appendChild(document.createElement('iframe'));
|
1528
|
+
$wrap[expando] = iframe;
|
1529
|
+
iframe.src = 'about:blank';
|
1530
|
+
iframe.style.cssText = 'position:absolute;z-index:-1;left:0;top:0;'
|
1531
|
+
+ 'filter:alpha(opacity=0);width:' + width + ';height:' + height;
|
1532
|
+
};
|
1533
|
+
} : $.noop,
|
1534
|
+
|
1535
|
+
// 解析HTML片段中自定义类型脚本,其this指向artDialog内部
|
1536
|
+
// <script type="text/dialog">/* [code] */</script>
|
1537
|
+
_runScript: function (elem) {
|
1538
|
+
var fun, i = 0, n = 0,
|
1539
|
+
tags = elem.getElementsByTagName('script'),
|
1540
|
+
length = tags.length,
|
1541
|
+
script = [];
|
1542
|
+
|
1543
|
+
for (; i < length; i ++) {
|
1544
|
+
if (tags[i].type === 'text/dialog') {
|
1545
|
+
script[n] = tags[i].innerHTML;
|
1546
|
+
n ++;
|
1547
|
+
};
|
1548
|
+
};
|
1549
|
+
|
1550
|
+
if (script.length) {
|
1551
|
+
script = script.join('');
|
1552
|
+
fun = new Function(script);
|
1553
|
+
fun.call(this);
|
1554
|
+
};
|
1555
|
+
},
|
1556
|
+
|
1557
|
+
// 自动切换定位类型
|
1558
|
+
_autoPositionType: function () {
|
1559
|
+
this[this.config.fixed ? '_setFixed' : '_setAbsolute']();/////////////
|
1560
|
+
},
|
1561
|
+
|
1562
|
+
|
1563
|
+
// 设置静止定位
|
1564
|
+
// IE6 Fixed @see: http://www.planeart.cn/?p=877
|
1565
|
+
_setFixed: (function () {
|
1566
|
+
_isIE6 && $(function () {
|
1567
|
+
var bg = 'backgroundAttachment';
|
1568
|
+
if (_$html.css(bg) !== 'fixed' && $('body').css(bg) !== 'fixed') {
|
1569
|
+
_$html.css({
|
1570
|
+
zoom: 1,// 避免偶尔出现body背景图片异常的情况
|
1571
|
+
backgroundImage: 'url(about:blank)',
|
1572
|
+
backgroundAttachment: 'fixed'
|
1573
|
+
});
|
1574
|
+
};
|
1575
|
+
});
|
1576
|
+
|
1577
|
+
return function () {
|
1578
|
+
var $elem = this.DOM.wrap,
|
1579
|
+
style = $elem[0].style;
|
1580
|
+
|
1581
|
+
if (_isIE6) {
|
1582
|
+
var left = parseInt($elem.css('left')),
|
1583
|
+
top = parseInt($elem.css('top')),
|
1584
|
+
sLeft = _$document.scrollLeft(),
|
1585
|
+
sTop = _$document.scrollTop(),
|
1586
|
+
txt = '(document.documentElement)';
|
1587
|
+
|
1588
|
+
this._setAbsolute();
|
1589
|
+
style.setExpression('left', 'eval(' + txt + '.scrollLeft + '
|
1590
|
+
+ (left - sLeft) + ') + "px"');
|
1591
|
+
style.setExpression('top', 'eval(' + txt + '.scrollTop + '
|
1592
|
+
+ (top - sTop) + ') + "px"');
|
1593
|
+
} else {
|
1594
|
+
style.position = 'fixed';
|
1595
|
+
};
|
1596
|
+
};
|
1597
|
+
}()),
|
1598
|
+
|
1599
|
+
// 设置绝对定位
|
1600
|
+
_setAbsolute: function () {
|
1601
|
+
var style = this.DOM.wrap[0].style;
|
1602
|
+
|
1603
|
+
if (_isIE6) {
|
1604
|
+
style.removeExpression('left');
|
1605
|
+
style.removeExpression('top');
|
1606
|
+
};
|
1607
|
+
|
1608
|
+
style.position = 'absolute';
|
1609
|
+
},
|
1610
|
+
|
1611
|
+
// 按钮回调函数触发
|
1612
|
+
_click: function (name) {
|
1613
|
+
var that = this,
|
1614
|
+
fn = that._listeners[name] && that._listeners[name].callback;
|
1615
|
+
return typeof fn !== 'function' || fn.call(that, window) !== false ?
|
1616
|
+
that.close() : that;
|
1617
|
+
},
|
1618
|
+
|
1619
|
+
// 重置位置与尺寸
|
1620
|
+
_reset: function (test) {
|
1621
|
+
var newSize,
|
1622
|
+
that = this,
|
1623
|
+
oldSize = that._winSize || _$window.width() * _$window.height(),
|
1624
|
+
elem = that._follow,
|
1625
|
+
width = that._width,
|
1626
|
+
height = that._height,
|
1627
|
+
left = that._left,
|
1628
|
+
top = that._top;
|
1629
|
+
|
1630
|
+
if (test) {
|
1631
|
+
// IE6~7 window.onresize bug
|
1632
|
+
newSize = that._winSize = _$window.width() * _$window.height();
|
1633
|
+
if (oldSize === newSize) return;
|
1634
|
+
};
|
1635
|
+
|
1636
|
+
if (width || height) that.size(width, height);
|
1637
|
+
|
1638
|
+
if (elem) {
|
1639
|
+
that.follow(elem);
|
1640
|
+
} else if (left || top) {
|
1641
|
+
that.position(left, top);
|
1642
|
+
};
|
1643
|
+
},
|
1644
|
+
|
1645
|
+
// 事件代理
|
1646
|
+
_addEvent: function () {
|
1647
|
+
var resizeTimer,
|
1648
|
+
that = this,
|
1649
|
+
config = that.config,
|
1650
|
+
isIE = 'CollectGarbage' in window,
|
1651
|
+
DOM = that.DOM;
|
1652
|
+
|
1653
|
+
// 窗口调节事件
|
1654
|
+
that._winResize = function () {
|
1655
|
+
resizeTimer && clearTimeout(resizeTimer);
|
1656
|
+
resizeTimer = setTimeout(function () {
|
1657
|
+
that._reset(isIE);
|
1658
|
+
}, 40);
|
1659
|
+
};
|
1660
|
+
_$window.bind('resize', that._winResize);
|
1661
|
+
|
1662
|
+
// 监听点击
|
1663
|
+
DOM.wrap
|
1664
|
+
.bind('click', function (event) {
|
1665
|
+
var target = event.target, callbackID;
|
1666
|
+
|
1667
|
+
if (target.disabled) return false; // IE BUG
|
1668
|
+
|
1669
|
+
if (target === DOM.close[0]) {
|
1670
|
+
that._click(config.cancelVal);
|
1671
|
+
return false;
|
1672
|
+
} else {
|
1673
|
+
callbackID = target[_expando + 'callback'];
|
1674
|
+
callbackID && that._click(callbackID);
|
1675
|
+
};
|
1676
|
+
|
1677
|
+
that._ie6SelectFix();
|
1678
|
+
})
|
1679
|
+
.bind('mousedown', function () {
|
1680
|
+
that.zIndex();
|
1681
|
+
});
|
1682
|
+
},
|
1683
|
+
|
1684
|
+
// 卸载事件代理
|
1685
|
+
_removeEvent: function () {
|
1686
|
+
var that = this,
|
1687
|
+
DOM = that.DOM;
|
1688
|
+
|
1689
|
+
DOM.wrap.unbind();
|
1690
|
+
_$window.unbind('resize', that._winResize);
|
1691
|
+
}
|
1692
|
+
|
1693
|
+
};
|
1694
|
+
|
1695
|
+
artDialog.fn._init.prototype = artDialog.fn;
|
1696
|
+
$.fn.dialog = $.fn.artDialog = function () {
|
1697
|
+
var config = arguments;
|
1698
|
+
this[this.live ? 'live' : 'bind']('click', function () {
|
1699
|
+
artDialog.apply(this, config);
|
1700
|
+
return false;
|
1701
|
+
});
|
1702
|
+
return this;
|
1703
|
+
};
|
1704
|
+
|
1705
|
+
|
1706
|
+
|
1707
|
+
/** 最顶层的对话框API */
|
1708
|
+
artDialog.focus = null;
|
1709
|
+
|
1710
|
+
|
1711
|
+
/** 获取某对话框API */
|
1712
|
+
artDialog.get = function (id) {
|
1713
|
+
return id === undefined
|
1714
|
+
? artDialog.list
|
1715
|
+
: artDialog.list[id];
|
1716
|
+
};
|
1717
|
+
|
1718
|
+
artDialog.list = {};
|
1719
|
+
|
1720
|
+
|
1721
|
+
|
1722
|
+
// 全局快捷键
|
1723
|
+
_$document.bind('keydown', function (event) {
|
1724
|
+
var target = event.target,
|
1725
|
+
nodeName = target.nodeName,
|
1726
|
+
rinput = /^INPUT|TEXTAREA$/,
|
1727
|
+
api = artDialog.focus,
|
1728
|
+
keyCode = event.keyCode;
|
1729
|
+
|
1730
|
+
if (!api || !api.config.esc || rinput.test(nodeName)) return;
|
1731
|
+
|
1732
|
+
keyCode === 27 && api._click(api.config.cancelVal);
|
1733
|
+
});
|
1734
|
+
|
1735
|
+
|
1736
|
+
|
1737
|
+
// 获取artDialog路径
|
1738
|
+
_path = window['_artDialog_path'] || (function (script, i, me) {
|
1739
|
+
for (i in script) {
|
1740
|
+
// 如果通过第三方脚本加载器加载本文件,请保证文件名含有"artDialog"字符
|
1741
|
+
if (script[i].src && script[i].src.indexOf('artDialog') !== -1) me = script[i];
|
1742
|
+
};
|
1743
|
+
|
1744
|
+
_thisScript = me || script[script.length - 1];
|
1745
|
+
me = _thisScript.src.replace(/\\/g, '/');
|
1746
|
+
return me.lastIndexOf('/') < 0 ? '.' : me.substring(0, me.lastIndexOf('/'));
|
1747
|
+
}(document.getElementsByTagName('script')));
|
1748
|
+
|
1749
|
+
|
1750
|
+
|
1751
|
+
// 无阻塞载入CSS (如"artDialog.js?skin=aero")
|
1752
|
+
_skin = _thisScript.src.split('skin=')[1];
|
1753
|
+
if (_skin) {
|
1754
|
+
var link = document.createElement('link');
|
1755
|
+
link.rel = 'stylesheet';
|
1756
|
+
link.href = _path + '/skins/' + _skin + '.css?' + artDialog.fn.version;
|
1757
|
+
_thisScript.parentNode.insertBefore(link, _thisScript);
|
1758
|
+
};
|
1759
|
+
|
1760
|
+
|
1761
|
+
|
1762
|
+
// 触发浏览器预先缓存背景图片
|
1763
|
+
_$window.bind('load', function () {
|
1764
|
+
setTimeout(function () {
|
1765
|
+
if (_count) return;
|
1766
|
+
artDialog({left: '-9999em',time: 9,fixed: false,lock: false,focus: false});
|
1767
|
+
}, 150);
|
1768
|
+
});
|
1769
|
+
|
1770
|
+
|
1771
|
+
|
1772
|
+
// 开启IE6 CSS背景图片缓存
|
1773
|
+
try {
|
1774
|
+
document.execCommand('BackgroundImageCache', false, true);
|
1775
|
+
} catch (e) {};
|
1776
|
+
|
1777
|
+
|
1778
|
+
|
1779
|
+
|
1780
|
+
// 使用uglifyjs压缩能够预先处理"+"号合并字符串
|
1781
|
+
// uglifyjs: http://marijnhaverbeke.nl/uglifyjs
|
1782
|
+
artDialog._templates =
|
1783
|
+
'<div class="aui_outer">'
|
1784
|
+
+ '<table class="aui_border">'
|
1785
|
+
+ '<tbody>'
|
1786
|
+
+ '<tr>'
|
1787
|
+
+ '<td class="aui_nw"></td>'
|
1788
|
+
+ '<td class="aui_n"></td>'
|
1789
|
+
+ '<td class="aui_ne"></td>'
|
1790
|
+
+ '</tr>'
|
1791
|
+
+ '<tr>'
|
1792
|
+
+ '<td class="aui_w"></td>'
|
1793
|
+
+ '<td class="aui_c">'
|
1794
|
+
+ '<div class="aui_inner">'
|
1795
|
+
+ '<table class="aui_dialog">'
|
1796
|
+
+ '<tbody>'
|
1797
|
+
+ '<tr>'
|
1798
|
+
+ '<td colspan="2" class="aui_header">'
|
1799
|
+
+ '<div class="aui_titleBar">'
|
1800
|
+
+ '<div class="aui_title"></div>'
|
1801
|
+
+ '<a class="aui_close" href="javascript:/*artDialog*/;">'
|
1802
|
+
+ '\xd7'
|
1803
|
+
+ '</a>'
|
1804
|
+
+ '</div>'
|
1805
|
+
+ '</td>'
|
1806
|
+
+ '</tr>'
|
1807
|
+
+ '<tr>'
|
1808
|
+
+ '<td class="aui_icon">'
|
1809
|
+
+ '<div class="aui_iconBg"></div>'
|
1810
|
+
+ '</td>'
|
1811
|
+
+ '<td class="aui_main">'
|
1812
|
+
+ '<div class="aui_content"></div>'
|
1813
|
+
+ '</td>'
|
1814
|
+
+ '</tr>'
|
1815
|
+
+ '<tr>'
|
1816
|
+
+ '<td colspan="2" class="aui_footer">'
|
1817
|
+
+ '<div class="aui_buttons"></div>'
|
1818
|
+
+ '</td>'
|
1819
|
+
+ '</tr>'
|
1820
|
+
+ '</tbody>'
|
1821
|
+
+ '</table>'
|
1822
|
+
+ '</div>'
|
1823
|
+
+ '</td>'
|
1824
|
+
+ '<td class="aui_e"></td>'
|
1825
|
+
+ '</tr>'
|
1826
|
+
+ '<tr>'
|
1827
|
+
+ '<td class="aui_sw"></td>'
|
1828
|
+
+ '<td class="aui_s"></td>'
|
1829
|
+
+ '<td class="aui_se"></td>'
|
1830
|
+
+ '</tr>'
|
1831
|
+
+ '</tbody>'
|
1832
|
+
+ '</table>'
|
1833
|
+
+'</div>';
|
1834
|
+
|
1835
|
+
|
1836
|
+
|
1837
|
+
/**
|
1838
|
+
* 默认配置
|
1839
|
+
*/
|
1840
|
+
artDialog.defaults = {
|
1841
|
+
// 消息内容
|
1842
|
+
content: '<div class="aui_loading"><span>loading..</span></div>',
|
1843
|
+
title: '\u6d88\u606f', // 标题. 默认'消息'
|
1844
|
+
button: null, // 自定义按钮
|
1845
|
+
ok: null, // 确定按钮回调函数
|
1846
|
+
cancel: null, // 取消按钮回调函数
|
1847
|
+
init: null, // 对话框初始化后执行的函数
|
1848
|
+
close: null, // 对话框关闭前执行的函数
|
1849
|
+
okVal: '\u786E\u5B9A', // 确定按钮文本. 默认'确定'
|
1850
|
+
cancelVal: '\u53D6\u6D88', // 取消按钮文本. 默认'取消'
|
1851
|
+
width: 'auto', // 内容宽度
|
1852
|
+
height: 'auto', // 内容高度
|
1853
|
+
minWidth: 96, // 最小宽度限制
|
1854
|
+
minHeight: 32, // 最小高度限制
|
1855
|
+
padding: '20px 25px', // 内容与边界填充距离
|
1856
|
+
skin: '', // 皮肤名(预留接口,尚未实现)
|
1857
|
+
icon: null, // 消息图标名称
|
1858
|
+
time: null, // 自动关闭时间
|
1859
|
+
esc: true, // 是否支持Esc键关闭
|
1860
|
+
focus: true, // 是否支持对话框按钮自动聚焦
|
1861
|
+
show: true, // 初始化后是否显示对话框
|
1862
|
+
follow: null, // 跟随某元素(即让对话框在元素附近弹出)
|
1863
|
+
path: _path, // artDialog路径
|
1864
|
+
lock: false, // 是否锁屏
|
1865
|
+
background: '#000', // 遮罩颜色
|
1866
|
+
opacity: .7, // 遮罩透明度
|
1867
|
+
duration: 300, // 遮罩透明度渐变动画速度
|
1868
|
+
fixed: false, // 是否静止定位
|
1869
|
+
left: '50%', // X轴坐标
|
1870
|
+
top: '38.2%', // Y轴坐标
|
1871
|
+
zIndex: 1987, // 对话框叠加高度值(重要:此值不能超过浏览器最大限制)
|
1872
|
+
resize: true, // 是否允许用户调节尺寸
|
1873
|
+
drag: true // 是否允许用户拖动位置
|
1874
|
+
|
1875
|
+
};
|
1876
|
+
|
1877
|
+
window.artDialog = $.dialog = $.artDialog = artDialog;
|
1878
|
+
}(this.art || this.jQuery && (this.art = jQuery), this));
|
1879
|
+
|
1880
|
+
|
1881
|
+
|
1882
|
+
|
1883
|
+
|
1884
|
+
|
1885
|
+
//------------------------------------------------
|
1886
|
+
// 对话框模块-拖拽支持(可选外置模块)
|
1887
|
+
//------------------------------------------------
|
1888
|
+
;(function ($) {
|
1889
|
+
|
1890
|
+
var _dragEvent, _use,
|
1891
|
+
_$window = $(window),
|
1892
|
+
_$document = $(document),
|
1893
|
+
_elem = document.documentElement,
|
1894
|
+
_isIE6 = !('minWidth' in _elem.style),
|
1895
|
+
_isLosecapture = 'onlosecapture' in _elem,
|
1896
|
+
_isSetCapture = 'setCapture' in _elem;
|
1897
|
+
|
1898
|
+
// 拖拽事件
|
1899
|
+
artDialog.dragEvent = function () {
|
1900
|
+
var that = this,
|
1901
|
+
proxy = function (name) {
|
1902
|
+
var fn = that[name];
|
1903
|
+
that[name] = function () {
|
1904
|
+
return fn.apply(that, arguments);
|
1905
|
+
};
|
1906
|
+
};
|
1907
|
+
|
1908
|
+
proxy('start');
|
1909
|
+
proxy('move');
|
1910
|
+
proxy('end');
|
1911
|
+
};
|
1912
|
+
|
1913
|
+
artDialog.dragEvent.prototype = {
|
1914
|
+
|
1915
|
+
// 开始拖拽
|
1916
|
+
onstart: $.noop,
|
1917
|
+
start: function (event) {
|
1918
|
+
_$document
|
1919
|
+
.bind('mousemove', this.move)
|
1920
|
+
.bind('mouseup', this.end);
|
1921
|
+
|
1922
|
+
this._sClientX = event.clientX;
|
1923
|
+
this._sClientY = event.clientY;
|
1924
|
+
this.onstart(event.clientX, event.clientY);
|
1925
|
+
|
1926
|
+
return false;
|
1927
|
+
},
|
1928
|
+
|
1929
|
+
// 正在拖拽
|
1930
|
+
onmove: $.noop,
|
1931
|
+
move: function (event) {
|
1932
|
+
this._mClientX = event.clientX;
|
1933
|
+
this._mClientY = event.clientY;
|
1934
|
+
this.onmove(
|
1935
|
+
event.clientX - this._sClientX,
|
1936
|
+
event.clientY - this._sClientY
|
1937
|
+
);
|
1938
|
+
|
1939
|
+
return false;
|
1940
|
+
},
|
1941
|
+
|
1942
|
+
// 结束拖拽
|
1943
|
+
onend: $.noop,
|
1944
|
+
end: function (event) {
|
1945
|
+
_$document
|
1946
|
+
.unbind('mousemove', this.move)
|
1947
|
+
.unbind('mouseup', this.end);
|
1948
|
+
|
1949
|
+
this.onend(event.clientX, event.clientY);
|
1950
|
+
return false;
|
1951
|
+
}
|
1952
|
+
|
1953
|
+
};
|
1954
|
+
|
1955
|
+
_use = function (event) {
|
1956
|
+
var limit, startWidth, startHeight, startLeft, startTop, isResize,
|
1957
|
+
api = artDialog.focus,
|
1958
|
+
//config = api.config,
|
1959
|
+
DOM = api.DOM,
|
1960
|
+
wrap = DOM.wrap,
|
1961
|
+
title = DOM.title,
|
1962
|
+
main = DOM.main;
|
1963
|
+
|
1964
|
+
// 清除文本选择
|
1965
|
+
var clsSelect = 'getSelection' in window ? function () {
|
1966
|
+
window.getSelection().removeAllRanges();
|
1967
|
+
} : function () {
|
1968
|
+
try {
|
1969
|
+
document.selection.empty();
|
1970
|
+
} catch (e) {};
|
1971
|
+
};
|
1972
|
+
|
1973
|
+
// 对话框准备拖动
|
1974
|
+
_dragEvent.onstart = function (x, y) {
|
1975
|
+
if (isResize) {
|
1976
|
+
startWidth = main[0].offsetWidth;
|
1977
|
+
startHeight = main[0].offsetHeight;
|
1978
|
+
} else {
|
1979
|
+
startLeft = wrap[0].offsetLeft;
|
1980
|
+
startTop = wrap[0].offsetTop;
|
1981
|
+
};
|
1982
|
+
|
1983
|
+
_$document.bind('dblclick', _dragEvent.end);
|
1984
|
+
!_isIE6 && _isLosecapture ?
|
1985
|
+
title.bind('losecapture', _dragEvent.end) :
|
1986
|
+
_$window.bind('blur', _dragEvent.end);
|
1987
|
+
_isSetCapture && title[0].setCapture();
|
1988
|
+
|
1989
|
+
wrap.addClass('aui_state_drag');
|
1990
|
+
api.focus();
|
1991
|
+
};
|
1992
|
+
|
1993
|
+
// 对话框拖动进行中
|
1994
|
+
_dragEvent.onmove = function (x, y) {
|
1995
|
+
if (isResize) {
|
1996
|
+
var wrapStyle = wrap[0].style,
|
1997
|
+
style = main[0].style,
|
1998
|
+
width = x + startWidth,
|
1999
|
+
height = y + startHeight;
|
2000
|
+
|
2001
|
+
wrapStyle.width = 'auto';
|
2002
|
+
style.width = Math.max(0, width) + 'px';
|
2003
|
+
wrapStyle.width = wrap[0].offsetWidth + 'px';
|
2004
|
+
|
2005
|
+
style.height = Math.max(0, height) + 'px';
|
2006
|
+
|
2007
|
+
} else {
|
2008
|
+
var style = wrap[0].style,
|
2009
|
+
left = Math.max(limit.minX, Math.min(limit.maxX, x + startLeft)),
|
2010
|
+
top = Math.max(limit.minY, Math.min(limit.maxY, y + startTop));
|
2011
|
+
|
2012
|
+
style.left = left + 'px';
|
2013
|
+
style.top = top + 'px';
|
2014
|
+
};
|
2015
|
+
|
2016
|
+
clsSelect();
|
2017
|
+
api._ie6SelectFix();
|
2018
|
+
};
|
2019
|
+
|
2020
|
+
// 对话框拖动结束
|
2021
|
+
_dragEvent.onend = function (x, y) {
|
2022
|
+
_$document.unbind('dblclick', _dragEvent.end);
|
2023
|
+
!_isIE6 && _isLosecapture ?
|
2024
|
+
title.unbind('losecapture', _dragEvent.end) :
|
2025
|
+
_$window.unbind('blur', _dragEvent.end);
|
2026
|
+
_isSetCapture && title[0].releaseCapture();
|
2027
|
+
|
2028
|
+
_isIE6 && !api.closed && api._autoPositionType();
|
2029
|
+
|
2030
|
+
wrap.removeClass('aui_state_drag');
|
2031
|
+
};
|
2032
|
+
|
2033
|
+
isResize = event.target === DOM.se[0] ? true : false;
|
2034
|
+
limit = (function () {
|
2035
|
+
var maxX, maxY,
|
2036
|
+
wrap = api.DOM.wrap[0],
|
2037
|
+
fixed = wrap.style.position === 'fixed',
|
2038
|
+
ow = wrap.offsetWidth,
|
2039
|
+
oh = wrap.offsetHeight,
|
2040
|
+
ww = _$window.width(),
|
2041
|
+
wh = _$window.height(),
|
2042
|
+
dl = fixed ? 0 : _$document.scrollLeft(),
|
2043
|
+
dt = fixed ? 0 : _$document.scrollTop(),
|
2044
|
+
|
2045
|
+
// 坐标最大值限制
|
2046
|
+
maxX = ww - ow + dl;
|
2047
|
+
maxY = wh - oh + dt;
|
2048
|
+
|
2049
|
+
return {
|
2050
|
+
minX: dl,
|
2051
|
+
minY: dt,
|
2052
|
+
maxX: maxX,
|
2053
|
+
maxY: maxY
|
2054
|
+
};
|
2055
|
+
})();
|
2056
|
+
|
2057
|
+
_dragEvent.start(event);
|
2058
|
+
};
|
2059
|
+
|
2060
|
+
// 代理 mousedown 事件触发对话框拖动
|
2061
|
+
_$document.bind('mousedown', function (event) {
|
2062
|
+
var api = artDialog.focus;
|
2063
|
+
if (!api) return;
|
2064
|
+
|
2065
|
+
var target = event.target,
|
2066
|
+
config = api.config,
|
2067
|
+
DOM = api.DOM;
|
2068
|
+
|
2069
|
+
if (config.drag !== false && target === DOM.title[0]
|
2070
|
+
|| config.resize !== false && target === DOM.se[0]) {
|
2071
|
+
_dragEvent = _dragEvent || new artDialog.dragEvent();
|
2072
|
+
_use(event);
|
2073
|
+
return false;// 防止firefox与chrome滚屏
|
2074
|
+
};
|
2075
|
+
});
|
2076
|
+
|
2077
|
+
})(this.art || this.jQuery && (this.art = jQuery));
|
2078
|
+
|