artDialog.js 51 KB

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