ddf6eedb09e7a8f9a230804b31b77489abd1d917.svn-base 32 KB

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