dialog-plus.min.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  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
  281. , app = navigator.appVersion;
  282. return {
  283. trident: u.indexOf("Trident") > -1,
  284. presto: u.indexOf("Presto") > -1,
  285. webKit: u.indexOf("AppleWebKit") > -1,
  286. gecko: u.indexOf("Gecko") > -1 && u.indexOf("KHTML") == -1,
  287. mobile: !!u.match(/AppleWebKit.*Mobile.*/),
  288. ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
  289. android: u.indexOf("Android") > -1 || u.indexOf("Linux") > -1,
  290. iPhone: u.indexOf("iPhone") > -1,
  291. iPad: u.indexOf("iPad") > -1,
  292. webApp: u.indexOf("Safari") == -1
  293. }
  294. }(),
  295. language: (navigator.browserLanguage || navigator.language).toLowerCase()
  296. },
  297. __follow: function(anchor) {
  298. var $elem = anchor.parentNode && $(anchor);
  299. var popup = this.__popup;
  300. if (this.__followSkin) {
  301. popup.removeClass(this.__followSkin)
  302. }
  303. if ($elem) {
  304. var o = $elem.offset();
  305. if (o.left * o.top < 0) {
  306. return this.__center()
  307. }
  308. }
  309. var that = this;
  310. var fixed = this.fixed;
  311. var $window = $(window);
  312. var $document = $(document);
  313. var winWidth = $window.width();
  314. var winHeight = $window.height();
  315. var docLeft = $document.scrollLeft();
  316. var docTop = $document.scrollTop();
  317. var popupWidth = popup.width();
  318. var popupHeight = popup.height();
  319. var width = $elem ? $elem.outerWidth() : 0;
  320. var height = $elem ? $elem.outerHeight() : 0;
  321. var offset = this.__offset(anchor);
  322. var x = offset.left;
  323. var y = offset.top;
  324. var left = fixed ? x - docLeft : x;
  325. var top = fixed ? y - docTop : y;
  326. var minLeft = fixed ? 0 : docLeft;
  327. var minTop = fixed ? 0 : docTop;
  328. var maxLeft = minLeft + winWidth - popupWidth;
  329. var maxTop = minTop + winHeight - popupHeight;
  330. var css = {};
  331. var align = this.align.split(" ");
  332. var className = this.className + "-";
  333. var reverse = {
  334. top: "bottom",
  335. bottom: "top",
  336. left: "right",
  337. right: "left"
  338. };
  339. var name = {
  340. top: "top",
  341. bottom: "top",
  342. left: "left",
  343. right: "left"
  344. };
  345. var temp = [{
  346. top: top - popupHeight,
  347. bottom: top + height,
  348. left: left - popupWidth,
  349. right: left + width
  350. }, {
  351. top: top,
  352. bottom: top - popupHeight + height,
  353. left: left,
  354. right: left - popupWidth + width
  355. }];
  356. var center = {
  357. left: left + width / 2 - popupWidth / 2,
  358. top: top + height / 2 - popupHeight / 2
  359. };
  360. var range = {
  361. left: [minLeft, maxLeft],
  362. top: [minTop, maxTop]
  363. };
  364. $.each(align, function(i, val) {
  365. if (temp[i][val] > range[name[val]][1]) {
  366. val = align[i] = reverse[val]
  367. }
  368. if (temp[i][val] < range[name[val]][0]) {
  369. align[i] = reverse[val]
  370. }
  371. });
  372. if (!align[1]) {
  373. name[align[1]] = name[align[0]] === "left" ? "top" : "left";
  374. temp[1][align[1]] = center[name[align[1]]]
  375. }
  376. className += align.join("-") + " " + this.className + "-follow";
  377. that.__followSkin = className;
  378. if ($elem) {
  379. popup.addClass(className)
  380. }
  381. css[name[align[0]]] = parseInt(temp[0][align[0]]);
  382. css[name[align[1]]] = parseInt(temp[1][align[1]]);
  383. popup.css(css)
  384. },
  385. __offset: function(anchor) {
  386. var isNode = anchor.parentNode;
  387. var offset = isNode ? $(anchor).offset() : {
  388. left: anchor.pageX,
  389. top: anchor.pageY
  390. };
  391. anchor = isNode ? anchor : anchor.target;
  392. var ownerDocument = anchor.ownerDocument;
  393. var defaultView = ownerDocument.defaultView || ownerDocument.parentWindow;
  394. if (defaultView == window) {
  395. return offset
  396. }
  397. var frameElement = defaultView.frameElement;
  398. var $ownerDocument = $(ownerDocument);
  399. var docLeft = $ownerDocument.scrollLeft();
  400. var docTop = $ownerDocument.scrollTop();
  401. var frameOffset = $(frameElement).offset();
  402. var frameLeft = frameOffset.left;
  403. var frameTop = frameOffset.top;
  404. return {
  405. left: offset.left + frameLeft - docLeft,
  406. top: offset.top + frameTop - docTop
  407. }
  408. }
  409. });
  410. Popup.zIndex = 1024;
  411. Popup.current = null;
  412. return Popup
  413. });
  414. define("dialog-config", {
  415. fixed: true,
  416. zIndex: 3e3,
  417. backdropBackground: "#000",
  418. backdropOpacity: .7,
  419. content: "",
  420. contentType: "",
  421. closeTime: 3e3,
  422. title: "",
  423. statusbar: "",
  424. button: null,
  425. ok: null,
  426. cancel: null,
  427. okValue: "确定",
  428. cancelValue: "取消",
  429. cancelDisplay: true,
  430. width: "",
  431. height: "",
  432. padding: "",
  433. titlePadding: "",
  434. contentBlock: false,
  435. skin: "ax-popup",
  436. boxSkin: "ui-popup-full fat-title",
  437. quickClose: false,
  438. cssUri: "",
  439. 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>"
  440. });
  441. define("dialog", function(require) {
  442. var $ = require("jquery");
  443. var Popup = require("popup");
  444. var defaults = require("dialog-config");
  445. var css = defaults.cssUri;
  446. if (css) {
  447. var fn = require[require.toUrl ? "toUrl" : "resolve"];
  448. if (fn) {
  449. css = fn(css);
  450. css = '<link rel="stylesheet" href="' + css + '" />';
  451. if ($("base")[0]) {
  452. $("base").before(css)
  453. } else {
  454. $("head").append(css)
  455. }
  456. }
  457. }
  458. var _count = 0;
  459. var _expando = new Date() - 0;
  460. var _isIE6 = !("minWidth"in $("html")[0].style);
  461. var _isMobile = "createTouch"in document && !("onmousemove"in document) || /(iPhone|iPad|iPod)/i.test(navigator.userAgent);
  462. var _isFixed = !_isIE6 && !_isMobile;
  463. var artDialog = function(options, ok, cancel) {
  464. var originalOptions = options = options || {};
  465. if (typeof options === "string" || options.nodeType === 1) {
  466. options = {
  467. content: options,
  468. fixed: !_isMobile
  469. }
  470. }
  471. options = $.extend(true, {}, artDialog.defaults, options);
  472. options.original = originalOptions;
  473. var id = options.id = options.id || _expando + _count;
  474. var api = artDialog.get(id);
  475. if (api) {
  476. return api.focus()
  477. }
  478. if (!_isFixed) {
  479. options.fixed = false
  480. }
  481. if (options.quickClose) {
  482. options.modal = true;
  483. options.backdropOpacity = .7
  484. }
  485. if (!$.isArray(options.button)) {
  486. options.button = []
  487. }
  488. if (cancel !== undefined) {
  489. options.cancel = cancel
  490. }
  491. if (options.cancel) {
  492. options.button.push({
  493. id: "cancel",
  494. value: options.cancelValue,
  495. callback: options.cancel,
  496. display: options.cancelDisplay
  497. })
  498. }
  499. if (ok !== undefined) {
  500. options.ok = ok
  501. }
  502. if (options.ok) {
  503. options.button.push({
  504. id: "ok",
  505. value: options.okValue,
  506. callback: options.ok,
  507. autofocus: true
  508. })
  509. }
  510. return artDialog.list[id] = new artDialog.create(options)
  511. };
  512. var popup = function() {};
  513. popup.prototype = Popup.prototype;
  514. var prototype = artDialog.prototype = new popup();
  515. artDialog.create = function(options) {
  516. var that = this;
  517. $.extend(this, new Popup());
  518. var originalOptions = options.original;
  519. var $popup = $(this.node).html(options.innerHTML);
  520. var $backdrop = $(this.backdrop);
  521. this.options = options;
  522. this._popup = $popup;
  523. $.each(options, function(name, value) {
  524. if (typeof that[name] === "function") {
  525. that[name](value)
  526. } else {
  527. that[name] = value
  528. }
  529. });
  530. if (options.zIndex) {
  531. Popup.zIndex = options.zIndex
  532. }
  533. $popup.attr({
  534. "aria-labelledby": this._$("title").attr("id", "title:" + this.id).attr("id"),
  535. "aria-describedby": this._$("content").attr("id", "content:" + this.id).attr("id")
  536. });
  537. this._$("close").css("display", this.cancel === false ? "none" : "").attr("title", this.cancelValue).on("click", function(event) {
  538. that._trigger("cancel");
  539. event.preventDefault()
  540. });
  541. if (this.contentType != "") {
  542. this.boxSkin = "";
  543. if (this.skin == "bk-popup") {
  544. this.skin = "bk-popup smallTips"
  545. } else {
  546. this.skin = "smallTips"
  547. }
  548. }
  549. this._$("dialog").addClass(this.skin);
  550. $popup.addClass(this.boxSkin);
  551. this._$("body").css("padding", this.padding);
  552. this._$("title").css("padding", this.titlePadding);
  553. if (this.contentBlock) {
  554. this._$("content").css("display", "block")
  555. }
  556. if (options.quickClose) {
  557. $backdrop.on("onmousedown"in document ? "mousedown" : "click", function() {
  558. that._trigger("cancel");
  559. return false
  560. })
  561. }
  562. this.addEventListener("show", function() {
  563. $backdrop.css({
  564. opacity: options.backdropOpacity,
  565. background: options.backdropBackground
  566. })
  567. });
  568. this._esc = function(event) {
  569. var target = event.target;
  570. var nodeName = target.nodeName;
  571. var rinput = /^input|textarea$/i;
  572. var isTop = Popup.current === that;
  573. var keyCode = event.keyCode;
  574. if (!isTop || rinput.test(nodeName) && target.type !== "button") {
  575. return
  576. }
  577. if (keyCode === 27) {
  578. that._trigger("cancel")
  579. }
  580. }
  581. ;
  582. $(document).on("keydown", this._esc);
  583. this.addEventListener("remove", function() {
  584. $(document).off("keydown", this._esc);
  585. delete artDialog.list[this.id]
  586. });
  587. _count++;
  588. artDialog.oncreate(this);
  589. return this
  590. }
  591. ;
  592. artDialog.create.prototype = prototype;
  593. $.extend(prototype, {
  594. content: function(html) {
  595. var $content = this._$("content");
  596. if (typeof html === "object") {
  597. html = $(html);
  598. $content.empty("").append(html.show());
  599. this.addEventListener("beforeremove", function() {
  600. $("body").append(html.hide())
  601. })
  602. } else {
  603. if (this.options.contentType != "") {
  604. switch (this.options.contentType) {
  605. case "load":
  606. if (this.options.content == "") {
  607. html = '<span class="ui-dialog-loading"></span><p style="float:left;">加载中,请稍候...</p>'
  608. } else {
  609. html = '<span class="ui-dialog-loading"></span><p style="float:left;">' + this.options.content + "</p>"
  610. }
  611. break;
  612. case "jsonload":
  613. if (this.options.content == "") {
  614. html = '<span class="ui-dialog-loading"></span><p style="float:left;">数据载入中,请稍候...</p>'
  615. } else {
  616. html = '<span class="ui-dialog-loading"></span><p style="float:left;">' + this.options.content + "</p>"
  617. }
  618. break;
  619. case "tipsbox":
  620. var th = this;
  621. if (this.options.closeTime != 0) {
  622. setTimeout(function() {
  623. artDialog.list[th.id].close().remove()
  624. }, this.options.closeTime)
  625. }
  626. break
  627. }
  628. }
  629. $content.html(html)
  630. }
  631. return this.reset()
  632. },
  633. title: function(text) {
  634. this._$("title").html(text);
  635. this._$("header")[text ? "show" : "hide"]();
  636. return this
  637. },
  638. width: function(value) {
  639. this._$("content").css("width", value);
  640. return this.reset()
  641. },
  642. height: function(value) {
  643. this._$("content").css("height", value);
  644. return this.reset()
  645. },
  646. button: function(args) {
  647. args = args || [];
  648. var that = this;
  649. var html = "";
  650. var number = 0;
  651. this.callbacks = {};
  652. if (typeof args === "string") {
  653. html = args;
  654. number++
  655. } else {
  656. $.each(args, function(i, val) {
  657. var id = val.id = val.id || val.value;
  658. var style = "";
  659. that.callbacks[id] = val.callback;
  660. if (val.display === false) {
  661. style = ' style="display:none"'
  662. } else {
  663. number++
  664. }
  665. html += "<button" + ' type="button"' + ' i-id="' + id + '"' + style + (val.disabled ? " disabled" : "") + (val.autofocus ? ' autofocus class="ui-dialog-autofocus"' : "") + "><span>" + val.value + "</span></button>";
  666. that._$("button").on("click", "[i-id=" + id + "]", function(event) {
  667. var $this = $(this);
  668. if (!$this.attr("disabled")) {
  669. that._trigger(id)
  670. }
  671. event.preventDefault()
  672. })
  673. })
  674. }
  675. this._$("button").html(html);
  676. this._$("footer")[number ? "show" : "hide"]();
  677. return this
  678. },
  679. statusbar: function(html) {
  680. this._$("statusbar").html(html)[html ? "show" : "hide"]();
  681. return this
  682. },
  683. _$: function(i) {
  684. return this._popup.find("[i=" + i + "]")
  685. },
  686. _trigger: function(id) {
  687. var fn = this.callbacks[id];
  688. return typeof fn !== "function" || fn.call(this) !== false ? this.close().remove() : this
  689. }
  690. });
  691. artDialog.oncreate = $.noop;
  692. artDialog.getCurrent = function() {
  693. return Popup.current
  694. }
  695. ;
  696. artDialog.get = function(id) {
  697. return id === undefined ? artDialog.list : artDialog.list[id]
  698. }
  699. ;
  700. artDialog.list = {};
  701. artDialog.defaults = defaults;
  702. return artDialog
  703. });
  704. define("drag", function(require) {
  705. var $ = require("jquery");
  706. var $window = $(window);
  707. var $document = $(document);
  708. var isTouch = "createTouch"in document;
  709. var html = document.documentElement;
  710. var isIE6 = !("minWidth"in html.style);
  711. var isLosecapture = !isIE6 && "onlosecapture"in html;
  712. var isSetCapture = "setCapture"in html;
  713. var types = {
  714. start: isTouch ? "touchstart" : "mousedown",
  715. over: isTouch ? "touchmove" : "mousemove",
  716. end: isTouch ? "touchend" : "mouseup"
  717. };
  718. var getEvent = isTouch ? function(event) {
  719. if (!event.touches) {
  720. event = event.originalEvent.touches.item(0)
  721. }
  722. return event
  723. }
  724. : function(event) {
  725. return event
  726. }
  727. ;
  728. var DragEvent = function() {
  729. this.start = $.proxy(this.start, this);
  730. this.over = $.proxy(this.over, this);
  731. this.end = $.proxy(this.end, this);
  732. this.onstart = this.onover = this.onend = $.noop
  733. };
  734. DragEvent.types = types;
  735. DragEvent.prototype = {
  736. start: function(event) {
  737. event = this.startFix(event);
  738. $document.on(types.over, this.over).on(types.end, this.end);
  739. this.onstart(event);
  740. return false
  741. },
  742. over: function(event) {
  743. event = this.overFix(event);
  744. this.onover(event);
  745. return false
  746. },
  747. end: function(event) {
  748. event = this.endFix(event);
  749. $document.off(types.over, this.over).off(types.end, this.end);
  750. this.onend(event);
  751. return false
  752. },
  753. startFix: function(event) {
  754. event = getEvent(event);
  755. this.target = $(event.target);
  756. this.selectstart = function() {
  757. return false
  758. }
  759. ;
  760. $document.on("selectstart", this.selectstart).on("dblclick", this.end);
  761. if (isLosecapture) {
  762. this.target.on("losecapture", this.end)
  763. } else {
  764. $window.on("blur", this.end)
  765. }
  766. if (isSetCapture) {
  767. this.target[0].setCapture()
  768. }
  769. return event
  770. },
  771. overFix: function(event) {
  772. event = getEvent(event);
  773. return event
  774. },
  775. endFix: function(event) {
  776. event = getEvent(event);
  777. $document.off("selectstart", this.selectstart).off("dblclick", this.end);
  778. if (isLosecapture) {
  779. this.target.off("losecapture", this.end)
  780. } else {
  781. $window.off("blur", this.end)
  782. }
  783. if (isSetCapture) {
  784. this.target[0].releaseCapture()
  785. }
  786. return event
  787. }
  788. };
  789. DragEvent.create = function(elem, event) {
  790. var $elem = $(elem);
  791. var dragEvent = new DragEvent();
  792. var startType = DragEvent.types.start;
  793. var noop = function() {};
  794. var className = elem.className.replace(/^\s|\s.*/g, "") + "-drag-start";
  795. var minX;
  796. var minY;
  797. var maxX;
  798. var maxY;
  799. var api = {
  800. onstart: noop,
  801. onover: noop,
  802. onend: noop,
  803. off: function() {
  804. $elem.off(startType, dragEvent.start)
  805. }
  806. };
  807. dragEvent.onstart = function(event) {
  808. var isFixed = $elem.css("position") === "fixed";
  809. var dl = $document.scrollLeft();
  810. var dt = $document.scrollTop();
  811. var w = $elem.width();
  812. var h = $elem.height();
  813. minX = 0;
  814. minY = 0;
  815. maxX = isFixed ? $window.width() - w + minX : $document.width() - w;
  816. maxY = isFixed ? $window.height() - h + minY : $document.height() - h;
  817. var offset = $elem.offset();
  818. var left = this.startLeft = isFixed ? offset.left - dl : offset.left;
  819. var top = this.startTop = isFixed ? offset.top - dt : offset.top;
  820. this.clientX = event.clientX;
  821. this.clientY = event.clientY;
  822. $elem.addClass(className);
  823. api.onstart.call(elem, event, left, top)
  824. }
  825. ;
  826. dragEvent.onover = function(event) {
  827. var left = event.clientX - this.clientX + this.startLeft;
  828. var top = event.clientY - this.clientY + this.startTop;
  829. var style = $elem[0].style;
  830. left = Math.max(minX, Math.min(maxX, left));
  831. top = Math.max(minY, Math.min(maxY, top));
  832. style.left = left + "px";
  833. style.top = top + "px";
  834. api.onover.call(elem, event, left, top)
  835. }
  836. ;
  837. dragEvent.onend = function(event) {
  838. var position = $elem.position();
  839. var left = position.left;
  840. var top = position.top;
  841. $elem.removeClass(className);
  842. api.onend.call(elem, event, left, top)
  843. }
  844. ;
  845. dragEvent.off = function() {
  846. $elem.off(startType, dragEvent.start)
  847. }
  848. ;
  849. if (event) {
  850. dragEvent.start(event)
  851. } else {
  852. $elem.on(startType, dragEvent.start)
  853. }
  854. return api
  855. }
  856. ;
  857. return DragEvent
  858. });
  859. define("dialog-plus", function(require) {
  860. var $ = require("jquery");
  861. var dialog = require("dialog");
  862. var drag = require("drag");
  863. dialog.oncreate = function(api) {
  864. var options = api.options;
  865. var originalOptions = options.original;
  866. var url = options.url;
  867. var oniframeload = options.oniframeload;
  868. var $iframe;
  869. if (url) {
  870. this.padding = options.padding = 0;
  871. $iframe = $("<iframe />");
  872. $iframe.attr({
  873. src: url,
  874. name: api.id,
  875. width: "100%",
  876. height: "100%",
  877. allowtransparency: "yes",
  878. frameborder: "no",
  879. scrolling: "no"
  880. }).on("load", function() {
  881. var test;
  882. try {
  883. test = $iframe[0].contentWindow.frameElement
  884. } catch (e) {}
  885. if (test) {
  886. if (!options.width) {
  887. api.width($iframe.contents().width())
  888. }
  889. if (!options.height) {
  890. api.height($iframe.contents().height())
  891. }
  892. }
  893. if (oniframeload) {
  894. oniframeload.call(api)
  895. }
  896. });
  897. api.addEventListener("beforeremove", function() {
  898. $iframe.attr("src", "about:blank").remove()
  899. }, false);
  900. api.content($iframe[0]);
  901. api.iframeNode = $iframe[0]
  902. }
  903. if (!(originalOptions instanceof Object)) {
  904. var un = function() {
  905. api.close().remove()
  906. };
  907. for (var i = 0; i < frames.length; i++) {
  908. try {
  909. if (originalOptions instanceof frames[i].Object) {
  910. $(frames[i]).one("unload", un);
  911. break
  912. }
  913. } catch (e) {}
  914. }
  915. }
  916. $(api.node).on(drag.types.start, "[i=title]", function(event) {
  917. if (!api.follow) {
  918. api.focus();
  919. drag.create(api.node, event)
  920. }
  921. })
  922. }
  923. ;
  924. dialog.get = function(id) {
  925. if (id && id.frameElement) {
  926. var iframe = id.frameElement;
  927. var list = dialog.list;
  928. var api;
  929. for (var i in list) {
  930. api = list[i];
  931. if (api.node.getElementsByTagName("iframe")[0] === iframe) {
  932. return api
  933. }
  934. }
  935. } else if (id) {
  936. return dialog.list[id]
  937. }
  938. }
  939. ;
  940. return dialog
  941. });
  942. window.dialog = require("dialog-plus")
  943. }();