dialog-plus.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. !function() {
  2. var __modules__ = {};
  3. function require(id) {
  4. var mod = __modules__[id];
  5. var exports = "exports";
  6. if (typeof mod === "object") {
  7. return mod;
  8. }
  9. if (!mod[exports]) {
  10. mod[exports] = {};
  11. mod[exports] = mod.call(mod[exports], require, mod[exports], mod) || mod[exports];
  12. }
  13. return mod[exports];
  14. }
  15. function define(path, fn) {
  16. __modules__[path] = fn;
  17. }
  18. define("jquery", function() {
  19. return jQuery;
  20. });
  21. define("popup", function(require) {
  22. var $ = require("jquery");
  23. var _count = 0;
  24. var _isIE6 = !("minWidth" in $("html")[0].style);
  25. var _isFixed = !_isIE6;
  26. function Popup() {
  27. this.destroyed = false;
  28. this.__popup = $("<div />").css({
  29. display:"none",
  30. position:"absolute",
  31. outline:0
  32. }).attr("tabindex", "-1").html(this.innerHTML).appendTo("body");
  33. this.__backdrop = this.__mask = $("<div />").css({
  34. opacity:.7,
  35. background:"#000"
  36. });
  37. this.node = this.__popup[0];
  38. this.backdrop = this.__backdrop[0];
  39. _count++;
  40. }
  41. $.extend(Popup.prototype, {
  42. node:null,
  43. backdrop:null,
  44. fixed:true,
  45. destroyed:true,
  46. open:false,
  47. returnValue:"",
  48. autofocus:true,
  49. align:"bottom left",
  50. innerHTML:"",
  51. className:"ui-popup",
  52. show:function(anchor) {
  53. if (this.destroyed) {
  54. return this;
  55. }
  56. var that = this;
  57. var popup = this.__popup;
  58. var backdrop = this.__backdrop;
  59. this.__activeElement = this.__getActive();
  60. this.open = true;
  61. this.follow = anchor || this.follow;
  62. if (!this.__ready) {
  63. popup.addClass(this.className).attr("role", this.modal ? "alertdialog" :"dialog").css("position", this.fixed ? "fixed" :"absolute");
  64. if (!_isIE6) {
  65. $(window).on("resize", $.proxy(this.reset, this));
  66. }
  67. if (this.modal) {
  68. var backdropCss = {
  69. position:"fixed",
  70. left:0,
  71. top:0,
  72. width:"100%",
  73. height:"100%",
  74. overflow:"hidden",
  75. userSelect:"none",
  76. zIndex:this.zIndex || Popup.zIndex
  77. };
  78. popup.addClass(this.className + "-modal");
  79. if (!_isFixed) {
  80. $.extend(backdropCss, {
  81. position:"absolute",
  82. width:$(window).width() + "px",
  83. height:$(document).height() + "px"
  84. });
  85. }
  86. backdrop.css(backdropCss).attr({
  87. tabindex:"0"
  88. }).on("focus", $.proxy(this.focus, this));
  89. this.__mask = backdrop.clone(true).attr("style", "").insertAfter(popup);
  90. backdrop.addClass(this.className + "-backdrop").insertBefore(popup);
  91. this.__ready = true;
  92. }
  93. if (!popup.html()) {
  94. popup.html(this.innerHTML);
  95. }
  96. }
  97. popup.addClass(this.className + "-show").show();
  98. backdrop.show();
  99. this.reset().focus();
  100. this.__dispatchEvent("show");
  101. return this;
  102. },
  103. showModal:function() {
  104. this.modal = true;
  105. return this.show.apply(this, arguments);
  106. },
  107. close:function(result) {
  108. if (!this.destroyed && this.open) {
  109. if (result !== undefined) {
  110. this.returnValue = result;
  111. }
  112. this.__popup.hide().removeClass(this.className + "-show");
  113. this.__backdrop.hide();
  114. this.open = false;
  115. this.blur();
  116. this.__dispatchEvent("close");
  117. }
  118. return this;
  119. },
  120. remove:function() {
  121. if (this.destroyed) {
  122. return this;
  123. }
  124. this.__dispatchEvent("beforeremove");
  125. if (Popup.current === this) {
  126. Popup.current = null;
  127. }
  128. this.__popup.remove();
  129. this.__backdrop.remove();
  130. this.__mask.remove();
  131. if (!_isIE6) {
  132. $(window).off("resize", this.reset);
  133. }
  134. this.__dispatchEvent("remove");
  135. for (var i in this) {
  136. delete this[i];
  137. }
  138. return this;
  139. },
  140. reset:function() {
  141. var elem = this.follow;
  142. var bottom = this.options.bottom;
  143. if (elem) {
  144. this.__follow(elem);
  145. } else if (bottom) {
  146. this.__bottom();
  147. } else {
  148. this.__center();
  149. }
  150. this.__dispatchEvent("reset");
  151. return this;
  152. },
  153. focus:function() {
  154. var node = this.node;
  155. var popup = this.__popup;
  156. var current = Popup.current;
  157. var index = this.zIndex = Popup.zIndex++;
  158. if (current && current !== this) {
  159. current.blur(false);
  160. }
  161. if (!$.contains(node, this.__getActive())) {
  162. var autofocus = popup.find("[autofocus]")[0];
  163. if (!this._autofocus && autofocus) {
  164. this._autofocus = true;
  165. } else {
  166. autofocus = node;
  167. }
  168. this.__focus(autofocus);
  169. }
  170. popup.css("zIndex", index);
  171. Popup.current = this;
  172. popup.addClass(this.className + "-focus");
  173. this.__dispatchEvent("focus");
  174. return this;
  175. },
  176. blur:function() {
  177. var activeElement = this.__activeElement;
  178. var isBlur = arguments[0];
  179. if (isBlur !== false) {
  180. this.__focus(activeElement);
  181. }
  182. this._autofocus = false;
  183. this.__popup.removeClass(this.className + "-focus");
  184. this.__dispatchEvent("blur");
  185. return this;
  186. },
  187. addEventListener:function(type, callback) {
  188. this.__getEventListener(type).push(callback);
  189. return this;
  190. },
  191. removeEventListener:function(type, callback) {
  192. var listeners = this.__getEventListener(type);
  193. for (var i = 0; i < listeners.length; i++) {
  194. if (callback === listeners[i]) {
  195. listeners.splice(i--, 1);
  196. }
  197. }
  198. return this;
  199. },
  200. __getEventListener:function(type) {
  201. var listener = this.__listener;
  202. if (!listener) {
  203. listener = this.__listener = {};
  204. }
  205. if (!listener[type]) {
  206. listener[type] = [];
  207. }
  208. return listener[type];
  209. },
  210. __dispatchEvent:function(type) {
  211. var listeners = this.__getEventListener(type);
  212. if (this["on" + type]) {
  213. this["on" + type]();
  214. }
  215. for (var i = 0; i < listeners.length; i++) {
  216. listeners[i].call(this);
  217. }
  218. },
  219. __focus:function(elem) {
  220. try {
  221. if (this.autofocus && !/^iframe$/i.test(elem.nodeName)) {
  222. elem.focus();
  223. }
  224. } catch (e) {}
  225. },
  226. __getActive:function() {
  227. try {
  228. var activeElement = document.activeElement;
  229. var contentDocument = activeElement.contentDocument;
  230. var elem = contentDocument && contentDocument.activeElement || activeElement;
  231. return elem;
  232. } catch (e) {}
  233. },
  234. __center:function() {
  235. var popup = this.__popup;
  236. var $window = $(window);
  237. var $document = $(document);
  238. var fixed = this.fixed;
  239. var dl = fixed ? 0 :$document.scrollLeft();
  240. var dt = fixed ? 0 :$document.scrollTop();
  241. var ww = $window.width();
  242. var wh = $window.height();
  243. var ow = popup.width();
  244. var oh = popup.height();
  245. var left = (ww - ow) / 2 + dl;
  246. var top = (wh - oh) * 382 / 1e3 + dt;
  247. var style = popup[0].style;
  248. style.left = Math.max(parseInt(left), dl) + "px";
  249. style.top = Math.max(parseInt(top), dt) + "px";
  250. if (this.__browser.versions.ios) {
  251. style.top = "50%";
  252. style.position = "fixed";
  253. style.marginTop = "-" + popup.height() / 2 + "px";
  254. }
  255. },
  256. __bottom:function() {
  257. var popup = this.__popup;
  258. var $window = $(window);
  259. var $document = $(document);
  260. var fixed = this.fixed;
  261. var dl = fixed ? 0 :$document.scrollLeft();
  262. var dt = fixed ? 0 :$document.scrollTop();
  263. var ww = $window.width();
  264. var wh = $window.height();
  265. var ow = popup.width();
  266. var oh = popup.height();
  267. var left = (ww - ow) / 2 + dl;
  268. var top = (wh - oh) * 382 / 1e3 + dt;
  269. var style = popup[0].style;
  270. style.left = Math.max(parseInt(left), dl) + "px";
  271. style.bottom = "50px";
  272. if (this.__browser.versions.ios) {
  273. style.bottom = "50px";
  274. style.position = "fixed";
  275. style.marginTop = "-" + popup.height() / 2 + "px";
  276. }
  277. },
  278. __browser:{
  279. versions:function() {
  280. var u = navigator.userAgent, app = navigator.appVersion;
  281. return {
  282. trident:u.indexOf("Trident") > -1,
  283. presto:u.indexOf("Presto") > -1,
  284. webKit:u.indexOf("AppleWebKit") > -1,
  285. gecko:u.indexOf("Gecko") > -1 && u.indexOf("KHTML") == -1,
  286. mobile:!!u.match(/AppleWebKit.*Mobile.*/),
  287. ios:!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
  288. android:u.indexOf("Android") > -1 || u.indexOf("Linux") > -1,
  289. iPhone:u.indexOf("iPhone") > -1,
  290. iPad:u.indexOf("iPad") > -1,
  291. webApp:u.indexOf("Safari") == -1
  292. };
  293. }(),
  294. language:(navigator.browserLanguage || navigator.language).toLowerCase()
  295. },
  296. __follow:function(anchor) {
  297. var $elem = anchor.parentNode && $(anchor);
  298. var popup = this.__popup;
  299. if (this.__followSkin) {
  300. popup.removeClass(this.__followSkin);
  301. }
  302. if ($elem) {
  303. var o = $elem.offset();
  304. if (o.left * o.top < 0) {
  305. return this.__center();
  306. }
  307. }
  308. var that = this;
  309. var fixed = this.fixed;
  310. var $window = $(window);
  311. var $document = $(document);
  312. var winWidth = $window.width();
  313. var winHeight = $window.height();
  314. var docLeft = $document.scrollLeft();
  315. var docTop = $document.scrollTop();
  316. var popupWidth = popup.width();
  317. var popupHeight = popup.height();
  318. var width = $elem ? $elem.outerWidth() :0;
  319. var height = $elem ? $elem.outerHeight() :0;
  320. var offset = this.__offset(anchor);
  321. var x = offset.left;
  322. var y = offset.top;
  323. var left = fixed ? x - docLeft :x;
  324. var top = fixed ? y - docTop :y;
  325. var minLeft = fixed ? 0 :docLeft;
  326. var minTop = fixed ? 0 :docTop;
  327. var maxLeft = minLeft + winWidth - popupWidth;
  328. var maxTop = minTop + winHeight - popupHeight;
  329. var css = {};
  330. var align = this.align.split(" ");
  331. var className = this.className + "-";
  332. var reverse = {
  333. top:"bottom",
  334. bottom:"top",
  335. left:"right",
  336. right:"left"
  337. };
  338. var name = {
  339. top:"top",
  340. bottom:"top",
  341. left:"left",
  342. right:"left"
  343. };
  344. var temp = [ {
  345. top:top - popupHeight,
  346. bottom:top + height,
  347. left:left - popupWidth,
  348. right:left + width
  349. }, {
  350. top:top,
  351. bottom:top - popupHeight + height,
  352. left:left,
  353. right:left - popupWidth + width
  354. } ];
  355. var center = {
  356. left:left + width / 2 - popupWidth / 2,
  357. top:top + height / 2 - popupHeight / 2
  358. };
  359. var range = {
  360. left:[ minLeft, maxLeft ],
  361. top:[ minTop, maxTop ]
  362. };
  363. $.each(align, function(i, val) {
  364. if (temp[i][val] > range[name[val]][1]) {
  365. val = align[i] = reverse[val];
  366. }
  367. if (temp[i][val] < range[name[val]][0]) {
  368. align[i] = reverse[val];
  369. }
  370. });
  371. if (!align[1]) {
  372. name[align[1]] = name[align[0]] === "left" ? "top" :"left";
  373. temp[1][align[1]] = center[name[align[1]]];
  374. }
  375. className += align.join("-") + " " + this.className + "-follow";
  376. that.__followSkin = className;
  377. if ($elem) {
  378. popup.addClass(className);
  379. }
  380. css[name[align[0]]] = parseInt(temp[0][align[0]]);
  381. css[name[align[1]]] = parseInt(temp[1][align[1]]);
  382. popup.css(css);
  383. },
  384. __offset:function(anchor) {
  385. var isNode = anchor.parentNode;
  386. var offset = isNode ? $(anchor).offset() :{
  387. left:anchor.pageX,
  388. top:anchor.pageY
  389. };
  390. anchor = isNode ? anchor :anchor.target;
  391. var ownerDocument = anchor.ownerDocument;
  392. var defaultView = ownerDocument.defaultView || ownerDocument.parentWindow;
  393. if (defaultView == window) {
  394. return offset;
  395. }
  396. var frameElement = defaultView.frameElement;
  397. var $ownerDocument = $(ownerDocument);
  398. var docLeft = $ownerDocument.scrollLeft();
  399. var docTop = $ownerDocument.scrollTop();
  400. var frameOffset = $(frameElement).offset();
  401. var frameLeft = frameOffset.left;
  402. var frameTop = frameOffset.top;
  403. return {
  404. left:offset.left + frameLeft - docLeft,
  405. top:offset.top + frameTop - docTop
  406. };
  407. }
  408. });
  409. Popup.zIndex = 1024;
  410. Popup.current = null;
  411. return Popup;
  412. });
  413. define("dialog-config", {
  414. fixed:true,
  415. zIndex:3e3,
  416. backdropBackground:"#000",
  417. backdropOpacity:.7,
  418. content:"",
  419. contentType:"",
  420. closeTime:3e3,
  421. title:"",
  422. statusbar:"",
  423. button:null,
  424. ok:null,
  425. cancel:null,
  426. okValue:"确定",
  427. cancelValue:"取消",
  428. cancelDisplay:true,
  429. width:"",
  430. height:"",
  431. padding:"",
  432. titlePadding:"",
  433. contentBlock:false,
  434. skin:"ax-popup",
  435. boxSkin:"ui-popup-full fat-title",
  436. quickClose:false,
  437. cssUri:"",
  438. innerHTML:'<div i="dialog" class="ui-dialog">' + '<div class="ui-dialog-arrow-a"></div>' + '<div class="ui-dialog-arrow-b"></div>' + '<table class="ui-dialog-grid">' + "<tr>" + '<td i="header" class="ui-dialog-header">' + '<button i="close" class="ui-dialog-close">&#215;</button>' + '<div i="title" class="ui-dialog-title"></div>' + "</td>" + "</tr>" + "<tr>" + '<td i="body" class="ui-dialog-body">' + '<div i="content" class="ui-dialog-content"></div>' + "</td>" + "</tr>" + "<tr>" + '<td i="footer" class="ui-dialog-footer">' + '<div i="statusbar" class="ui-dialog-statusbar"></div>' + '<div i="button" class="ui-dialog-button"></div>' + "</td>" + "</tr>" + "</table>" + "</div>"
  439. });
  440. define("dialog", function(require) {
  441. var $ = require("jquery");
  442. var Popup = require("popup");
  443. var defaults = require("dialog-config");
  444. var css = defaults.cssUri;
  445. if (css) {
  446. var fn = require[require.toUrl ? "toUrl" :"resolve"];
  447. if (fn) {
  448. css = fn(css);
  449. css = '<link rel="stylesheet" href="' + css + '" />';
  450. if ($("base")[0]) {
  451. $("base").before(css);
  452. } else {
  453. $("head").append(css);
  454. }
  455. }
  456. }
  457. var _count = 0;
  458. var _expando = new Date() - 0;
  459. var _isIE6 = !("minWidth" in $("html")[0].style);
  460. var _isMobile = "createTouch" in document && !("onmousemove" in document) || /(iPhone|iPad|iPod)/i.test(navigator.userAgent);
  461. var _isFixed = !_isIE6 && !_isMobile;
  462. var artDialog = function(options, ok, cancel) {
  463. var originalOptions = options = options || {};
  464. if (typeof options === "string" || options.nodeType === 1) {
  465. options = {
  466. content:options,
  467. fixed:!_isMobile
  468. };
  469. }
  470. options = $.extend(true, {}, artDialog.defaults, options);
  471. options.original = originalOptions;
  472. var id = options.id = options.id || _expando + _count;
  473. var api = artDialog.get(id);
  474. if (api) {
  475. return api.focus();
  476. }
  477. if (!_isFixed) {
  478. options.fixed = false;
  479. }
  480. if (options.quickClose) {
  481. options.modal = true;
  482. options.backdropOpacity = .7;
  483. }
  484. if (!$.isArray(options.button)) {
  485. options.button = [];
  486. }
  487. if (cancel !== undefined) {
  488. options.cancel = cancel;
  489. }
  490. if (options.cancel) {
  491. options.button.push({
  492. id:"cancel",
  493. value:options.cancelValue,
  494. callback:options.cancel,
  495. display:options.cancelDisplay
  496. });
  497. }
  498. if (ok !== undefined) {
  499. options.ok = ok;
  500. }
  501. if (options.ok) {
  502. options.button.push({
  503. id:"ok",
  504. value:options.okValue,
  505. callback:options.ok,
  506. autofocus:true
  507. });
  508. }
  509. return artDialog.list[id] = new artDialog.create(options);
  510. };
  511. var popup = function() {};
  512. popup.prototype = Popup.prototype;
  513. var prototype = artDialog.prototype = new popup();
  514. artDialog.create = function(options) {
  515. var that = this;
  516. $.extend(this, new Popup());
  517. var originalOptions = options.original;
  518. var $popup = $(this.node).html(options.innerHTML);
  519. var $backdrop = $(this.backdrop);
  520. this.options = options;
  521. this._popup = $popup;
  522. $.each(options, function(name, value) {
  523. if (typeof that[name] === "function") {
  524. that[name](value);
  525. } else {
  526. that[name] = value;
  527. }
  528. });
  529. if (options.zIndex) {
  530. Popup.zIndex = options.zIndex;
  531. }
  532. $popup.attr({
  533. "aria-labelledby":this._$("title").attr("id", "title:" + this.id).attr("id"),
  534. "aria-describedby":this._$("content").attr("id", "content:" + this.id).attr("id")
  535. });
  536. this._$("close").css("display", this.cancel === false ? "none" :"").attr("title", this.cancelValue).on("click", function(event) {
  537. that._trigger("cancel");
  538. event.preventDefault();
  539. });
  540. if (this.contentType != "") {
  541. this.boxSkin = "";
  542. if (this.skin == "bk-popup") {
  543. this.skin = "bk-popup smallTips";
  544. } else {
  545. this.skin = "smallTips";
  546. }
  547. }
  548. this._$("dialog").addClass(this.skin);
  549. $popup.addClass(this.boxSkin);
  550. this._$("body").css("padding", this.padding);
  551. this._$("title").css("padding", this.titlePadding);
  552. if (this.contentBlock) {
  553. this._$("content").css("display", "block");
  554. }
  555. if (options.quickClose) {
  556. $backdrop.on("onmousedown" in document ? "mousedown" :"click", function() {
  557. that._trigger("cancel");
  558. return false;
  559. });
  560. }
  561. this.addEventListener("show", function() {
  562. $backdrop.css({
  563. opacity:options.backdropOpacity,
  564. background:options.backdropBackground
  565. });
  566. });
  567. this._esc = function(event) {
  568. var target = event.target;
  569. var nodeName = target.nodeName;
  570. var rinput = /^input|textarea$/i;
  571. var isTop = Popup.current === that;
  572. var keyCode = event.keyCode;
  573. if (!isTop || rinput.test(nodeName) && target.type !== "button") {
  574. return;
  575. }
  576. if (keyCode === 27) {
  577. that._trigger("cancel");
  578. }
  579. };
  580. $(document).on("keydown", this._esc);
  581. this.addEventListener("remove", function() {
  582. $(document).off("keydown", this._esc);
  583. delete artDialog.list[this.id];
  584. });
  585. _count++;
  586. artDialog.oncreate(this);
  587. return this;
  588. };
  589. artDialog.create.prototype = prototype;
  590. $.extend(prototype, {
  591. content:function(html) {
  592. var $content = this._$("content");
  593. if (typeof html === "object") {
  594. html = $(html);
  595. $content.empty("").append(html.show());
  596. this.addEventListener("beforeremove", function() {
  597. $("body").append(html.hide());
  598. });
  599. } else {
  600. if (this.options.contentType != "") {
  601. switch (this.options.contentType) {
  602. case "load":
  603. if (this.options.content == "") {
  604. html = '<span class="ui-dialog-loading"></span><p style="float:left;">加载中,请稍候...</p>';
  605. } else {
  606. html = '<span class="ui-dialog-loading"></span><p style="float:left;">' + this.options.content + "</p>";
  607. }
  608. break;
  609. case "jsonload":
  610. if (this.options.content == "") {
  611. html = '<span class="ui-dialog-loading"></span><p style="float:left;">数据载入中,请稍候...</p>';
  612. } else {
  613. html = '<span class="ui-dialog-loading"></span><p style="float:left;">' + this.options.content + "</p>";
  614. }
  615. break;
  616. case "tipsbox":
  617. var th = this;
  618. if (this.options.closeTime != 0) {
  619. setTimeout(function() {
  620. artDialog.list[th.id].close().remove();
  621. }, this.options.closeTime);
  622. }
  623. break;
  624. }
  625. }
  626. $content.html(html);
  627. }
  628. return this.reset();
  629. },
  630. title:function(text) {
  631. this._$("title").html(text);
  632. this._$("header")[text ? "show" :"hide"]();
  633. return this;
  634. },
  635. width:function(value) {
  636. this._$("content").css("width", value);
  637. return this.reset();
  638. },
  639. height:function(value) {
  640. this._$("content").css("height", value);
  641. return this.reset();
  642. },
  643. button:function(args) {
  644. args = args || [];
  645. var that = this;
  646. var html = "";
  647. var number = 0;
  648. this.callbacks = {};
  649. if (typeof args === "string") {
  650. html = args;
  651. number++;
  652. } else {
  653. $.each(args, function(i, val) {
  654. var id = val.id = val.id || val.value;
  655. var style = "";
  656. that.callbacks[id] = val.callback;
  657. if (val.display === false) {
  658. style = ' style="display:none"';
  659. } else {
  660. number++;
  661. }
  662. html += "<button" + ' type="button"' + ' i-id="' + id + '"' + style + (val.disabled ? " disabled" :"") + (val.autofocus ? ' autofocus class="ui-dialog-autofocus"' :"") + "><span>" + val.value + "</span></button>";
  663. that._$("button").on("click", "[i-id=" + id + "]", function(event) {
  664. var $this = $(this);
  665. if (!$this.attr("disabled")) {
  666. that._trigger(id);
  667. }
  668. event.preventDefault();
  669. });
  670. });
  671. }
  672. this._$("button").html(html);
  673. this._$("footer")[number ? "show" :"hide"]();
  674. return this;
  675. },
  676. statusbar:function(html) {
  677. this._$("statusbar").html(html)[html ? "show" :"hide"]();
  678. return this;
  679. },
  680. _$:function(i) {
  681. return this._popup.find("[i=" + i + "]");
  682. },
  683. _trigger:function(id) {
  684. var fn = this.callbacks[id];
  685. return typeof fn !== "function" || fn.call(this) !== false ? this.close().remove() :this;
  686. }
  687. });
  688. artDialog.oncreate = $.noop;
  689. artDialog.getCurrent = function() {
  690. return Popup.current;
  691. };
  692. artDialog.get = function(id) {
  693. return id === undefined ? artDialog.list :artDialog.list[id];
  694. };
  695. artDialog.list = {};
  696. artDialog.defaults = defaults;
  697. return artDialog;
  698. });
  699. define("drag", function(require) {
  700. var $ = require("jquery");
  701. var $window = $(window);
  702. var $document = $(document);
  703. var isTouch = "createTouch" in document;
  704. var html = document.documentElement;
  705. var isIE6 = !("minWidth" in html.style);
  706. var isLosecapture = !isIE6 && "onlosecapture" in html;
  707. var isSetCapture = "setCapture" in html;
  708. var types = {
  709. start:isTouch ? "touchstart" :"mousedown",
  710. over:isTouch ? "touchmove" :"mousemove",
  711. end:isTouch ? "touchend" :"mouseup"
  712. };
  713. var getEvent = isTouch ? function(event) {
  714. if (!event.touches) {
  715. event = event.originalEvent.touches.item(0);
  716. }
  717. return event;
  718. } :function(event) {
  719. return event;
  720. };
  721. var DragEvent = function() {
  722. this.start = $.proxy(this.start, this);
  723. this.over = $.proxy(this.over, this);
  724. this.end = $.proxy(this.end, this);
  725. this.onstart = this.onover = this.onend = $.noop;
  726. };
  727. DragEvent.types = types;
  728. DragEvent.prototype = {
  729. start:function(event) {
  730. event = this.startFix(event);
  731. $document.on(types.over, this.over).on(types.end, this.end);
  732. this.onstart(event);
  733. return false;
  734. },
  735. over:function(event) {
  736. event = this.overFix(event);
  737. this.onover(event);
  738. return false;
  739. },
  740. end:function(event) {
  741. event = this.endFix(event);
  742. $document.off(types.over, this.over).off(types.end, this.end);
  743. this.onend(event);
  744. return false;
  745. },
  746. startFix:function(event) {
  747. event = getEvent(event);
  748. this.target = $(event.target);
  749. this.selectstart = function() {
  750. return false;
  751. };
  752. $document.on("selectstart", this.selectstart).on("dblclick", this.end);
  753. if (isLosecapture) {
  754. this.target.on("losecapture", this.end);
  755. } else {
  756. $window.on("blur", this.end);
  757. }
  758. if (isSetCapture) {
  759. this.target[0].setCapture();
  760. }
  761. return event;
  762. },
  763. overFix:function(event) {
  764. event = getEvent(event);
  765. return event;
  766. },
  767. endFix:function(event) {
  768. event = getEvent(event);
  769. $document.off("selectstart", this.selectstart).off("dblclick", this.end);
  770. if (isLosecapture) {
  771. this.target.off("losecapture", this.end);
  772. } else {
  773. $window.off("blur", this.end);
  774. }
  775. if (isSetCapture) {
  776. this.target[0].releaseCapture();
  777. }
  778. return event;
  779. }
  780. };
  781. DragEvent.create = function(elem, event) {
  782. var $elem = $(elem);
  783. var dragEvent = new DragEvent();
  784. var startType = DragEvent.types.start;
  785. var noop = function() {};
  786. var className = elem.className.replace(/^\s|\s.*/g, "") + "-drag-start";
  787. var minX;
  788. var minY;
  789. var maxX;
  790. var maxY;
  791. var api = {
  792. onstart:noop,
  793. onover:noop,
  794. onend:noop,
  795. off:function() {
  796. $elem.off(startType, dragEvent.start);
  797. }
  798. };
  799. dragEvent.onstart = function(event) {
  800. var isFixed = $elem.css("position") === "fixed";
  801. var dl = $document.scrollLeft();
  802. var dt = $document.scrollTop();
  803. var w = $elem.width();
  804. var h = $elem.height();
  805. minX = 0;
  806. minY = 0;
  807. maxX = isFixed ? $window.width() - w + minX :$document.width() - w;
  808. maxY = isFixed ? $window.height() - h + minY :$document.height() - h;
  809. var offset = $elem.offset();
  810. var left = this.startLeft = isFixed ? offset.left - dl :offset.left;
  811. var top = this.startTop = isFixed ? offset.top - dt :offset.top;
  812. this.clientX = event.clientX;
  813. this.clientY = event.clientY;
  814. $elem.addClass(className);
  815. api.onstart.call(elem, event, left, top);
  816. };
  817. dragEvent.onover = function(event) {
  818. var left = event.clientX - this.clientX + this.startLeft;
  819. var top = event.clientY - this.clientY + this.startTop;
  820. var style = $elem[0].style;
  821. left = Math.max(minX, Math.min(maxX, left));
  822. top = Math.max(minY, Math.min(maxY, top));
  823. style.left = left + "px";
  824. style.top = top + "px";
  825. api.onover.call(elem, event, left, top);
  826. };
  827. dragEvent.onend = function(event) {
  828. var position = $elem.position();
  829. var left = position.left;
  830. var top = position.top;
  831. $elem.removeClass(className);
  832. api.onend.call(elem, event, left, top);
  833. };
  834. dragEvent.off = function() {
  835. $elem.off(startType, dragEvent.start);
  836. };
  837. if (event) {
  838. dragEvent.start(event);
  839. } else {
  840. $elem.on(startType, dragEvent.start);
  841. }
  842. return api;
  843. };
  844. return DragEvent;
  845. });
  846. define("dialog-plus", function(require) {
  847. var $ = require("jquery");
  848. var dialog = require("dialog");
  849. var drag = require("drag");
  850. dialog.oncreate = function(api) {
  851. var options = api.options;
  852. var originalOptions = options.original;
  853. var url = options.url;
  854. var oniframeload = options.oniframeload;
  855. var $iframe;
  856. if (url) {
  857. this.padding = options.padding = 0;
  858. $iframe = $("<iframe />");
  859. $iframe.attr({
  860. src:url,
  861. name:api.id,
  862. width:"100%",
  863. height:"100%",
  864. allowtransparency:"yes",
  865. frameborder:"no",
  866. scrolling:"no"
  867. }).on("load", function() {
  868. var test;
  869. try {
  870. test = $iframe[0].contentWindow.frameElement;
  871. } catch (e) {}
  872. if (test) {
  873. if (!options.width) {
  874. api.width($iframe.contents().width());
  875. }
  876. if (!options.height) {
  877. api.height($iframe.contents().height());
  878. }
  879. }
  880. if (oniframeload) {
  881. oniframeload.call(api);
  882. }
  883. });
  884. api.addEventListener("beforeremove", function() {
  885. $iframe.attr("src", "about:blank").remove();
  886. }, false);
  887. api.content($iframe[0]);
  888. api.iframeNode = $iframe[0];
  889. }
  890. if (!(originalOptions instanceof Object)) {
  891. var un = function() {
  892. api.close().remove();
  893. };
  894. for (var i = 0; i < frames.length; i++) {
  895. try {
  896. if (originalOptions instanceof frames[i].Object) {
  897. $(frames[i]).one("unload", un);
  898. break;
  899. }
  900. } catch (e) {}
  901. }
  902. }
  903. $(api.node).on(drag.types.start, "[i=title]", function(event) {
  904. if (!api.follow) {
  905. api.focus();
  906. drag.create(api.node, event);
  907. }
  908. });
  909. };
  910. dialog.get = function(id) {
  911. if (id && id.frameElement) {
  912. var iframe = id.frameElement;
  913. var list = dialog.list;
  914. var api;
  915. for (var i in list) {
  916. api = list[i];
  917. if (api.node.getElementsByTagName("iframe")[0] === iframe) {
  918. return api;
  919. }
  920. }
  921. } else if (id) {
  922. return dialog.list[id];
  923. }
  924. };
  925. return dialog;
  926. });
  927. window.dialog = require("dialog-plus");
  928. }();