artDialog.js 51 KB

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