artDialog.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096
  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: 'images/' + icon + '.png'}
  774. : {backgroundImage: 'url(\'' + 'images/' + icon + '.png\')'});
  775. var artIcon='';
  776. switch(config.artIcon)
  777. {
  778. case 'add':
  779. artIcon='<i class="art-icon icon-title-add"></i>';
  780. break;
  781. case 'edit':
  782. artIcon='<i class="art-icon icon-title-edit"></i>';
  783. break;
  784. case 'ask':
  785. artIcon='<i class="art-icon icon-title-ask"></i>';
  786. break;
  787. case 'error':
  788. artIcon='<i class="art-icon icon-title-error"></i>';
  789. break;
  790. }
  791. that.closed = false;
  792. that.config = config;
  793. that.DOM = DOM = that.DOM || that._getDOM();
  794. DOM.wrap.addClass(config.skin);
  795. DOM.close[config.cancel === false ? 'hide' : 'show']();
  796. DOM.icon[0].style.display = icon ? '' : 'none';
  797. DOM.iconBg.css(iconBg || {background: 'none'});
  798. DOM.se.css('cursor', config.resize ? 'se-resize' : 'auto');
  799. DOM.title.css('cursor', config.drag ? 'move' : 'auto');
  800. DOM.content.css('padding', config.padding);
  801. that[config.show ? 'show' : 'hide'](true)
  802. that.button(config.button)
  803. .title(artIcon+config.title)
  804. .content(config.content, true)
  805. .size(config.width, config.height)
  806. .time(config.time);
  807. config.follow
  808. ? that.follow(config.follow)
  809. : that.position(config.left, config.top);
  810. that.zIndex().focus();
  811. config.lock && that.lock();
  812. that._addEvent();
  813. that._ie6PngFix();
  814. _box = null;
  815. if(config.tips){
  816. $('#aui_dialog_title').hide();
  817. }
  818. config.init && config.init.call(that, window);
  819. return that;
  820. },
  821. /**
  822. * 设置内容
  823. * @param {String, HTMLElement} 内容 (可选)
  824. * @return {this, HTMLElement} 如果无参数则返回内容容器DOM对象
  825. */
  826. content: function (msg) {
  827. var prev, next, parent, display,
  828. that = this,
  829. DOM = that.DOM,
  830. wrap = DOM.wrap[0],
  831. width = wrap.offsetWidth,
  832. height = wrap.offsetHeight,
  833. left = parseInt(wrap.style.left),
  834. top = parseInt(wrap.style.top),
  835. cssWidth = wrap.style.width,
  836. $content = DOM.content,
  837. content = $content[0];
  838. that._elemBack && that._elemBack();
  839. wrap.style.width = 'auto';
  840. if (msg === undefined) return content;
  841. if (typeof msg === 'string') {
  842. $content.html(msg);
  843. } else if (msg && msg.nodeType === 1) {
  844. // 让传入的元素在对话框关闭后可以返回到原来的地方
  845. display = msg.style.display;
  846. prev = msg.previousSibling;
  847. next = msg.nextSibling;
  848. parent = msg.parentNode;
  849. that._elemBack = function () {
  850. if (prev && prev.parentNode) {
  851. prev.parentNode.insertBefore(msg, prev.nextSibling);
  852. } else if (next && next.parentNode) {
  853. next.parentNode.insertBefore(msg, next);
  854. } else if (parent) {
  855. parent.appendChild(msg);
  856. };
  857. msg.style.display = display;
  858. that._elemBack = null;
  859. };
  860. $content.html('');
  861. content.appendChild(msg);
  862. msg.style.display = 'block';
  863. };
  864. // 新增内容后调整位置
  865. if (!arguments[1]) {
  866. if (that.config.follow) {
  867. that.follow(that.config.follow);
  868. } else {
  869. width = wrap.offsetWidth - width;
  870. height = wrap.offsetHeight - height;
  871. left = left - width / 2;
  872. top = top - height / 2;
  873. wrap.style.left = Math.max(left, 0) + 'px';
  874. wrap.style.top = Math.max(top, 0) + 'px';
  875. };
  876. if (cssWidth && cssWidth !== 'auto') {
  877. wrap.style.width = wrap.offsetWidth + 'px';
  878. };
  879. that._autoPositionType();
  880. };
  881. that._ie6SelectFix();
  882. that._runScript(content);
  883. return that;
  884. },
  885. /**
  886. * 设置标题
  887. * @param {String, Boolean} 标题内容. 为false则隐藏标题栏
  888. * @return {this, HTMLElement} 如果无参数则返回内容器DOM对象
  889. */
  890. title: function (text) {
  891. var DOM = this.DOM,
  892. wrap = DOM.wrap,
  893. title = DOM.title,
  894. className = 'aui_state_noTitle';
  895. if (text === undefined) return title[0];
  896. if (text === false) {
  897. title.hide().html('');
  898. wrap.addClass(className);
  899. } else {
  900. title.show().html(text || '');
  901. wrap.removeClass(className);
  902. };
  903. return this;
  904. },
  905. /**
  906. * 位置(相对于可视区域)
  907. * @param {Number, String}
  908. * @param {Number, String}
  909. */
  910. position: function (left, top) {
  911. var that = this,
  912. config = that.config,
  913. wrap = that.DOM.wrap[0],
  914. isFixed = _isIE6 ? false : config.fixed,
  915. ie6Fixed = _isIE6 && that.config.fixed,
  916. docLeft = _$document.scrollLeft(),
  917. docTop = _$document.scrollTop(),
  918. dl = isFixed ? 0 : docLeft,
  919. dt = isFixed ? 0 : docTop,
  920. ww = _$window.width(),
  921. wh = _$window.height(),
  922. ow = wrap.offsetWidth,
  923. oh = wrap.offsetHeight,
  924. style = wrap.style;
  925. if (left || left === 0) {
  926. that._left = left.toString().indexOf('%') !== -1 ? left : null;
  927. left = that._toNumber(left, ww - ow);
  928. if (typeof left === 'number') {
  929. left = ie6Fixed ? (left += docLeft) : left + dl;
  930. style.left = Math.max(left, dl) + 'px';
  931. } else if (typeof left === 'string') {
  932. style.left = left;
  933. };
  934. };
  935. if (top || top === 0) {
  936. that._top = top.toString().indexOf('%') !== -1 ? top : null;
  937. top = that._toNumber(top, wh - oh);
  938. if (typeof top === 'number') {
  939. top = ie6Fixed ? (top += docTop) : top + dt;
  940. style.top = Math.max(top, dt) + 'px';
  941. } else if (typeof top === 'string') {
  942. style.top = top;
  943. };
  944. };
  945. if (left !== undefined && top !== undefined) {
  946. that._follow = null;
  947. that._autoPositionType();
  948. };
  949. return that;
  950. },
  951. /**
  952. * 尺寸
  953. * @param {Number, String} 宽度
  954. * @param {Number, String} 高度
  955. */
  956. size: function (width, height) {
  957. var maxWidth, maxHeight, scaleWidth, scaleHeight,
  958. that = this,
  959. config = that.config,
  960. DOM = that.DOM,
  961. wrap = DOM.wrap,
  962. main = DOM.main,
  963. wrapStyle = wrap[0].style,
  964. style = main[0].style;
  965. if (width) {
  966. that._width = width.toString().indexOf('%') !== -1 ? width : null;
  967. maxWidth = _$window.width() - wrap[0].offsetWidth + main[0].offsetWidth;
  968. scaleWidth = that._toNumber(width, maxWidth);
  969. width = scaleWidth;
  970. if (typeof width === 'number') {
  971. wrapStyle.width = 'auto';
  972. style.width = Math.max(that.config.minWidth, width) + 'px';
  973. wrapStyle.width = wrap[0].offsetWidth + 'px'; // 防止未定义宽度的表格遇到浏览器右边边界伸缩
  974. } else if (typeof width === 'string') {
  975. style.width = width;
  976. width === 'auto' && wrap.css('width', 'auto');
  977. };
  978. };
  979. if (height) {
  980. that._height = height.toString().indexOf('%') !== -1 ? height : null;
  981. maxHeight = _$window.height() - wrap[0].offsetHeight + main[0].offsetHeight;
  982. scaleHeight = that._toNumber(height, maxHeight);
  983. height = scaleHeight;
  984. if (typeof height === 'number') {
  985. style.height = Math.max(that.config.minHeight, height) + 'px';
  986. } else if (typeof height === 'string') {
  987. style.height = height;
  988. };
  989. };
  990. that._ie6SelectFix();
  991. return that;
  992. },
  993. /**
  994. * 跟随元素
  995. * @param {HTMLElement, String}
  996. */
  997. follow: function (elem) {
  998. var $elem, that = this, config = that.config;
  999. if (typeof elem === 'string' || elem && elem.nodeType === 1) {
  1000. $elem = $(elem);
  1001. elem = $elem[0];
  1002. };
  1003. // 隐藏元素不可用
  1004. if (!elem || !elem.offsetWidth && !elem.offsetHeight) {
  1005. return that.position(that._left, that._top);
  1006. };
  1007. var expando = _expando + 'follow',
  1008. winWidth = _$window.width(),
  1009. winHeight = _$window.height(),
  1010. docLeft = _$document.scrollLeft(),
  1011. docTop = _$document.scrollTop(),
  1012. offset = $elem.offset(),
  1013. width = elem.offsetWidth,
  1014. height = elem.offsetHeight,
  1015. isFixed = _isIE6 ? false : config.fixed,
  1016. left = isFixed ? offset.left - docLeft : offset.left,
  1017. top = isFixed ? offset.top - docTop : offset.top,
  1018. wrap = that.DOM.wrap[0],
  1019. style = wrap.style,
  1020. wrapWidth = wrap.offsetWidth,
  1021. wrapHeight = wrap.offsetHeight,
  1022. setLeft = left - (wrapWidth - width) / 2,
  1023. setTop = top + height,
  1024. dl = isFixed ? 0 : docLeft,
  1025. dt = isFixed ? 0 : docTop;
  1026. setLeft = setLeft < dl ? left :
  1027. (setLeft + wrapWidth > winWidth) && (left - wrapWidth > dl)
  1028. ? left - wrapWidth + width
  1029. : setLeft;
  1030. setTop = (setTop + wrapHeight > winHeight + dt)
  1031. && (top - wrapHeight > dt)
  1032. ? top - wrapHeight
  1033. : setTop;
  1034. style.left = setLeft + 'px';
  1035. style.top = setTop + 'px';
  1036. that._follow && that._follow.removeAttribute(expando);
  1037. that._follow = elem;
  1038. elem[expando] = config.id;
  1039. that._autoPositionType();
  1040. return that;
  1041. },
  1042. /**
  1043. * 自定义按钮
  1044. * @example
  1045. button({
  1046. name: 'login',
  1047. callback: function () {},
  1048. disabled: false,
  1049. focus: true
  1050. }, .., ..)
  1051. */
  1052. button: function () {
  1053. var that = this,
  1054. ags = arguments,
  1055. DOM = that.DOM,
  1056. buttons = DOM.buttons,
  1057. elem = buttons[0],
  1058. strongButton = 'aui_state_highlight',
  1059. listeners = that._listeners = that._listeners || {},
  1060. list = $.isArray(ags[0]) ? ags[0] : [].slice.call(ags);
  1061. if (ags[0] === undefined) return elem;
  1062. $.each(list, function (i, val) {
  1063. var name = val.name,
  1064. isNewButton = !listeners[name],
  1065. button = !isNewButton ?
  1066. listeners[name].elem :
  1067. document.createElement('button');
  1068. if (!listeners[name]) listeners[name] = {};
  1069. if (val.callback) listeners[name].callback = val.callback;
  1070. if (val.className) button.className = val.className;
  1071. if (val.focus) {
  1072. that._focus && that._focus.removeClass(strongButton);
  1073. that._focus = $(button).addClass(strongButton);
  1074. that.focus();
  1075. };
  1076. // Internet Explorer 的默认类型是 "button",
  1077. // 而其他浏览器中(包括 W3C 规范)的默认值是 "submit"
  1078. // @see http://www.w3school.com.cn/tags/att_button_type.asp
  1079. button.setAttribute('type', 'button');
  1080. button[_expando + 'callback'] = name;
  1081. button.disabled = !!val.disabled;
  1082. if (isNewButton) {
  1083. button.innerHTML = name;
  1084. listeners[name].elem = button;
  1085. elem.appendChild(button);
  1086. };
  1087. });
  1088. buttons[0].style.display = list.length ? '' : 'none';
  1089. that._ie6SelectFix();
  1090. return that;
  1091. },
  1092. /** 显示对话框 */
  1093. show: function () {
  1094. this.DOM.wrap.show();
  1095. !arguments[0] && this._lockMaskWrap && this._lockMaskWrap.show();
  1096. return this;
  1097. },
  1098. /** 隐藏对话框 */
  1099. hide: function () {
  1100. this.DOM.wrap.hide();
  1101. !arguments[0] && this._lockMaskWrap && this._lockMaskWrap.hide();
  1102. return this;
  1103. },
  1104. /** 关闭对话框 */
  1105. close: function () {
  1106. if (this.closed) return this;
  1107. var that = this,
  1108. DOM = that.DOM,
  1109. wrap = DOM.wrap,
  1110. list = artDialog.list,
  1111. fn = that.config.close,
  1112. follow = that.config.follow;
  1113. that.time();
  1114. if (typeof fn === 'function' && fn.call(that, window) === false) {
  1115. return that;
  1116. };
  1117. that.unlock();
  1118. // 置空内容
  1119. that._elemBack && that._elemBack();
  1120. wrap[0].className = wrap[0].style.cssText = '';
  1121. DOM.title.html('');
  1122. DOM.content.html('');
  1123. DOM.buttons.html('');
  1124. if (artDialog.focus === that) artDialog.focus = null;
  1125. if (follow) follow.removeAttribute(_expando + 'follow');
  1126. delete list[that.config.id];
  1127. that._removeEvent();
  1128. that.hide(true)._setAbsolute();
  1129. // 清空除this.DOM之外临时对象,恢复到初始状态,以便使用单例模式
  1130. for (var i in that) {
  1131. if (that.hasOwnProperty(i) && i !== 'DOM') delete that[i];
  1132. };
  1133. // 移除HTMLElement或重用
  1134. //_box ? wrap.remove() : _box = that;
  1135. wrap.remove();
  1136. return that;
  1137. },
  1138. /**
  1139. * 定时关闭
  1140. * @param {Number} 单位为秒, 无参数则停止计时器
  1141. */
  1142. time: function (second) {
  1143. var that = this,
  1144. cancel = that.config.cancelVal,
  1145. timer = that._timer;
  1146. timer && clearTimeout(timer);
  1147. if (second) {
  1148. that._timer = setTimeout(function(){
  1149. that._click(cancel);
  1150. }, 1000 * second);
  1151. };
  1152. return that;
  1153. },
  1154. /** 设置焦点 */
  1155. focus: function () {
  1156. try {
  1157. if (this.config.focus) {
  1158. var elem = this._focus && this._focus[0] || this.DOM.close[0];
  1159. elem && elem.focus();
  1160. }
  1161. } catch (e) {}; // IE对不可见元素设置焦点会报错
  1162. return this;
  1163. },
  1164. /** 置顶对话框 */
  1165. zIndex: function () {
  1166. var that = this,
  1167. DOM = that.DOM,
  1168. wrap = DOM.wrap,
  1169. top = artDialog.focus,
  1170. index = artDialog.defaults.zIndex ++;
  1171. // 设置叠加高度
  1172. wrap.css('zIndex', index);
  1173. that._lockMask && that._lockMask.css('zIndex', index - 1);
  1174. // 设置最高层的样式
  1175. top && top.DOM.wrap.removeClass('aui_state_focus');
  1176. artDialog.focus = that;
  1177. wrap.addClass('aui_state_focus');
  1178. return that;
  1179. },
  1180. /** 设置屏锁 */
  1181. lock: function () {
  1182. if (this._lock) return this;
  1183. var that = this,
  1184. index = artDialog.defaults.zIndex - 1,
  1185. wrap = that.DOM.wrap,
  1186. config = that.config,
  1187. docWidth = _$document.width(),
  1188. docHeight = _$document.height(),
  1189. lockMaskWrap = that._lockMaskWrap || $(document.body.appendChild(document.createElement('div'))),
  1190. lockMask = that._lockMask || $(lockMaskWrap[0].appendChild(document.createElement('div'))),
  1191. domTxt = '(document).documentElement',
  1192. sizeCss = _isMobile ? 'width:' + docWidth + 'px;height:' + docHeight
  1193. + 'px' : 'width:100%;height:100%',
  1194. ie6Css = _isIE6 ?
  1195. 'position:absolute;left:expression(' + domTxt + '.scrollLeft);top:expression('
  1196. + domTxt + '.scrollTop);width:expression(' + domTxt
  1197. + '.clientWidth);height:expression(' + domTxt + '.clientHeight)'
  1198. : '';
  1199. that.zIndex();
  1200. wrap.addClass('aui_state_lock');
  1201. lockMaskWrap[0].style.cssText = sizeCss + ';position:fixed;z-index:'
  1202. + index + ';top:0;left:0;overflow:hidden;' + ie6Css;
  1203. lockMask[0].style.cssText = 'height:100%;background:' + config.background
  1204. + ';filter:alpha(opacity=0);opacity:0';
  1205. // 让IE6锁屏遮罩能够盖住下拉控件
  1206. if (_isIE6) lockMask.html(
  1207. '<iframe src="about:blank" style="width:100%;height:100%;position:absolute;' +
  1208. 'top:0;left:0;z-index:-1;filter:alpha(opacity=0)"></iframe>');
  1209. lockMask.stop();
  1210. lockMask.bind('click', function () {
  1211. that._reset();
  1212. }).bind('dblclick', function () {
  1213. return false;
  1214. //that._click(that.config.cancelVal);
  1215. });
  1216. if (config.duration === 0) {
  1217. lockMask.css({opacity: config.opacity});
  1218. } else {
  1219. lockMask.animate({opacity: config.opacity}, config.duration);
  1220. };
  1221. that._lockMaskWrap = lockMaskWrap;
  1222. that._lockMask = lockMask;
  1223. that._lock = true;
  1224. return that;
  1225. },
  1226. /** 解开屏锁 */
  1227. unlock: function () {
  1228. var that = this,
  1229. lockMaskWrap = that._lockMaskWrap,
  1230. lockMask = that._lockMask;
  1231. if (!that._lock) return that;
  1232. var style = lockMaskWrap[0].style;
  1233. var un = function () {
  1234. if (_isIE6) {
  1235. style.removeExpression('width');
  1236. style.removeExpression('height');
  1237. style.removeExpression('left');
  1238. style.removeExpression('top');
  1239. };
  1240. style.cssText = 'display:none';
  1241. _box && lockMaskWrap.remove();
  1242. };
  1243. lockMask.stop().unbind();
  1244. that.DOM.wrap.removeClass('aui_state_lock');
  1245. if (!that.config.duration) {// 取消动画,快速关闭
  1246. un();
  1247. } else {
  1248. lockMask.animate({opacity: 0}, that.config.duration, un);
  1249. };
  1250. that._lock = false;
  1251. return that;
  1252. },
  1253. // 获取元素
  1254. _getDOM: function () {
  1255. var wrap = document.createElement('div'),
  1256. body = document.body;
  1257. wrap.style.cssText = 'position:absolute;left:0;top:0';
  1258. wrap.innerHTML = artDialog._templates;
  1259. body.insertBefore(wrap, body.firstChild);
  1260. var name, i = 0,
  1261. DOM = {wrap: $(wrap)},
  1262. els = wrap.getElementsByTagName('*'),
  1263. elsLen = els.length;
  1264. for (; i < elsLen; i ++) {
  1265. name = els[i].className.split('aui_')[1];
  1266. if (name) DOM[name] = $(els[i]);
  1267. };
  1268. return DOM;
  1269. },
  1270. // px与%单位转换成数值 (百分比单位按照最大值换算)
  1271. // 其他的单位返回原值
  1272. _toNumber: function (thisValue, maxValue) {
  1273. if (!thisValue && thisValue !== 0 || typeof thisValue === 'number') {
  1274. return thisValue;
  1275. };
  1276. var last = thisValue.length - 1;
  1277. if (thisValue.lastIndexOf('px') === last) {
  1278. thisValue = parseInt(thisValue);
  1279. } else if (thisValue.lastIndexOf('%') === last) {
  1280. thisValue = parseInt(maxValue * thisValue.split('%')[0] / 100);
  1281. };
  1282. return thisValue;
  1283. },
  1284. // 让IE6 CSS支持PNG背景
  1285. _ie6PngFix: _isIE6 ? function () {
  1286. var i = 0, elem, png, pngPath, runtimeStyle,
  1287. path = artDialog.defaults.path + '/skins/',
  1288. list = this.DOM.wrap[0].getElementsByTagName('*');
  1289. for (; i < list.length; i ++) {
  1290. elem = list[i];
  1291. png = elem.currentStyle['png'];
  1292. if (png) {
  1293. pngPath = path + png;
  1294. runtimeStyle = elem.runtimeStyle;
  1295. runtimeStyle.backgroundImage = 'none';
  1296. runtimeStyle.filter = "progid:DXImageTransform.Microsoft." +
  1297. "AlphaImageLoader(src='" + pngPath + "',sizingMethod='crop')";
  1298. };
  1299. };
  1300. } : $.noop,
  1301. // 强制覆盖IE6下拉控件
  1302. _ie6SelectFix: _isIE6 ? function () {
  1303. var $wrap = this.DOM.wrap,
  1304. wrap = $wrap[0],
  1305. expando = _expando + 'iframeMask',
  1306. iframe = $wrap[expando],
  1307. width = wrap.offsetWidth,
  1308. height = wrap.offsetHeight;
  1309. width = width + 'px';
  1310. height = height + 'px';
  1311. if (iframe) {
  1312. iframe.style.width = width;
  1313. iframe.style.height = height;
  1314. } else {
  1315. iframe = wrap.appendChild(document.createElement('iframe'));
  1316. $wrap[expando] = iframe;
  1317. iframe.src = 'about:blank';
  1318. iframe.style.cssText = 'position:absolute;z-index:-1;left:0;top:0;'
  1319. + 'filter:alpha(opacity=0);width:' + width + ';height:' + height;
  1320. };
  1321. } : $.noop,
  1322. // 解析HTML片段中自定义类型脚本,其this指向artDialog内部
  1323. // <script type="text/dialog">/* [code] */</script>
  1324. _runScript: function (elem) {
  1325. var fun, i = 0, n = 0,
  1326. tags = elem.getElementsByTagName('script'),
  1327. length = tags.length,
  1328. script = [];
  1329. for (; i < length; i ++) {
  1330. if (tags[i].type === 'text/dialog') {
  1331. script[n] = tags[i].innerHTML;
  1332. n ++;
  1333. };
  1334. };
  1335. if (script.length) {
  1336. script = script.join('');
  1337. fun = new Function(script);
  1338. fun.call(this);
  1339. };
  1340. },
  1341. // 自动切换定位类型
  1342. _autoPositionType: function () {
  1343. this[this.config.fixed ? '_setFixed' : '_setAbsolute']();/////////////
  1344. },
  1345. // 设置静止定位
  1346. // IE6 Fixed @see: http://www.planeart.cn/?p=877
  1347. _setFixed: (function () {
  1348. _isIE6 && $(function () {
  1349. var bg = 'backgroundAttachment';
  1350. if (_$html.css(bg) !== 'fixed' && $('body').css(bg) !== 'fixed') {
  1351. _$html.css({
  1352. zoom: 1,// 避免偶尔出现body背景图片异常的情况
  1353. backgroundImage: 'url(about:blank)',
  1354. backgroundAttachment: 'fixed'
  1355. });
  1356. };
  1357. });
  1358. return function () {
  1359. var $elem = this.DOM.wrap,
  1360. style = $elem[0].style;
  1361. if (_isIE6) {
  1362. var left = parseInt($elem.css('left')),
  1363. top = parseInt($elem.css('top')),
  1364. sLeft = _$document.scrollLeft(),
  1365. sTop = _$document.scrollTop(),
  1366. txt = '(document.documentElement)';
  1367. this._setAbsolute();
  1368. style.setExpression('left', 'eval(' + txt + '.scrollLeft + '
  1369. + (left - sLeft) + ') + "px"');
  1370. style.setExpression('top', 'eval(' + txt + '.scrollTop + '
  1371. + (top - sTop) + ') + "px"');
  1372. } else {
  1373. style.position = 'fixed';
  1374. };
  1375. };
  1376. }()),
  1377. // 设置绝对定位
  1378. _setAbsolute: function () {
  1379. var style = this.DOM.wrap[0].style;
  1380. if (_isIE6) {
  1381. style.removeExpression('left');
  1382. style.removeExpression('top');
  1383. };
  1384. style.position = 'absolute';
  1385. },
  1386. // 按钮回调函数触发
  1387. _click: function (name) {
  1388. var that = this,
  1389. fn = that._listeners[name] && that._listeners[name].callback;
  1390. return typeof fn !== 'function' || fn.call(that, window) !== false ?
  1391. that.close() : that;
  1392. },
  1393. // 重置位置与尺寸
  1394. _reset: function (test) {
  1395. var newSize,
  1396. that = this,
  1397. oldSize = that._winSize || _$window.width() * _$window.height(),
  1398. elem = that._follow,
  1399. width = that._width,
  1400. height = that._height,
  1401. left = that._left,
  1402. top = that._top;
  1403. if (test) {
  1404. // IE6~7 window.onresize bug
  1405. newSize = that._winSize = _$window.width() * _$window.height();
  1406. if (oldSize === newSize) return;
  1407. };
  1408. if (width || height) that.size(width, height);
  1409. if (elem) {
  1410. that.follow(elem);
  1411. } else if (left || top) {
  1412. that.position(left, top);
  1413. };
  1414. },
  1415. // 事件代理
  1416. _addEvent: function () {
  1417. var resizeTimer,
  1418. that = this,
  1419. config = that.config,
  1420. isIE = 'CollectGarbage' in window,
  1421. DOM = that.DOM;
  1422. // 窗口调节事件
  1423. that._winResize = function () {
  1424. resizeTimer && clearTimeout(resizeTimer);
  1425. resizeTimer = setTimeout(function () {
  1426. that._reset(isIE);
  1427. }, 40);
  1428. };
  1429. _$window.bind('resize', that._winResize);
  1430. // 监听点击
  1431. DOM.wrap
  1432. .bind('click', function (event) {
  1433. var target = event.target, callbackID;
  1434. if (target.disabled) return false; // IE BUG
  1435. if (target === DOM.close[0]) {
  1436. that._click(config.cancelVal);
  1437. return false;
  1438. } else {
  1439. callbackID = target[_expando + 'callback'];
  1440. callbackID && that._click(callbackID);
  1441. };
  1442. that._ie6SelectFix();
  1443. })
  1444. .bind('mousedown', function () {
  1445. that.zIndex();
  1446. });
  1447. },
  1448. // 卸载事件代理
  1449. _removeEvent: function () {
  1450. var that = this,
  1451. DOM = that.DOM;
  1452. DOM.wrap.unbind();
  1453. _$window.unbind('resize', that._winResize);
  1454. }
  1455. };
  1456. artDialog.fn._init.prototype = artDialog.fn;
  1457. $.fn.dialog = $.fn.artDialog = function () {
  1458. var config = arguments;
  1459. this[this.live ? 'live' : 'bind']('click', function () {
  1460. artDialog.apply(this, config);
  1461. return false;
  1462. });
  1463. return this;
  1464. };
  1465. /** 最顶层的对话框API */
  1466. artDialog.focus = null;
  1467. /** 获取某对话框API */
  1468. artDialog.get = function (id) {
  1469. return id === undefined
  1470. ? artDialog.list
  1471. : artDialog.list[id];
  1472. };
  1473. artDialog.list = {};
  1474. // 全局快捷键
  1475. _$document.bind('keydown', function (event) {
  1476. var target = event.target,
  1477. nodeName = target.nodeName,
  1478. rinput = /^INPUT|TEXTAREA$/,
  1479. api = artDialog.focus,
  1480. keyCode = event.keyCode;
  1481. if (!api || !api.config.esc || rinput.test(nodeName)) return;
  1482. keyCode === 27 && api._click(api.config.cancelVal);
  1483. });
  1484. // 获取artDialog路径
  1485. _path = window['_artDialog_path'] || (function (script, i, me) {
  1486. for (i in script) {
  1487. // 如果通过第三方脚本加载器加载本文件,请保证文件名含有"artDialog"字符
  1488. if (script[i].src && script[i].src.indexOf('artDialog') !== -1) me = script[i];
  1489. };
  1490. _thisScript = me || script[script.length - 1];
  1491. me = _thisScript.src.replace(/\\/g, '/');
  1492. return me.lastIndexOf('/') < 0 ? '.' : me.substring(0, me.lastIndexOf('/'));
  1493. }(document.getElementsByTagName('script')));
  1494. // 无阻塞载入CSS (如"artDialog.js?skin=aero")
  1495. _skin = _thisScript.src.split('skin=')[1];
  1496. if (_skin) {
  1497. var link = document.createElement('link');
  1498. link.rel = 'stylesheet';
  1499. link.href = _path + '/skins/' + _skin + '.css?' + artDialog.fn.version;
  1500. _thisScript.parentNode.insertBefore(link, _thisScript);
  1501. };
  1502. // 触发浏览器预先缓存背景图片
  1503. _$window.bind('load', function () {
  1504. setTimeout(function () {
  1505. if (_count) return;
  1506. //artDialog({left: '-9999em',time: 0,fixed: false,lock: false,focus: false});
  1507. }, 150);
  1508. });
  1509. // 开启IE6 CSS背景图片缓存
  1510. try {
  1511. document.execCommand('BackgroundImageCache', false, true);
  1512. } catch (e) {};
  1513. // 使用uglifyjs压缩能够预先处理"+"号合并字符串
  1514. // uglifyjs: http://marijnhaverbeke.nl/uglifyjs
  1515. artDialog._templates =
  1516. '<div class="aui_outer">'
  1517. + '<table class="aui_border">'
  1518. + '<tbody>'
  1519. + '<tr>'
  1520. + '<td class="aui_nw"></td>'
  1521. + '<td class="aui_n"></td>'
  1522. + '<td class="aui_ne"></td>'
  1523. + '</tr>'
  1524. + '<tr>'
  1525. + '<td class="aui_w"></td>'
  1526. + '<td class="aui_c">'
  1527. + '<div class="aui_inner">'
  1528. + '<table class="aui_dialog">'
  1529. + '<tbody>'
  1530. + '<tr id="aui_dialog_title">'
  1531. + '<td colspan="2" class="aui_header">'
  1532. + '<div class="aui_titleBar">'
  1533. + '<div class="aui_title"></div>'
  1534. + '<a class="aui_close" href="javascript:/*artDialog*/;">'
  1535. + '\xd7'
  1536. + '</a>'
  1537. + '</div>'
  1538. + '</td>'
  1539. + '</tr>'
  1540. + '<tr>'
  1541. + '<td class="aui_icon">'
  1542. + '<div class="aui_iconBg"></div>'
  1543. + '</td>'
  1544. + '<td class="aui_main">'
  1545. + '<div class="aui_content"></div>'
  1546. + '</td>'
  1547. + '</tr>'
  1548. + '<tr>'
  1549. + '<td colspan="2" class="aui_footer">'
  1550. + '<div class="aui_buttons"></div>'
  1551. + '</td>'
  1552. + '</tr>'
  1553. + '</tbody>'
  1554. + '</table>'
  1555. + '</div>'
  1556. + '</td>'
  1557. + '<td class="aui_e"></td>'
  1558. + '</tr>'
  1559. + '<tr>'
  1560. + '<td class="aui_sw"></td>'
  1561. + '<td class="aui_s"></td>'
  1562. + '<td class="aui_se"></td>'
  1563. + '</tr>'
  1564. + '</tbody>'
  1565. + '</table>'
  1566. +'</div>';
  1567. /**
  1568. * 默认配置
  1569. */
  1570. artDialog.defaults = {
  1571. // 消息内容
  1572. content: '<div class="aui_loading"><span>loading..</span></div>',
  1573. title: '\u6d88\u606f', // 标题. 默认'消息'
  1574. button: null, // 自定义按钮
  1575. ok: null, // 确定按钮回调函数
  1576. cancel: null, // 取消按钮回调函数
  1577. init: null, // 对话框初始化后执行的函数
  1578. close: null, // 对话框关闭前执行的函数
  1579. okVal: '\u786E\u5B9A', // 确定按钮文本. 默认'确定'
  1580. cancelVal: '\u53D6\u6D88', // 取消按钮文本. 默认'取消'
  1581. width: 'auto', // 内容宽度
  1582. height: 'auto', // 内容高度
  1583. minWidth: 96, // 最小宽度限制
  1584. minHeight: 32, // 最小高度限制
  1585. padding: '20px 25px', // 内容与边界填充距离
  1586. skin: '', // 皮肤名(预留接口,尚未实现)
  1587. icon: null, // 消息图标名称
  1588. time: null, // 自动关闭时间
  1589. esc: true, // 是否支持Esc键关闭
  1590. focus: true, // 是否支持对话框按钮自动聚焦
  1591. show: true, // 初始化后是否显示对话框
  1592. follow: null, // 跟随某元素(即让对话框在元素附近弹出)
  1593. path: _path, // artDialog路径
  1594. lock: false, // 是否锁屏
  1595. background: '#000', // 遮罩颜色
  1596. opacity: .7, // 遮罩透明度
  1597. duration: 300, // 遮罩透明度渐变动画速度
  1598. fixed: false, // 是否静止定位
  1599. left: '50%', // X轴坐标
  1600. top: '38.2%', // Y轴坐标
  1601. zIndex: 1987, // 对话框叠加高度值(重要:此值不能超过浏览器最大限制)
  1602. resize: true, // 是否允许用户调节尺寸
  1603. drag: true, // 是否允许用户拖动位置
  1604. artIcon: '', //标题旁边的图标,
  1605. tips: false
  1606. };
  1607. window.artDialog = $.dialog = $.artDialog = artDialog;
  1608. }(this.art || this.jQuery && (this.art = jQuery), this));
  1609. //------------------------------------------------
  1610. // 对话框模块-拖拽支持(可选外置模块)
  1611. //------------------------------------------------
  1612. ;(function ($) {
  1613. var _dragEvent, _use,
  1614. _$window = $(window),
  1615. _$document = $(document),
  1616. _elem = document.documentElement,
  1617. _isIE6 = !('minWidth' in _elem.style),
  1618. _isLosecapture = 'onlosecapture' in _elem,
  1619. _isSetCapture = 'setCapture' in _elem;
  1620. // 拖拽事件
  1621. artDialog.dragEvent = function () {
  1622. var that = this,
  1623. proxy = function (name) {
  1624. var fn = that[name];
  1625. that[name] = function () {
  1626. return fn.apply(that, arguments);
  1627. };
  1628. };
  1629. proxy('start');
  1630. proxy('move');
  1631. proxy('end');
  1632. };
  1633. artDialog.dragEvent.prototype = {
  1634. // 开始拖拽
  1635. onstart: $.noop,
  1636. start: function (event) {
  1637. _$document
  1638. .bind('mousemove', this.move)
  1639. .bind('mouseup', this.end);
  1640. this._sClientX = event.clientX;
  1641. this._sClientY = event.clientY;
  1642. this.onstart(event.clientX, event.clientY);
  1643. return false;
  1644. },
  1645. // 正在拖拽
  1646. onmove: $.noop,
  1647. move: function (event) {
  1648. this._mClientX = event.clientX;
  1649. this._mClientY = event.clientY;
  1650. this.onmove(
  1651. event.clientX - this._sClientX,
  1652. event.clientY - this._sClientY
  1653. );
  1654. return false;
  1655. },
  1656. // 结束拖拽
  1657. onend: $.noop,
  1658. end: function (event) {
  1659. _$document
  1660. .unbind('mousemove', this.move)
  1661. .unbind('mouseup', this.end);
  1662. this.onend(event.clientX, event.clientY);
  1663. return false;
  1664. }
  1665. };
  1666. _use = function (event) {
  1667. var limit, startWidth, startHeight, startLeft, startTop, isResize,
  1668. api = artDialog.focus,
  1669. //config = api.config,
  1670. DOM = api.DOM,
  1671. wrap = DOM.wrap,
  1672. title = DOM.title,
  1673. main = DOM.main;
  1674. // 清除文本选择
  1675. var clsSelect = 'getSelection' in window ? function () {
  1676. window.getSelection().removeAllRanges();
  1677. } : function () {
  1678. try {
  1679. document.selection.empty();
  1680. } catch (e) {};
  1681. };
  1682. // 对话框准备拖动
  1683. _dragEvent.onstart = function (x, y) {
  1684. if (isResize) {
  1685. startWidth = main[0].offsetWidth;
  1686. startHeight = main[0].offsetHeight;
  1687. } else {
  1688. startLeft = wrap[0].offsetLeft;
  1689. startTop = wrap[0].offsetTop;
  1690. };
  1691. _$document.bind('dblclick', _dragEvent.end);
  1692. !_isIE6 && _isLosecapture ?
  1693. title.bind('losecapture', _dragEvent.end) :
  1694. _$window.bind('blur', _dragEvent.end);
  1695. _isSetCapture && title[0].setCapture();
  1696. wrap.addClass('aui_state_drag');
  1697. api.focus();
  1698. };
  1699. // 对话框拖动进行中
  1700. _dragEvent.onmove = function (x, y) {
  1701. if (isResize) {
  1702. var wrapStyle = wrap[0].style,
  1703. style = main[0].style,
  1704. width = x + startWidth,
  1705. height = y + startHeight;
  1706. wrapStyle.width = 'auto';
  1707. style.width = Math.max(0, width) + 'px';
  1708. wrapStyle.width = wrap[0].offsetWidth + 'px';
  1709. style.height = Math.max(0, height) + 'px';
  1710. } else {
  1711. var style = wrap[0].style,
  1712. left = Math.max(limit.minX, Math.min(limit.maxX, x + startLeft)),
  1713. top = Math.max(limit.minY, Math.min(limit.maxY, y + startTop));
  1714. style.left = left + 'px';
  1715. style.top = top + 'px';
  1716. };
  1717. clsSelect();
  1718. api._ie6SelectFix();
  1719. };
  1720. // 对话框拖动结束
  1721. _dragEvent.onend = function (x, y) {
  1722. _$document.unbind('dblclick', _dragEvent.end);
  1723. !_isIE6 && _isLosecapture ?
  1724. title.unbind('losecapture', _dragEvent.end) :
  1725. _$window.unbind('blur', _dragEvent.end);
  1726. _isSetCapture && title[0].releaseCapture();
  1727. _isIE6 && !api.closed && api._autoPositionType();
  1728. wrap.removeClass('aui_state_drag');
  1729. };
  1730. isResize = event.target === DOM.se[0] ? true : false;
  1731. limit = (function () {
  1732. var maxX, maxY,
  1733. wrap = api.DOM.wrap[0],
  1734. fixed = wrap.style.position === 'fixed',
  1735. ow = wrap.offsetWidth,
  1736. oh = wrap.offsetHeight,
  1737. ww = _$window.width(),
  1738. wh = _$window.height(),
  1739. dl = fixed ? 0 : _$document.scrollLeft(),
  1740. dt = fixed ? 0 : _$document.scrollTop(),
  1741. // 坐标最大值限制
  1742. maxX = ww - ow + dl;
  1743. maxY = wh - oh + dt;
  1744. return {
  1745. minX: dl,
  1746. minY: dt,
  1747. maxX: maxX,
  1748. maxY: maxY
  1749. };
  1750. })();
  1751. _dragEvent.start(event);
  1752. };
  1753. // 代理 mousedown 事件触发对话框拖动
  1754. _$document.bind('mousedown', function (event) {
  1755. var api = artDialog.focus;
  1756. if (!api) return;
  1757. var target = event.target,
  1758. config = api.config,
  1759. DOM = api.DOM;
  1760. if (config.drag !== false && target === DOM.title[0]
  1761. || config.resize !== false && target === DOM.se[0]) {
  1762. _dragEvent = _dragEvent || new artDialog.dragEvent();
  1763. _use(event);
  1764. return false;// 防止firefox与chrome滚屏
  1765. };
  1766. });
  1767. })(this.art || this.jQuery && (this.art = jQuery));