artdialog4 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +3 -0
  4. data/Gemfile +4 -0
  5. data/README.md +39 -0
  6. data/Rakefile +1 -0
  7. data/artdialog4.gemspec +28 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +7 -0
  10. data/lib/artdialog4/version.rb +3 -0
  11. data/lib/artdialog4.rb +6 -0
  12. data/vendor/assets/javascripts/artdialog.js +2078 -0
  13. data/vendor/assets/javascripts/jquery.artDialog.js +1261 -0
  14. data/vendor/assets/stylesheets/artdialog/aero/aero_s.png +0 -0
  15. data/vendor/assets/stylesheets/artdialog/aero/aero_s2.png +0 -0
  16. data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_close.hover.png +0 -0
  17. data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_close.png +0 -0
  18. data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_e.png +0 -0
  19. data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_n.png +0 -0
  20. data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_ne.png +0 -0
  21. data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_nw.png +0 -0
  22. data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_s.png +0 -0
  23. data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_se.png +0 -0
  24. data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_sw.png +0 -0
  25. data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_title_icon.png +0 -0
  26. data/vendor/assets/stylesheets/artdialog/aero/ie6/aui_w.png +0 -0
  27. data/vendor/assets/stylesheets/artdialog/aero.css +61 -0
  28. data/vendor/assets/stylesheets/artdialog/black/bg.png +0 -0
  29. data/vendor/assets/stylesheets/artdialog/black/bg2.png +0 -0
  30. data/vendor/assets/stylesheets/artdialog/black/bg_css3.png +0 -0
  31. data/vendor/assets/stylesheets/artdialog/black/bg_css3_2.png +0 -0
  32. data/vendor/assets/stylesheets/artdialog/black/ie6/close.hover.png +0 -0
  33. data/vendor/assets/stylesheets/artdialog/black/ie6/close.png +0 -0
  34. data/vendor/assets/stylesheets/artdialog/black/ie6/e.png +0 -0
  35. data/vendor/assets/stylesheets/artdialog/black/ie6/n.png +0 -0
  36. data/vendor/assets/stylesheets/artdialog/black/ie6/ne.png +0 -0
  37. data/vendor/assets/stylesheets/artdialog/black/ie6/nw.png +0 -0
  38. data/vendor/assets/stylesheets/artdialog/black/ie6/s.png +0 -0
  39. data/vendor/assets/stylesheets/artdialog/black/ie6/se.png +0 -0
  40. data/vendor/assets/stylesheets/artdialog/black/ie6/sw.png +0 -0
  41. data/vendor/assets/stylesheets/artdialog/black/ie6/w.png +0 -0
  42. data/vendor/assets/stylesheets/artdialog/black.css +79 -0
  43. data/vendor/assets/stylesheets/artdialog/blue/bg.png +0 -0
  44. data/vendor/assets/stylesheets/artdialog/blue/bg2.png +0 -0
  45. data/vendor/assets/stylesheets/artdialog/blue/bg_css3.png +0 -0
  46. data/vendor/assets/stylesheets/artdialog/blue/bg_css3_2.png +0 -0
  47. data/vendor/assets/stylesheets/artdialog/blue/ie6/close.hover.png +0 -0
  48. data/vendor/assets/stylesheets/artdialog/blue/ie6/close.png +0 -0
  49. data/vendor/assets/stylesheets/artdialog/blue/ie6/e.png +0 -0
  50. data/vendor/assets/stylesheets/artdialog/blue/ie6/n.png +0 -0
  51. data/vendor/assets/stylesheets/artdialog/blue/ie6/ne.png +0 -0
  52. data/vendor/assets/stylesheets/artdialog/blue/ie6/nw.png +0 -0
  53. data/vendor/assets/stylesheets/artdialog/blue/ie6/s.png +0 -0
  54. data/vendor/assets/stylesheets/artdialog/blue/ie6/se.png +0 -0
  55. data/vendor/assets/stylesheets/artdialog/blue/ie6/sw.png +0 -0
  56. data/vendor/assets/stylesheets/artdialog/blue/ie6/w.png +0 -0
  57. data/vendor/assets/stylesheets/artdialog/blue.css +79 -0
  58. data/vendor/assets/stylesheets/artdialog/chrome/border.png +0 -0
  59. data/vendor/assets/stylesheets/artdialog/chrome/chrome_s.png +0 -0
  60. data/vendor/assets/stylesheets/artdialog/chrome.css +61 -0
  61. data/vendor/assets/stylesheets/artdialog/default.css +67 -0
  62. data/vendor/assets/stylesheets/artdialog/green/bg.png +0 -0
  63. data/vendor/assets/stylesheets/artdialog/green/bg2.png +0 -0
  64. data/vendor/assets/stylesheets/artdialog/green/bg_css3.png +0 -0
  65. data/vendor/assets/stylesheets/artdialog/green/bg_css3_2.png +0 -0
  66. data/vendor/assets/stylesheets/artdialog/green/color_bg.png +0 -0
  67. data/vendor/assets/stylesheets/artdialog/green/ie6/close.hover.png +0 -0
  68. data/vendor/assets/stylesheets/artdialog/green/ie6/close.png +0 -0
  69. data/vendor/assets/stylesheets/artdialog/green/ie6/e.png +0 -0
  70. data/vendor/assets/stylesheets/artdialog/green/ie6/n.png +0 -0
  71. data/vendor/assets/stylesheets/artdialog/green/ie6/ne.png +0 -0
  72. data/vendor/assets/stylesheets/artdialog/green/ie6/nw.png +0 -0
  73. data/vendor/assets/stylesheets/artdialog/green/ie6/s.png +0 -0
  74. data/vendor/assets/stylesheets/artdialog/green/ie6/se.png +0 -0
  75. data/vendor/assets/stylesheets/artdialog/green/ie6/sw.png +0 -0
  76. data/vendor/assets/stylesheets/artdialog/green/ie6/w.png +0 -0
  77. data/vendor/assets/stylesheets/artdialog/green.css +79 -0
  78. data/vendor/assets/stylesheets/artdialog/icons/error.png +0 -0
  79. data/vendor/assets/stylesheets/artdialog/icons/face-sad.png +0 -0
  80. data/vendor/assets/stylesheets/artdialog/icons/face-smile.png +0 -0
  81. data/vendor/assets/stylesheets/artdialog/icons/loading.gif +0 -0
  82. data/vendor/assets/stylesheets/artdialog/icons/question.png +0 -0
  83. data/vendor/assets/stylesheets/artdialog/icons/succeed.png +0 -0
  84. data/vendor/assets/stylesheets/artdialog/icons/warning.png +0 -0
  85. data/vendor/assets/stylesheets/artdialog/idialog/idialog_s.png +0 -0
  86. data/vendor/assets/stylesheets/artdialog/idialog/idialog_s2.png +0 -0
  87. data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_close.hover.png +0 -0
  88. data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_close.png +0 -0
  89. data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_e.png +0 -0
  90. data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_n.png +0 -0
  91. data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_ne.png +0 -0
  92. data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_nw.png +0 -0
  93. data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_s.png +0 -0
  94. data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_se.png +0 -0
  95. data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_sw.png +0 -0
  96. data/vendor/assets/stylesheets/artdialog/idialog/ie6/aui_w.png +0 -0
  97. data/vendor/assets/stylesheets/artdialog/idialog.css +71 -0
  98. data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_close.hover.png +0 -0
  99. data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_close.png +0 -0
  100. data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_e.png +0 -0
  101. data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_n.png +0 -0
  102. data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_ne.png +0 -0
  103. data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_nw.png +0 -0
  104. data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_s.png +0 -0
  105. data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_se.png +0 -0
  106. data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_sw.png +0 -0
  107. data/vendor/assets/stylesheets/artdialog/opera/ie6/aui_w.png +0 -0
  108. data/vendor/assets/stylesheets/artdialog/opera/s1.png +0 -0
  109. data/vendor/assets/stylesheets/artdialog/opera/s2.png +0 -0
  110. data/vendor/assets/stylesheets/artdialog/opera.css +62 -0
  111. data/vendor/assets/stylesheets/artdialog/simple.css +55 -0
  112. data/vendor/assets/stylesheets/artdialog/twitter.css +59 -0
  113. data/vendor/assets/stylesheets/simple.css +55 -0
  114. metadata +184 -0
@@ -0,0 +1,1261 @@
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
+
12
+
13
+
14
+ //------------------------------------------------
15
+ // 对话框模块
16
+ //------------------------------------------------
17
+ ;(function ($, window, undefined) {
18
+
19
+ $.noop = $.noop || function () {}; // jQuery 1.3.2
20
+ var _box, _thisScript, _skin, _path,
21
+ _count = 0,
22
+ _$window = $(window),
23
+ _$document = $(document),
24
+ _$html = $('html'),
25
+ _elem = document.documentElement,
26
+ _isIE6 = window.VBArray && !window.XMLHttpRequest,
27
+ _isMobile = 'createTouch' in document && !('onmousemove' in _elem)
28
+ || /(iPhone|iPad|iPod)/i.test(navigator.userAgent),
29
+ _expando = 'artDialog' + + new Date;
30
+
31
+ var artDialog = function (config, ok, cancel) {
32
+ config = config || {};
33
+
34
+ if (typeof config === 'string' || config.nodeType === 1) {
35
+ config = {content: config, fixed: !_isMobile};
36
+ };
37
+
38
+ var api,
39
+ defaults = artDialog.defaults,
40
+ elem = config.follow = this.nodeType === 1 && this || config.follow;
41
+
42
+ // 合并默认配置
43
+ for (var i in defaults) {
44
+ if (config[i] === undefined) config[i] = defaults[i];
45
+ };
46
+
47
+ // 兼容v4.1.0之前的参数,未来版本将删除此
48
+ $.each({ok:"yesFn",cancel:"noFn",close:"closeFn",init:"initFn",okVal:"yesText",cancelVal:"noText"},
49
+ function(i,o){config[i]=config[i]!==undefined?config[i]:config[o]});
50
+
51
+ // 返回跟随模式或重复定义的ID
52
+ if (typeof elem === 'string') elem = $(elem)[0];
53
+ config.id = elem && elem[_expando + 'follow'] || config.id || _expando + _count;
54
+ api = artDialog.list[config.id];
55
+ if (elem && api) return api.follow(elem).zIndex().focus();
56
+ if (api) return api.zIndex().focus();
57
+
58
+ // 目前主流移动设备对fixed支持不好
59
+ if (_isMobile) config.fixed = false;
60
+
61
+ // 按钮队列
62
+ if (!$.isArray(config.button)) {
63
+ config.button = config.button ? [config.button] : [];
64
+ };
65
+ if (ok !== undefined) config.ok = ok;
66
+ if (cancel !== undefined) config.cancel = cancel;
67
+ config.ok && config.button.push({
68
+ name: config.okVal,
69
+ callback: config.ok,
70
+ focus: true
71
+ });
72
+ config.cancel && config.button.push({
73
+ name: config.cancelVal,
74
+ callback: config.cancel
75
+ });
76
+
77
+ // zIndex全局配置
78
+ artDialog.defaults.zIndex = config.zIndex;
79
+
80
+ _count ++;
81
+
82
+ return artDialog.list[config.id] = _box ?
83
+ _box._init(config) : new artDialog.fn._init(config);
84
+ };
85
+
86
+ artDialog.fn = artDialog.prototype = {
87
+
88
+ version: '4.1.7',
89
+
90
+ closed: true,
91
+
92
+ _init: function (config) {
93
+ var that = this, DOM,
94
+ icon = config.icon,
95
+ iconBg = icon && (_isIE6 ? {png: 'icons/' + icon + '.png'}
96
+ : {backgroundImage: 'url(\'' + config.path + '/skins/icons/' + icon + '.png\')'});
97
+
98
+ that.closed = false;
99
+ that.config = config;
100
+ that.DOM = DOM = that.DOM || that._getDOM();
101
+
102
+ DOM.wrap.addClass(config.skin);
103
+ DOM.close[config.cancel === false ? 'hide' : 'show']();
104
+ DOM.icon[0].style.display = icon ? '' : 'none';
105
+ DOM.iconBg.css(iconBg || {background: 'none'});
106
+ DOM.se.css('cursor', config.resize ? 'se-resize' : 'auto');
107
+ DOM.title.css('cursor', config.drag ? 'move' : 'auto');
108
+ DOM.content.css('padding', config.padding);
109
+
110
+ that[config.show ? 'show' : 'hide'](true)
111
+ that.button(config.button)
112
+ .title(config.title)
113
+ .content(config.content, true)
114
+ .size(config.width, config.height)
115
+ .time(config.time);
116
+
117
+ config.follow
118
+ ? that.follow(config.follow)
119
+ : that.position(config.left, config.top);
120
+
121
+ that.zIndex().focus();
122
+ config.lock && that.lock();
123
+
124
+ that._addEvent();
125
+ that._ie6PngFix();
126
+ _box = null;
127
+
128
+ config.init && config.init.call(that, window);
129
+ return that;
130
+ },
131
+
132
+ /**
133
+ * 设置内容
134
+ * @param {String, HTMLElement} 内容 (可选)
135
+ * @return {this, HTMLElement} 如果无参数则返回内容容器DOM对象
136
+ */
137
+ content: function (msg) {
138
+ var prev, next, parent, display,
139
+ that = this,
140
+ DOM = that.DOM,
141
+ wrap = DOM.wrap[0],
142
+ width = wrap.offsetWidth,
143
+ height = wrap.offsetHeight,
144
+ left = parseInt(wrap.style.left),
145
+ top = parseInt(wrap.style.top),
146
+ cssWidth = wrap.style.width,
147
+ $content = DOM.content,
148
+ content = $content[0];
149
+
150
+ that._elemBack && that._elemBack();
151
+ wrap.style.width = 'auto';
152
+
153
+ if (msg === undefined) return content;
154
+ if (typeof msg === 'string') {
155
+ $content.html(msg);
156
+ } else if (msg && msg.nodeType === 1) {
157
+
158
+ // 让传入的元素在对话框关闭后可以返回到原来的地方
159
+ display = msg.style.display;
160
+ prev = msg.previousSibling;
161
+ next = msg.nextSibling;
162
+ parent = msg.parentNode;
163
+ that._elemBack = function () {
164
+ if (prev && prev.parentNode) {
165
+ prev.parentNode.insertBefore(msg, prev.nextSibling);
166
+ } else if (next && next.parentNode) {
167
+ next.parentNode.insertBefore(msg, next);
168
+ } else if (parent) {
169
+ parent.appendChild(msg);
170
+ };
171
+ msg.style.display = display;
172
+ that._elemBack = null;
173
+ };
174
+
175
+ $content.html('');
176
+ content.appendChild(msg);
177
+ msg.style.display = 'block';
178
+
179
+ };
180
+
181
+ // 新增内容后调整位置
182
+ if (!arguments[1]) {
183
+ if (that.config.follow) {
184
+ that.follow(that.config.follow);
185
+ } else {
186
+ width = wrap.offsetWidth - width;
187
+ height = wrap.offsetHeight - height;
188
+ left = left - width / 2;
189
+ top = top - height / 2;
190
+ wrap.style.left = Math.max(left, 0) + 'px';
191
+ wrap.style.top = Math.max(top, 0) + 'px';
192
+ };
193
+ if (cssWidth && cssWidth !== 'auto') {
194
+ wrap.style.width = wrap.offsetWidth + 'px';
195
+ };
196
+ that._autoPositionType();
197
+ };
198
+
199
+ that._ie6SelectFix();
200
+ that._runScript(content);
201
+
202
+ return that;
203
+ },
204
+
205
+ /**
206
+ * 设置标题
207
+ * @param {String, Boolean} 标题内容. 为false则隐藏标题栏
208
+ * @return {this, HTMLElement} 如果无参数则返回内容器DOM对象
209
+ */
210
+ title: function (text) {
211
+ var DOM = this.DOM,
212
+ wrap = DOM.wrap,
213
+ title = DOM.title,
214
+ className = 'aui_state_noTitle';
215
+
216
+ if (text === undefined) return title[0];
217
+ if (text === false) {
218
+ title.hide().html('');
219
+ wrap.addClass(className);
220
+ } else {
221
+ title.show().html(text || '');
222
+ wrap.removeClass(className);
223
+ };
224
+
225
+ return this;
226
+ },
227
+
228
+ /**
229
+ * 位置(相对于可视区域)
230
+ * @param {Number, String}
231
+ * @param {Number, String}
232
+ */
233
+ position: function (left, top) {
234
+ var that = this,
235
+ config = that.config,
236
+ wrap = that.DOM.wrap[0],
237
+ isFixed = _isIE6 ? false : config.fixed,
238
+ ie6Fixed = _isIE6 && that.config.fixed,
239
+ docLeft = _$document.scrollLeft(),
240
+ docTop = _$document.scrollTop(),
241
+ dl = isFixed ? 0 : docLeft,
242
+ dt = isFixed ? 0 : docTop,
243
+ ww = _$window.width(),
244
+ wh = _$window.height(),
245
+ ow = wrap.offsetWidth,
246
+ oh = wrap.offsetHeight,
247
+ style = wrap.style;
248
+
249
+ if (left || left === 0) {
250
+ that._left = left.toString().indexOf('%') !== -1 ? left : null;
251
+ left = that._toNumber(left, ww - ow);
252
+
253
+ if (typeof left === 'number') {
254
+ left = ie6Fixed ? (left += docLeft) : left + dl;
255
+ style.left = Math.max(left, dl) + 'px';
256
+ } else if (typeof left === 'string') {
257
+ style.left = left;
258
+ };
259
+ };
260
+
261
+ if (top || top === 0) {
262
+ that._top = top.toString().indexOf('%') !== -1 ? top : null;
263
+ top = that._toNumber(top, wh - oh);
264
+
265
+ if (typeof top === 'number') {
266
+ top = ie6Fixed ? (top += docTop) : top + dt;
267
+ style.top = Math.max(top, dt) + 'px';
268
+ } else if (typeof top === 'string') {
269
+ style.top = top;
270
+ };
271
+ };
272
+
273
+ if (left !== undefined && top !== undefined) {
274
+ that._follow = null;
275
+ that._autoPositionType();
276
+ };
277
+
278
+ return that;
279
+ },
280
+
281
+ /**
282
+ * 尺寸
283
+ * @param {Number, String} 宽度
284
+ * @param {Number, String} 高度
285
+ */
286
+ size: function (width, height) {
287
+ var maxWidth, maxHeight, scaleWidth, scaleHeight,
288
+ that = this,
289
+ config = that.config,
290
+ DOM = that.DOM,
291
+ wrap = DOM.wrap,
292
+ main = DOM.main,
293
+ wrapStyle = wrap[0].style,
294
+ style = main[0].style;
295
+
296
+ if (width) {
297
+ that._width = width.toString().indexOf('%') !== -1 ? width : null;
298
+ maxWidth = _$window.width() - wrap[0].offsetWidth + main[0].offsetWidth;
299
+ scaleWidth = that._toNumber(width, maxWidth);
300
+ width = scaleWidth;
301
+
302
+ if (typeof width === 'number') {
303
+ wrapStyle.width = 'auto';
304
+ style.width = Math.max(that.config.minWidth, width) + 'px';
305
+ wrapStyle.width = wrap[0].offsetWidth + 'px'; // 防止未定义宽度的表格遇到浏览器右边边界伸缩
306
+ } else if (typeof width === 'string') {
307
+ style.width = width;
308
+ width === 'auto' && wrap.css('width', 'auto');
309
+ };
310
+ };
311
+
312
+ if (height) {
313
+ that._height = height.toString().indexOf('%') !== -1 ? height : null;
314
+ maxHeight = _$window.height() - wrap[0].offsetHeight + main[0].offsetHeight;
315
+ scaleHeight = that._toNumber(height, maxHeight);
316
+ height = scaleHeight;
317
+
318
+ if (typeof height === 'number') {
319
+ style.height = Math.max(that.config.minHeight, height) + 'px';
320
+ } else if (typeof height === 'string') {
321
+ style.height = height;
322
+ };
323
+ };
324
+
325
+ that._ie6SelectFix();
326
+
327
+ return that;
328
+ },
329
+
330
+ /**
331
+ * 跟随元素
332
+ * @param {HTMLElement, String}
333
+ */
334
+ follow: function (elem) {
335
+ var $elem, that = this, config = that.config;
336
+
337
+ if (typeof elem === 'string' || elem && elem.nodeType === 1) {
338
+ $elem = $(elem);
339
+ elem = $elem[0];
340
+ };
341
+
342
+ // 隐藏元素不可用
343
+ if (!elem || !elem.offsetWidth && !elem.offsetHeight) {
344
+ return that.position(that._left, that._top);
345
+ };
346
+
347
+ var expando = _expando + 'follow',
348
+ winWidth = _$window.width(),
349
+ winHeight = _$window.height(),
350
+ docLeft = _$document.scrollLeft(),
351
+ docTop = _$document.scrollTop(),
352
+ offset = $elem.offset(),
353
+ width = elem.offsetWidth,
354
+ height = elem.offsetHeight,
355
+ isFixed = _isIE6 ? false : config.fixed,
356
+ left = isFixed ? offset.left - docLeft : offset.left,
357
+ top = isFixed ? offset.top - docTop : offset.top,
358
+ wrap = that.DOM.wrap[0],
359
+ style = wrap.style,
360
+ wrapWidth = wrap.offsetWidth,
361
+ wrapHeight = wrap.offsetHeight,
362
+ setLeft = left - (wrapWidth - width) / 2,
363
+ setTop = top + height,
364
+ dl = isFixed ? 0 : docLeft,
365
+ dt = isFixed ? 0 : docTop;
366
+
367
+ setLeft = setLeft < dl ? left :
368
+ (setLeft + wrapWidth > winWidth) && (left - wrapWidth > dl)
369
+ ? left - wrapWidth + width
370
+ : setLeft;
371
+
372
+ setTop = (setTop + wrapHeight > winHeight + dt)
373
+ && (top - wrapHeight > dt)
374
+ ? top - wrapHeight
375
+ : setTop;
376
+
377
+ style.left = setLeft + 'px';
378
+ style.top = setTop + 'px';
379
+
380
+ that._follow && that._follow.removeAttribute(expando);
381
+ that._follow = elem;
382
+ elem[expando] = config.id;
383
+ that._autoPositionType();
384
+ return that;
385
+ },
386
+
387
+ /**
388
+ * 自定义按钮
389
+ * @example
390
+ button({
391
+ name: 'login',
392
+ callback: function () {},
393
+ disabled: false,
394
+ focus: true
395
+ }, .., ..)
396
+ */
397
+ button: function () {
398
+ var that = this,
399
+ ags = arguments,
400
+ DOM = that.DOM,
401
+ buttons = DOM.buttons,
402
+ elem = buttons[0],
403
+ strongButton = 'aui_state_highlight',
404
+ listeners = that._listeners = that._listeners || {},
405
+ list = $.isArray(ags[0]) ? ags[0] : [].slice.call(ags);
406
+
407
+ if (ags[0] === undefined) return elem;
408
+ $.each(list, function (i, val) {
409
+ var name = val.name,
410
+ isNewButton = !listeners[name],
411
+ button = !isNewButton ?
412
+ listeners[name].elem :
413
+ document.createElement('button');
414
+
415
+ if (!listeners[name]) listeners[name] = {};
416
+ if (val.callback) listeners[name].callback = val.callback;
417
+ if (val.className) button.className = val.className;
418
+ if (val.focus) {
419
+ that._focus && that._focus.removeClass(strongButton);
420
+ that._focus = $(button).addClass(strongButton);
421
+ that.focus();
422
+ };
423
+
424
+ // Internet Explorer 的默认类型是 "button",
425
+ // 而其他浏览器中(包括 W3C 规范)的默认值是 "submit"
426
+ // @see http://www.w3school.com.cn/tags/att_button_type.asp
427
+ button.setAttribute('type', 'button');
428
+
429
+ button[_expando + 'callback'] = name;
430
+ button.disabled = !!val.disabled;
431
+
432
+ if (isNewButton) {
433
+ button.innerHTML = name;
434
+ listeners[name].elem = button;
435
+ elem.appendChild(button);
436
+ };
437
+ });
438
+
439
+ buttons[0].style.display = list.length ? '' : 'none';
440
+
441
+ that._ie6SelectFix();
442
+ return that;
443
+ },
444
+
445
+ /** 显示对话框 */
446
+ show: function () {
447
+ this.DOM.wrap.show();
448
+ !arguments[0] && this._lockMaskWrap && this._lockMaskWrap.show();
449
+ return this;
450
+ },
451
+
452
+ /** 隐藏对话框 */
453
+ hide: function () {
454
+ this.DOM.wrap.hide();
455
+ !arguments[0] && this._lockMaskWrap && this._lockMaskWrap.hide();
456
+ return this;
457
+ },
458
+
459
+ /** 关闭对话框 */
460
+ close: function () {
461
+ if (this.closed) return this;
462
+
463
+ var that = this,
464
+ DOM = that.DOM,
465
+ wrap = DOM.wrap,
466
+ list = artDialog.list,
467
+ fn = that.config.close,
468
+ follow = that.config.follow;
469
+
470
+ that.time();
471
+ if (typeof fn === 'function' && fn.call(that, window) === false) {
472
+ return that;
473
+ };
474
+
475
+ that.unlock();
476
+
477
+ // 置空内容
478
+ that._elemBack && that._elemBack();
479
+ wrap[0].className = wrap[0].style.cssText = '';
480
+ DOM.title.html('');
481
+ DOM.content.html('');
482
+ DOM.buttons.html('');
483
+
484
+ if (artDialog.focus === that) artDialog.focus = null;
485
+ if (follow) follow.removeAttribute(_expando + 'follow');
486
+ delete list[that.config.id];
487
+ that._removeEvent();
488
+ that.hide(true)._setAbsolute();
489
+
490
+ // 清空除this.DOM之外临时对象,恢复到初始状态,以便使用单例模式
491
+ for (var i in that) {
492
+ if (that.hasOwnProperty(i) && i !== 'DOM') delete that[i];
493
+ };
494
+
495
+ // 移除HTMLElement或重用
496
+ _box ? wrap.remove() : _box = that;
497
+
498
+ return that;
499
+ },
500
+
501
+ /**
502
+ * 定时关闭
503
+ * @param {Number} 单位为秒, 无参数则停止计时器
504
+ */
505
+ time: function (second) {
506
+ var that = this,
507
+ cancel = that.config.cancelVal,
508
+ timer = that._timer;
509
+
510
+ timer && clearTimeout(timer);
511
+
512
+ if (second) {
513
+ that._timer = setTimeout(function(){
514
+ that._click(cancel);
515
+ }, 1000 * second);
516
+ };
517
+
518
+ return that;
519
+ },
520
+
521
+ /** 设置焦点 */
522
+ focus: function () {
523
+ try {
524
+ if (this.config.focus) {
525
+ var elem = this._focus && this._focus[0] || this.DOM.close[0];
526
+ elem && elem.focus();
527
+ }
528
+ } catch (e) {}; // IE对不可见元素设置焦点会报错
529
+ return this;
530
+ },
531
+
532
+ /** 置顶对话框 */
533
+ zIndex: function () {
534
+ var that = this,
535
+ DOM = that.DOM,
536
+ wrap = DOM.wrap,
537
+ top = artDialog.focus,
538
+ index = artDialog.defaults.zIndex ++;
539
+
540
+ // 设置叠加高度
541
+ wrap.css('zIndex', index);
542
+ that._lockMask && that._lockMask.css('zIndex', index - 1);
543
+
544
+ // 设置最高层的样式
545
+ top && top.DOM.wrap.removeClass('aui_state_focus');
546
+ artDialog.focus = that;
547
+ wrap.addClass('aui_state_focus');
548
+
549
+ return that;
550
+ },
551
+
552
+ /** 设置屏锁 */
553
+ lock: function () {
554
+ if (this._lock) return this;
555
+
556
+ var that = this,
557
+ index = artDialog.defaults.zIndex - 1,
558
+ wrap = that.DOM.wrap,
559
+ config = that.config,
560
+ docWidth = _$document.width(),
561
+ docHeight = _$document.height(),
562
+ lockMaskWrap = that._lockMaskWrap || $(document.body.appendChild(document.createElement('div'))),
563
+ lockMask = that._lockMask || $(lockMaskWrap[0].appendChild(document.createElement('div'))),
564
+ domTxt = '(document).documentElement',
565
+ sizeCss = _isMobile ? 'width:' + docWidth + 'px;height:' + docHeight
566
+ + 'px' : 'width:100%;height:100%',
567
+ ie6Css = _isIE6 ?
568
+ 'position:absolute;left:expression(' + domTxt + '.scrollLeft);top:expression('
569
+ + domTxt + '.scrollTop);width:expression(' + domTxt
570
+ + '.clientWidth);height:expression(' + domTxt + '.clientHeight)'
571
+ : '';
572
+
573
+ that.zIndex();
574
+ wrap.addClass('aui_state_lock');
575
+
576
+ lockMaskWrap[0].style.cssText = sizeCss + ';position:fixed;z-index:'
577
+ + index + ';top:0;left:0;overflow:hidden;' + ie6Css;
578
+ lockMask[0].style.cssText = 'height:100%;background:' + config.background
579
+ + ';filter:alpha(opacity=0);opacity:0';
580
+
581
+ // 让IE6锁屏遮罩能够盖住下拉控件
582
+ if (_isIE6) lockMask.html(
583
+ '<iframe src="about:blank" style="width:100%;height:100%;position:absolute;' +
584
+ 'top:0;left:0;z-index:-1;filter:alpha(opacity=0)"></iframe>');
585
+
586
+ lockMask.stop();
587
+ lockMask.bind('click', function () {
588
+ that._reset();
589
+ }).bind('dblclick', function () {
590
+ that._click(that.config.cancelVal);
591
+ });
592
+
593
+ if (config.duration === 0) {
594
+ lockMask.css({opacity: config.opacity});
595
+ } else {
596
+ lockMask.animate({opacity: config.opacity}, config.duration);
597
+ };
598
+
599
+ that._lockMaskWrap = lockMaskWrap;
600
+ that._lockMask = lockMask;
601
+
602
+ that._lock = true;
603
+ return that;
604
+ },
605
+
606
+ /** 解开屏锁 */
607
+ unlock: function () {
608
+ var that = this,
609
+ lockMaskWrap = that._lockMaskWrap,
610
+ lockMask = that._lockMask;
611
+
612
+ if (!that._lock) return that;
613
+ var style = lockMaskWrap[0].style;
614
+ var un = function () {
615
+ if (_isIE6) {
616
+ style.removeExpression('width');
617
+ style.removeExpression('height');
618
+ style.removeExpression('left');
619
+ style.removeExpression('top');
620
+ };
621
+ style.cssText = 'display:none';
622
+
623
+ _box && lockMaskWrap.remove();
624
+ };
625
+
626
+ lockMask.stop().unbind();
627
+ that.DOM.wrap.removeClass('aui_state_lock');
628
+ if (!that.config.duration) {// 取消动画,快速关闭
629
+ un();
630
+ } else {
631
+ lockMask.animate({opacity: 0}, that.config.duration, un);
632
+ };
633
+
634
+ that._lock = false;
635
+ return that;
636
+ },
637
+
638
+ // 获取元素
639
+ _getDOM: function () {
640
+ var wrap = document.createElement('div'),
641
+ body = document.body;
642
+ wrap.style.cssText = 'position:absolute;left:0;top:0';
643
+ wrap.innerHTML = artDialog._templates;
644
+ body.insertBefore(wrap, body.firstChild);
645
+
646
+ var name, i = 0,
647
+ DOM = {wrap: $(wrap)},
648
+ els = wrap.getElementsByTagName('*'),
649
+ elsLen = els.length;
650
+
651
+ for (; i < elsLen; i ++) {
652
+ name = els[i].className.split('aui_')[1];
653
+ if (name) DOM[name] = $(els[i]);
654
+ };
655
+
656
+ return DOM;
657
+ },
658
+
659
+ // px与%单位转换成数值 (百分比单位按照最大值换算)
660
+ // 其他的单位返回原值
661
+ _toNumber: function (thisValue, maxValue) {
662
+ if (!thisValue && thisValue !== 0 || typeof thisValue === 'number') {
663
+ return thisValue;
664
+ };
665
+
666
+ var last = thisValue.length - 1;
667
+ if (thisValue.lastIndexOf('px') === last) {
668
+ thisValue = parseInt(thisValue);
669
+ } else if (thisValue.lastIndexOf('%') === last) {
670
+ thisValue = parseInt(maxValue * thisValue.split('%')[0] / 100);
671
+ };
672
+
673
+ return thisValue;
674
+ },
675
+
676
+ // 让IE6 CSS支持PNG背景
677
+ _ie6PngFix: _isIE6 ? function () {
678
+ var i = 0, elem, png, pngPath, runtimeStyle,
679
+ path = artDialog.defaults.path + '/skins/',
680
+ list = this.DOM.wrap[0].getElementsByTagName('*');
681
+
682
+ for (; i < list.length; i ++) {
683
+ elem = list[i];
684
+ png = elem.currentStyle['png'];
685
+ if (png) {
686
+ pngPath = path + png;
687
+ runtimeStyle = elem.runtimeStyle;
688
+ runtimeStyle.backgroundImage = 'none';
689
+ runtimeStyle.filter = "progid:DXImageTransform.Microsoft." +
690
+ "AlphaImageLoader(src='" + pngPath + "',sizingMethod='crop')";
691
+ };
692
+ };
693
+ } : $.noop,
694
+
695
+ // 强制覆盖IE6下拉控件
696
+ _ie6SelectFix: _isIE6 ? function () {
697
+ var $wrap = this.DOM.wrap,
698
+ wrap = $wrap[0],
699
+ expando = _expando + 'iframeMask',
700
+ iframe = $wrap[expando],
701
+ width = wrap.offsetWidth,
702
+ height = wrap.offsetHeight;
703
+
704
+ width = width + 'px';
705
+ height = height + 'px';
706
+ if (iframe) {
707
+ iframe.style.width = width;
708
+ iframe.style.height = height;
709
+ } else {
710
+ iframe = wrap.appendChild(document.createElement('iframe'));
711
+ $wrap[expando] = iframe;
712
+ iframe.src = 'about:blank';
713
+ iframe.style.cssText = 'position:absolute;z-index:-1;left:0;top:0;'
714
+ + 'filter:alpha(opacity=0);width:' + width + ';height:' + height;
715
+ };
716
+ } : $.noop,
717
+
718
+ // 解析HTML片段中自定义类型脚本,其this指向artDialog内部
719
+ // <script type="text/dialog">/* [code] */</script>
720
+ _runScript: function (elem) {
721
+ var fun, i = 0, n = 0,
722
+ tags = elem.getElementsByTagName('script'),
723
+ length = tags.length,
724
+ script = [];
725
+
726
+ for (; i < length; i ++) {
727
+ if (tags[i].type === 'text/dialog') {
728
+ script[n] = tags[i].innerHTML;
729
+ n ++;
730
+ };
731
+ };
732
+
733
+ if (script.length) {
734
+ script = script.join('');
735
+ fun = new Function(script);
736
+ fun.call(this);
737
+ };
738
+ },
739
+
740
+ // 自动切换定位类型
741
+ _autoPositionType: function () {
742
+ this[this.config.fixed ? '_setFixed' : '_setAbsolute']();/////////////
743
+ },
744
+
745
+
746
+ // 设置静止定位
747
+ // IE6 Fixed @see: http://www.planeart.cn/?p=877
748
+ _setFixed: (function () {
749
+ _isIE6 && $(function () {
750
+ var bg = 'backgroundAttachment';
751
+ if (_$html.css(bg) !== 'fixed' && $('body').css(bg) !== 'fixed') {
752
+ _$html.css({
753
+ zoom: 1,// 避免偶尔出现body背景图片异常的情况
754
+ backgroundImage: 'url(about:blank)',
755
+ backgroundAttachment: 'fixed'
756
+ });
757
+ };
758
+ });
759
+
760
+ return function () {
761
+ var $elem = this.DOM.wrap,
762
+ style = $elem[0].style;
763
+
764
+ if (_isIE6) {
765
+ var left = parseInt($elem.css('left')),
766
+ top = parseInt($elem.css('top')),
767
+ sLeft = _$document.scrollLeft(),
768
+ sTop = _$document.scrollTop(),
769
+ txt = '(document.documentElement)';
770
+
771
+ this._setAbsolute();
772
+ style.setExpression('left', 'eval(' + txt + '.scrollLeft + '
773
+ + (left - sLeft) + ') + "px"');
774
+ style.setExpression('top', 'eval(' + txt + '.scrollTop + '
775
+ + (top - sTop) + ') + "px"');
776
+ } else {
777
+ style.position = 'fixed';
778
+ };
779
+ };
780
+ }()),
781
+
782
+ // 设置绝对定位
783
+ _setAbsolute: function () {
784
+ var style = this.DOM.wrap[0].style;
785
+
786
+ if (_isIE6) {
787
+ style.removeExpression('left');
788
+ style.removeExpression('top');
789
+ };
790
+
791
+ style.position = 'absolute';
792
+ },
793
+
794
+ // 按钮回调函数触发
795
+ _click: function (name) {
796
+ var that = this,
797
+ fn = that._listeners[name] && that._listeners[name].callback;
798
+ return typeof fn !== 'function' || fn.call(that, window) !== false ?
799
+ that.close() : that;
800
+ },
801
+
802
+ // 重置位置与尺寸
803
+ _reset: function (test) {
804
+ var newSize,
805
+ that = this,
806
+ oldSize = that._winSize || _$window.width() * _$window.height(),
807
+ elem = that._follow,
808
+ width = that._width,
809
+ height = that._height,
810
+ left = that._left,
811
+ top = that._top;
812
+
813
+ if (test) {
814
+ // IE6~7 window.onresize bug
815
+ newSize = that._winSize = _$window.width() * _$window.height();
816
+ if (oldSize === newSize) return;
817
+ };
818
+
819
+ if (width || height) that.size(width, height);
820
+
821
+ if (elem) {
822
+ that.follow(elem);
823
+ } else if (left || top) {
824
+ that.position(left, top);
825
+ };
826
+ },
827
+
828
+ // 事件代理
829
+ _addEvent: function () {
830
+ var resizeTimer,
831
+ that = this,
832
+ config = that.config,
833
+ isIE = 'CollectGarbage' in window,
834
+ DOM = that.DOM;
835
+
836
+ // 窗口调节事件
837
+ that._winResize = function () {
838
+ resizeTimer && clearTimeout(resizeTimer);
839
+ resizeTimer = setTimeout(function () {
840
+ that._reset(isIE);
841
+ }, 40);
842
+ };
843
+ _$window.bind('resize', that._winResize);
844
+
845
+ // 监听点击
846
+ DOM.wrap
847
+ .bind('click', function (event) {
848
+ var target = event.target, callbackID;
849
+
850
+ if (target.disabled) return false; // IE BUG
851
+
852
+ if (target === DOM.close[0]) {
853
+ that._click(config.cancelVal);
854
+ return false;
855
+ } else {
856
+ callbackID = target[_expando + 'callback'];
857
+ callbackID && that._click(callbackID);
858
+ };
859
+
860
+ that._ie6SelectFix();
861
+ })
862
+ .bind('mousedown', function () {
863
+ that.zIndex();
864
+ });
865
+ },
866
+
867
+ // 卸载事件代理
868
+ _removeEvent: function () {
869
+ var that = this,
870
+ DOM = that.DOM;
871
+
872
+ DOM.wrap.unbind();
873
+ _$window.unbind('resize', that._winResize);
874
+ }
875
+
876
+ };
877
+
878
+ artDialog.fn._init.prototype = artDialog.fn;
879
+ $.fn.dialog = $.fn.artDialog = function () {
880
+ var config = arguments;
881
+ this[this.live ? 'live' : 'bind']('click', function () {
882
+ artDialog.apply(this, config);
883
+ return false;
884
+ });
885
+ return this;
886
+ };
887
+
888
+
889
+
890
+ /** 最顶层的对话框API */
891
+ artDialog.focus = null;
892
+
893
+
894
+ /** 获取某对话框API */
895
+ artDialog.get = function (id) {
896
+ return id === undefined
897
+ ? artDialog.list
898
+ : artDialog.list[id];
899
+ };
900
+
901
+ artDialog.list = {};
902
+
903
+
904
+
905
+ // 全局快捷键
906
+ _$document.bind('keydown', function (event) {
907
+ var target = event.target,
908
+ nodeName = target.nodeName,
909
+ rinput = /^INPUT|TEXTAREA$/,
910
+ api = artDialog.focus,
911
+ keyCode = event.keyCode;
912
+
913
+ if (!api || !api.config.esc || rinput.test(nodeName)) return;
914
+
915
+ keyCode === 27 && api._click(api.config.cancelVal);
916
+ });
917
+
918
+
919
+
920
+ // 获取artDialog路径
921
+ _path = window['_artDialog_path'] || (function (script, i, me) {
922
+ for (i in script) {
923
+ // 如果通过第三方脚本加载器加载本文件,请保证文件名含有"artDialog"字符
924
+ if (script[i].src && script[i].src.indexOf('artDialog') !== -1) me = script[i];
925
+ };
926
+
927
+ _thisScript = me || script[script.length - 1];
928
+ me = _thisScript.src.replace(/\\/g, '/');
929
+ return me.lastIndexOf('/') < 0 ? '.' : me.substring(0, me.lastIndexOf('/'));
930
+ }(document.getElementsByTagName('script')));
931
+
932
+
933
+
934
+ // 无阻塞载入CSS (如"artDialog.js?skin=aero")
935
+ _skin = _thisScript.src.split('skin=')[1];
936
+ if (_skin) {
937
+ var link = document.createElement('link');
938
+ link.rel = 'stylesheet';
939
+ link.href = _path + '/skins/' + _skin + '.css?' + artDialog.fn.version;
940
+ _thisScript.parentNode.insertBefore(link, _thisScript);
941
+ };
942
+
943
+
944
+
945
+ // 触发浏览器预先缓存背景图片
946
+ _$window.bind('load', function () {
947
+ setTimeout(function () {
948
+ if (_count) return;
949
+ artDialog({left: '-9999em',time: 9,fixed: false,lock: false,focus: false});
950
+ }, 150);
951
+ });
952
+
953
+
954
+
955
+ // 开启IE6 CSS背景图片缓存
956
+ try {
957
+ document.execCommand('BackgroundImageCache', false, true);
958
+ } catch (e) {};
959
+
960
+
961
+
962
+
963
+ // 使用uglifyjs压缩能够预先处理"+"号合并字符串
964
+ // uglifyjs: http://marijnhaverbeke.nl/uglifyjs
965
+ artDialog._templates =
966
+ '<div class="aui_outer">'
967
+ + '<table class="aui_border">'
968
+ + '<tbody>'
969
+ + '<tr>'
970
+ + '<td class="aui_nw"></td>'
971
+ + '<td class="aui_n"></td>'
972
+ + '<td class="aui_ne"></td>'
973
+ + '</tr>'
974
+ + '<tr>'
975
+ + '<td class="aui_w"></td>'
976
+ + '<td class="aui_c">'
977
+ + '<div class="aui_inner">'
978
+ + '<table class="aui_dialog">'
979
+ + '<tbody>'
980
+ + '<tr>'
981
+ + '<td colspan="2" class="aui_header">'
982
+ + '<div class="aui_titleBar">'
983
+ + '<div class="aui_title"></div>'
984
+ + '<a class="aui_close" href="javascript:/*artDialog*/;">'
985
+ + '\xd7'
986
+ + '</a>'
987
+ + '</div>'
988
+ + '</td>'
989
+ + '</tr>'
990
+ + '<tr>'
991
+ + '<td class="aui_icon">'
992
+ + '<div class="aui_iconBg"></div>'
993
+ + '</td>'
994
+ + '<td class="aui_main">'
995
+ + '<div class="aui_content"></div>'
996
+ + '</td>'
997
+ + '</tr>'
998
+ + '<tr>'
999
+ + '<td colspan="2" class="aui_footer">'
1000
+ + '<div class="aui_buttons"></div>'
1001
+ + '</td>'
1002
+ + '</tr>'
1003
+ + '</tbody>'
1004
+ + '</table>'
1005
+ + '</div>'
1006
+ + '</td>'
1007
+ + '<td class="aui_e"></td>'
1008
+ + '</tr>'
1009
+ + '<tr>'
1010
+ + '<td class="aui_sw"></td>'
1011
+ + '<td class="aui_s"></td>'
1012
+ + '<td class="aui_se"></td>'
1013
+ + '</tr>'
1014
+ + '</tbody>'
1015
+ + '</table>'
1016
+ +'</div>';
1017
+
1018
+
1019
+
1020
+ /**
1021
+ * 默认配置
1022
+ */
1023
+ artDialog.defaults = {
1024
+ // 消息内容
1025
+ content: '<div class="aui_loading"><span>loading..</span></div>',
1026
+ title: '\u6d88\u606f', // 标题. 默认'消息'
1027
+ button: null, // 自定义按钮
1028
+ ok: null, // 确定按钮回调函数
1029
+ cancel: null, // 取消按钮回调函数
1030
+ init: null, // 对话框初始化后执行的函数
1031
+ close: null, // 对话框关闭前执行的函数
1032
+ okVal: '\u786E\u5B9A', // 确定按钮文本. 默认'确定'
1033
+ cancelVal: '\u53D6\u6D88', // 取消按钮文本. 默认'取消'
1034
+ width: 'auto', // 内容宽度
1035
+ height: 'auto', // 内容高度
1036
+ minWidth: 96, // 最小宽度限制
1037
+ minHeight: 32, // 最小高度限制
1038
+ padding: '20px 25px', // 内容与边界填充距离
1039
+ skin: '', // 皮肤名(预留接口,尚未实现)
1040
+ icon: null, // 消息图标名称
1041
+ time: null, // 自动关闭时间
1042
+ esc: true, // 是否支持Esc键关闭
1043
+ focus: true, // 是否支持对话框按钮自动聚焦
1044
+ show: true, // 初始化后是否显示对话框
1045
+ follow: null, // 跟随某元素(即让对话框在元素附近弹出)
1046
+ path: _path, // artDialog路径
1047
+ lock: false, // 是否锁屏
1048
+ background: '#000', // 遮罩颜色
1049
+ opacity: .7, // 遮罩透明度
1050
+ duration: 300, // 遮罩透明度渐变动画速度
1051
+ fixed: false, // 是否静止定位
1052
+ left: '50%', // X轴坐标
1053
+ top: '38.2%', // Y轴坐标
1054
+ zIndex: 1987, // 对话框叠加高度值(重要:此值不能超过浏览器最大限制)
1055
+ resize: true, // 是否允许用户调节尺寸
1056
+ drag: true // 是否允许用户拖动位置
1057
+
1058
+ };
1059
+
1060
+ window.artDialog = $.dialog = $.artDialog = artDialog;
1061
+ }(this.art || this.jQuery && (this.art = jQuery), this));
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+ //------------------------------------------------
1069
+ // 对话框模块-拖拽支持(可选外置模块)
1070
+ //------------------------------------------------
1071
+ ;(function ($) {
1072
+
1073
+ var _dragEvent, _use,
1074
+ _$window = $(window),
1075
+ _$document = $(document),
1076
+ _elem = document.documentElement,
1077
+ _isIE6 = !('minWidth' in _elem.style),
1078
+ _isLosecapture = 'onlosecapture' in _elem,
1079
+ _isSetCapture = 'setCapture' in _elem;
1080
+
1081
+ // 拖拽事件
1082
+ artDialog.dragEvent = function () {
1083
+ var that = this,
1084
+ proxy = function (name) {
1085
+ var fn = that[name];
1086
+ that[name] = function () {
1087
+ return fn.apply(that, arguments);
1088
+ };
1089
+ };
1090
+
1091
+ proxy('start');
1092
+ proxy('move');
1093
+ proxy('end');
1094
+ };
1095
+
1096
+ artDialog.dragEvent.prototype = {
1097
+
1098
+ // 开始拖拽
1099
+ onstart: $.noop,
1100
+ start: function (event) {
1101
+ _$document
1102
+ .bind('mousemove', this.move)
1103
+ .bind('mouseup', this.end);
1104
+
1105
+ this._sClientX = event.clientX;
1106
+ this._sClientY = event.clientY;
1107
+ this.onstart(event.clientX, event.clientY);
1108
+
1109
+ return false;
1110
+ },
1111
+
1112
+ // 正在拖拽
1113
+ onmove: $.noop,
1114
+ move: function (event) {
1115
+ this._mClientX = event.clientX;
1116
+ this._mClientY = event.clientY;
1117
+ this.onmove(
1118
+ event.clientX - this._sClientX,
1119
+ event.clientY - this._sClientY
1120
+ );
1121
+
1122
+ return false;
1123
+ },
1124
+
1125
+ // 结束拖拽
1126
+ onend: $.noop,
1127
+ end: function (event) {
1128
+ _$document
1129
+ .unbind('mousemove', this.move)
1130
+ .unbind('mouseup', this.end);
1131
+
1132
+ this.onend(event.clientX, event.clientY);
1133
+ return false;
1134
+ }
1135
+
1136
+ };
1137
+
1138
+ _use = function (event) {
1139
+ var limit, startWidth, startHeight, startLeft, startTop, isResize,
1140
+ api = artDialog.focus,
1141
+ //config = api.config,
1142
+ DOM = api.DOM,
1143
+ wrap = DOM.wrap,
1144
+ title = DOM.title,
1145
+ main = DOM.main;
1146
+
1147
+ // 清除文本选择
1148
+ var clsSelect = 'getSelection' in window ? function () {
1149
+ window.getSelection().removeAllRanges();
1150
+ } : function () {
1151
+ try {
1152
+ document.selection.empty();
1153
+ } catch (e) {};
1154
+ };
1155
+
1156
+ // 对话框准备拖动
1157
+ _dragEvent.onstart = function (x, y) {
1158
+ if (isResize) {
1159
+ startWidth = main[0].offsetWidth;
1160
+ startHeight = main[0].offsetHeight;
1161
+ } else {
1162
+ startLeft = wrap[0].offsetLeft;
1163
+ startTop = wrap[0].offsetTop;
1164
+ };
1165
+
1166
+ _$document.bind('dblclick', _dragEvent.end);
1167
+ !_isIE6 && _isLosecapture ?
1168
+ title.bind('losecapture', _dragEvent.end) :
1169
+ _$window.bind('blur', _dragEvent.end);
1170
+ _isSetCapture && title[0].setCapture();
1171
+
1172
+ wrap.addClass('aui_state_drag');
1173
+ api.focus();
1174
+ };
1175
+
1176
+ // 对话框拖动进行中
1177
+ _dragEvent.onmove = function (x, y) {
1178
+ if (isResize) {
1179
+ var wrapStyle = wrap[0].style,
1180
+ style = main[0].style,
1181
+ width = x + startWidth,
1182
+ height = y + startHeight;
1183
+
1184
+ wrapStyle.width = 'auto';
1185
+ style.width = Math.max(0, width) + 'px';
1186
+ wrapStyle.width = wrap[0].offsetWidth + 'px';
1187
+
1188
+ style.height = Math.max(0, height) + 'px';
1189
+
1190
+ } else {
1191
+ var style = wrap[0].style,
1192
+ left = Math.max(limit.minX, Math.min(limit.maxX, x + startLeft)),
1193
+ top = Math.max(limit.minY, Math.min(limit.maxY, y + startTop));
1194
+
1195
+ style.left = left + 'px';
1196
+ style.top = top + 'px';
1197
+ };
1198
+
1199
+ clsSelect();
1200
+ api._ie6SelectFix();
1201
+ };
1202
+
1203
+ // 对话框拖动结束
1204
+ _dragEvent.onend = function (x, y) {
1205
+ _$document.unbind('dblclick', _dragEvent.end);
1206
+ !_isIE6 && _isLosecapture ?
1207
+ title.unbind('losecapture', _dragEvent.end) :
1208
+ _$window.unbind('blur', _dragEvent.end);
1209
+ _isSetCapture && title[0].releaseCapture();
1210
+
1211
+ _isIE6 && !api.closed && api._autoPositionType();
1212
+
1213
+ wrap.removeClass('aui_state_drag');
1214
+ };
1215
+
1216
+ isResize = event.target === DOM.se[0] ? true : false;
1217
+ limit = (function () {
1218
+ var maxX, maxY,
1219
+ wrap = api.DOM.wrap[0],
1220
+ fixed = wrap.style.position === 'fixed',
1221
+ ow = wrap.offsetWidth,
1222
+ oh = wrap.offsetHeight,
1223
+ ww = _$window.width(),
1224
+ wh = _$window.height(),
1225
+ dl = fixed ? 0 : _$document.scrollLeft(),
1226
+ dt = fixed ? 0 : _$document.scrollTop(),
1227
+
1228
+ // 坐标最大值限制
1229
+ maxX = ww - ow + dl;
1230
+ maxY = wh - oh + dt;
1231
+
1232
+ return {
1233
+ minX: dl,
1234
+ minY: dt,
1235
+ maxX: maxX,
1236
+ maxY: maxY
1237
+ };
1238
+ })();
1239
+
1240
+ _dragEvent.start(event);
1241
+ };
1242
+
1243
+ // 代理 mousedown 事件触发对话框拖动
1244
+ _$document.bind('mousedown', function (event) {
1245
+ var api = artDialog.focus;
1246
+ if (!api) return;
1247
+
1248
+ var target = event.target,
1249
+ config = api.config,
1250
+ DOM = api.DOM;
1251
+
1252
+ if (config.drag !== false && target === DOM.title[0]
1253
+ || config.resize !== false && target === DOM.se[0]) {
1254
+ _dragEvent = _dragEvent || new artDialog.dragEvent();
1255
+ _use(event);
1256
+ return false;// 防止firefox与chrome滚屏
1257
+ };
1258
+ });
1259
+
1260
+ })(this.art || this.jQuery && (this.art = jQuery));
1261
+