bootstrap-dialog.min.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  1. /* global define */
  2. /* ================================================
  3. * Make use of Bootstrap's modal more monkey-friendly.
  4. *
  5. * For Bootstrap 3.
  6. *
  7. * javanoob@hotmail.com
  8. *
  9. * https://github.com/nakupanda/bootstrap3-dialog
  10. *
  11. * Licensed under The MIT License.
  12. *
  13. * zxh 修复几个bug
  14. * 1、新增 iframe url 的方式的窗口;
  15. * 2、新增 target 方式的窗口;
  16. * 3、修正 office控件被遮挡的问题;
  17. * 4、修改了BootstrapDialog.confirm的处理方式;
  18. * 5、新增等待窗口。
  19. * ================================================ */
  20. (function(root, factory) {
  21. "use strict";
  22. // CommonJS module is defined
  23. if (typeof module !== 'undefined' && module.exports) {
  24. module.exports = factory(require('jquery')(root));
  25. }
  26. // AMD module is defined
  27. else if (typeof define === "function" && define.amd) {
  28. define("bootstrap-dialog", ["jquery"], function($) {
  29. return factory($);
  30. });
  31. } else {
  32. // planted over the root!
  33. root.BootstrapDialog = factory(root.jQuery);
  34. }
  35. }(this, function($) {
  36. "use strict";
  37. /* ================================================
  38. * Definition of BootstrapDialogModal.
  39. * Extend Bootstrap Modal and override some functions.
  40. * BootstrapDialogModal === Modified Modal.
  41. * ================================================ */
  42. var Modal = $.fn.modal.Constructor;
  43. var BootstrapDialogModal = function(element, options) {
  44. Modal.call(this, element, options);
  45. };
  46. BootstrapDialogModal.getModalVersion = function() {
  47. var version = null;
  48. if (typeof $.fn.modal.Constructor.VERSION === 'undefined') {
  49. version = 'v3.1';
  50. } else if (/3\.2\.\d+/.test($.fn.modal.Constructor.VERSION)) {
  51. version = 'v3.2';
  52. } else {
  53. version = 'v3.3'; // v3.3+
  54. }
  55. return version;
  56. };
  57. BootstrapDialogModal.ORIGINAL_BODY_PADDING = $('body').css('padding-right') || 0;
  58. BootstrapDialogModal.METHODS_TO_OVERRIDE = {};
  59. BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.1'] = {};
  60. BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.2'] = {
  61. hide: function(e) {
  62. if (e) {
  63. e.preventDefault();
  64. }
  65. e = $.Event('hide.bs.modal');
  66. this.$element.trigger(e);
  67. if (!this.isShown || e.isDefaultPrevented()) {
  68. return;
  69. }
  70. this.isShown = false;
  71. // Remove css class 'modal-open' when the last opened dialog is closing.
  72. var openedDialogs = this.getGlobalOpenedDialogs();
  73. if (openedDialogs.length === 0) {
  74. this.$body.removeClass('modal-open');
  75. }
  76. this.resetScrollbar();
  77. this.escape();
  78. $(document).off('focusin.bs.modal');
  79. this.$element
  80. .removeClass('in')
  81. .attr('aria-hidden', true)
  82. .off('click.dismiss.bs.modal');
  83. $.support.transition && this.$element.hasClass('fade') ?
  84. this.$element
  85. .one('bsTransitionEnd', $.proxy(this.hideModal, this))
  86. .emulateTransitionEnd(300) :
  87. this.hideModal();
  88. }
  89. };
  90. BootstrapDialogModal.METHODS_TO_OVERRIDE['v3.3'] = {
  91. /**
  92. * Overrided.
  93. *
  94. * @returns {undefined}
  95. */
  96. setScrollbar: function() {
  97. var bodyPad = BootstrapDialogModal.ORIGINAL_BODY_PADDING;
  98. if (this.bodyIsOverflowing) {
  99. this.$body.css('padding-right', bodyPad + this.scrollbarWidth);
  100. }
  101. },
  102. /**
  103. * Overrided.
  104. *
  105. * @returns {undefined}
  106. */
  107. resetScrollbar: function() {
  108. var openedDialogs = this.getGlobalOpenedDialogs();
  109. if (openedDialogs.length === 0) {
  110. this.$body.css('padding-right', BootstrapDialogModal.ORIGINAL_BODY_PADDING);
  111. }
  112. },
  113. /**
  114. * Overrided.
  115. *
  116. * @returns {undefined}
  117. */
  118. hideModal: function() {
  119. this.$element.hide();
  120. this.backdrop($.proxy(function() {
  121. var openedDialogs = this.getGlobalOpenedDialogs();
  122. if (openedDialogs.length === 0) {
  123. this.$body.removeClass('modal-open');
  124. }
  125. this.resetAdjustments();
  126. this.resetScrollbar();
  127. this.$element.trigger('hidden.bs.modal');
  128. }, this));
  129. }
  130. };
  131. BootstrapDialogModal.prototype = {
  132. constructor: BootstrapDialogModal,
  133. /**
  134. * New function, to get the dialogs that opened by BootstrapDialog.
  135. *
  136. * @returns {undefined}
  137. */
  138. getGlobalOpenedDialogs: function() {
  139. var openedDialogs = [];
  140. $.each(BootstrapDialog.dialogs, function(id, dialogInstance) {
  141. if (dialogInstance.isRealized() && dialogInstance.isOpened()) {
  142. openedDialogs.push(dialogInstance);
  143. }
  144. });
  145. return openedDialogs;
  146. }
  147. };
  148. // Add compatible methods.
  149. BootstrapDialogModal.prototype = $.extend(BootstrapDialogModal.prototype, Modal.prototype, BootstrapDialogModal.METHODS_TO_OVERRIDE[BootstrapDialogModal.getModalVersion()]);
  150. /* ================================================
  151. * Definition of BootstrapDialog.
  152. * ================================================ */
  153. var BootstrapDialog = function(options) {
  154. this.defaultOptions = $.extend(true, {
  155. id: BootstrapDialog.newGuid(),
  156. buttons: [],
  157. data: {},
  158. onshow: null,
  159. onshown: null,
  160. onhide: null,
  161. onhidden: null
  162. }, BootstrapDialog.defaultOptions);
  163. this.indexedButtons = {};
  164. this.registeredButtonHotkeys = {};
  165. this.draggableData = {
  166. isMouseDown: false,
  167. mouseOffset: {}
  168. };
  169. this.realized = false;
  170. this.opened = false;
  171. this.initOptions(options);
  172. this.holdThisInstance();
  173. };
  174. BootstrapDialog.BootstrapDialogModal = BootstrapDialogModal;
  175. /**
  176. * Some constants.
  177. */
  178. BootstrapDialog.NAMESPACE = 'bootstrap-dialog';
  179. BootstrapDialog.TYPE_DEFAULT = 'type-default';
  180. BootstrapDialog.TYPE_INFO = 'type-info';
  181. BootstrapDialog.TYPE_PRIMARY = 'type-primary';
  182. BootstrapDialog.TYPE_SUCCESS = 'type-success';
  183. BootstrapDialog.TYPE_WARNING = 'type-warning';
  184. BootstrapDialog.TYPE_DANGER = 'type-danger';
  185. BootstrapDialog.DEFAULT_TEXTS = {};
  186. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_DEFAULT] = '提示';
  187. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_INFO] = '提示';
  188. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_PRIMARY] = '提示';
  189. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_SUCCESS] = '提示';
  190. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_WARNING] = '提示';
  191. BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_DANGER] = '提示';
  192. BootstrapDialog.DEFAULT_TEXTS['OK'] = '确定';
  193. BootstrapDialog.DEFAULT_TEXTS['CANCEL'] = '取消';
  194. BootstrapDialog.DEFAULT_TEXTS['YES'] = '是';
  195. BootstrapDialog.DEFAULT_TEXTS['NO'] = '否';
  196. BootstrapDialog.SIZE_NORMAL = 'size-normal';
  197. BootstrapDialog.SIZE_SMALL = 'size-small';
  198. BootstrapDialog.SIZE_WIDE = 'size-wide'; // size-wide is equal to modal-lg
  199. BootstrapDialog.SIZE_LARGE = 'size-large';
  200. BootstrapDialog.BUTTON_SIZES = {};
  201. BootstrapDialog.BUTTON_SIZES[BootstrapDialog.SIZE_NORMAL] = '';
  202. BootstrapDialog.BUTTON_SIZES[BootstrapDialog.SIZE_SMALL] = '';
  203. BootstrapDialog.BUTTON_SIZES[BootstrapDialog.SIZE_WIDE] = '';
  204. BootstrapDialog.BUTTON_SIZES[BootstrapDialog.SIZE_LARGE] = 'btn-lg';
  205. BootstrapDialog.ICON_SPINNER = 'glyphicon glyphicon-asterisk';
  206. /**
  207. * Default options.
  208. */
  209. BootstrapDialog.defaultOptions = {
  210. type: BootstrapDialog.TYPE_PRIMARY,
  211. size: BootstrapDialog.SIZE_NORMAL,
  212. cssClass: '',
  213. title: null,
  214. message: null,
  215. nl2br: true,
  216. closable: true,
  217. closeByBackdrop: true,
  218. closeByKeyboard: true,
  219. spinicon: BootstrapDialog.ICON_SPINNER,
  220. autodestroy: true,
  221. draggable: false,
  222. animate: true,
  223. description: ''
  224. };
  225. /**
  226. * Config default options.
  227. */
  228. BootstrapDialog.configDefaultOptions = function(options) {
  229. BootstrapDialog.defaultOptions = $.extend(true, BootstrapDialog.defaultOptions, options);
  230. };
  231. /**
  232. * Open / Close all created dialogs all at once.
  233. */
  234. BootstrapDialog.dialogs = {};
  235. BootstrapDialog.openAll = function() {
  236. $.each(BootstrapDialog.dialogs, function(id, dialogInstance) {
  237. dialogInstance.open();
  238. });
  239. };
  240. BootstrapDialog.closeAll = function() {
  241. $.each(BootstrapDialog.dialogs, function(id, dialogInstance) {
  242. dialogInstance.close();
  243. });
  244. };
  245. /**
  246. * Move focus to next visible dialog.
  247. */
  248. BootstrapDialog.moveFocus = function() {
  249. var lastDialogInstance = null;
  250. $.each(BootstrapDialog.dialogs, function(id, dialogInstance) {
  251. lastDialogInstance = dialogInstance;
  252. });
  253. if (lastDialogInstance !== null && lastDialogInstance.isRealized()) {
  254. lastDialogInstance.getModal().focus();
  255. }
  256. };
  257. BootstrapDialog.METHODS_TO_OVERRIDE = {};
  258. BootstrapDialog.METHODS_TO_OVERRIDE['v3.1'] = {
  259. handleModalBackdropEvent: function() {
  260. this.getModal().on('click', {dialog: this}, function(event) {
  261. event.target === this && event.data.dialog.isClosable() && event.data.dialog.canCloseByBackdrop() && event.data.dialog.close();
  262. });
  263. return this;
  264. },
  265. /**
  266. * To make multiple opened dialogs look better.
  267. *
  268. * Will be removed in later version, after Bootstrap Modal >= 3.3.0, updating z-index is unnecessary.
  269. */
  270. updateZIndex: function() {
  271. var zIndexBackdrop = 1040;
  272. var zIndexModal = 1050;
  273. var dialogCount = 0;
  274. $.each(BootstrapDialog.dialogs, function(dialogId, dialogInstance) {
  275. dialogCount++;
  276. });
  277. var $modal = this.getModal();
  278. var $backdrop = $modal.data('bs.modal').$backdrop;
  279. $modal.css('z-index', zIndexModal + (dialogCount - 1) * 20);
  280. $backdrop.css('z-index', zIndexBackdrop + (dialogCount - 1) * 20);
  281. return this;
  282. },
  283. open: function() {
  284. !this.isRealized() && this.realize();
  285. this.getModal().modal('show');
  286. this.updateZIndex();
  287. this.setOpened(true);
  288. return this;
  289. }
  290. };
  291. BootstrapDialog.METHODS_TO_OVERRIDE['v3.2'] = {
  292. handleModalBackdropEvent: BootstrapDialog.METHODS_TO_OVERRIDE['v3.1']['handleModalBackdropEvent'],
  293. updateZIndex: BootstrapDialog.METHODS_TO_OVERRIDE['v3.1']['updateZIndex'],
  294. open: BootstrapDialog.METHODS_TO_OVERRIDE['v3.1']['open']
  295. };
  296. BootstrapDialog.METHODS_TO_OVERRIDE['v3.3'] = {};
  297. BootstrapDialog.prototype = {
  298. constructor: BootstrapDialog,
  299. initOptions: function(options) {
  300. this.options = $.extend(true, this.defaultOptions, options);
  301. return this;
  302. },
  303. holdThisInstance: function() {
  304. BootstrapDialog.dialogs[this.getId()] = this;
  305. return this;
  306. },
  307. initModalStuff: function() {
  308. this.setModal(this.createModal())
  309. .setModalDialog(this.createModalDialog())
  310. .setModalContent(this.createModalContent())
  311. .setModalHeader(this.createModalHeader())
  312. .setModalBody(this.createModalBody())
  313. .setModalFooter(this.createModalFooter());
  314. this.getModal().append(this.getModalDialog());
  315. this.getModalDialog().append(this.getModalContent());
  316. this.getModalContent()
  317. .append(this.getModalHeader())
  318. .append(this.getModalBody())
  319. .append(this.getModalFooter());
  320. return this;
  321. },
  322. createModal: function() {
  323. var $modal = $('<div class="modal" tabindex="-1" role="dialog" aria-hidden="true"></div>');
  324. $modal.prop('id', this.getId()).attr('aria-labelledby', this.getId() + '_title');
  325. return $modal;
  326. },
  327. getModal: function() {
  328. return this.$modal;
  329. },
  330. setModal: function($modal) {
  331. this.$modal = $modal;
  332. return this;
  333. },
  334. createModalDialog: function() {
  335. return $('<div class="modal-dialog"></div>');
  336. },
  337. getModalDialog: function() {
  338. return this.$modalDialog;
  339. },
  340. setModalDialog: function($modalDialog) {
  341. this.$modalDialog = $modalDialog;
  342. return this;
  343. },
  344. createModalContent: function() {
  345. return $('<div class="modal-content"></div>');
  346. },
  347. getModalContent: function() {
  348. return this.$modalContent;
  349. },
  350. setModalContent: function($modalContent) {
  351. this.$modalContent = $modalContent;
  352. return this;
  353. },
  354. createModalHeader: function() {
  355. return $('<div class="modal-header"></div>');
  356. },
  357. getModalHeader: function() {
  358. return this.$modalHeader;
  359. },
  360. setModalHeader: function($modalHeader) {
  361. this.$modalHeader = $modalHeader;
  362. return this;
  363. },
  364. createModalBody: function() {
  365. return $('<div class="modal-body"></div>');
  366. },
  367. getModalBody: function() {
  368. return this.$modalBody;
  369. },
  370. setModalBody: function($modalBody) {
  371. this.$modalBody = $modalBody;
  372. return this;
  373. },
  374. createModalFooter: function() {
  375. return $('<div class="modal-footer"></div>');
  376. },
  377. getModalFooter: function() {
  378. return this.$modalFooter;
  379. },
  380. setModalFooter: function($modalFooter) {
  381. this.$modalFooter = $modalFooter;
  382. return this;
  383. },
  384. createDynamicContent: function(rawContent) {
  385. var content = null;
  386. if (typeof rawContent === 'function') {
  387. content = rawContent.call(rawContent, this);
  388. } else {
  389. content = rawContent;
  390. }
  391. if (typeof content === 'string') {
  392. content = this.formatStringContent(content);
  393. }
  394. return content;
  395. },
  396. formatStringContent: function(content) {
  397. if (this.options.nl2br) {
  398. return content.replace(/\r\n/g, '<br />').replace(/[\r\n]/g, '<br />');
  399. }
  400. return content;
  401. },
  402. setData: function(key, value) {
  403. this.options.data[key] = value;
  404. return this;
  405. },
  406. getData: function(key) {
  407. return this.options.data[key];
  408. },
  409. setId: function(id) {
  410. this.options.id = id;
  411. return this;
  412. },
  413. getId: function() {
  414. return this.options.id;
  415. },
  416. getType: function() {
  417. return this.options.type;
  418. },
  419. setType: function(type) {
  420. this.options.type = type;
  421. this.updateType();
  422. return this;
  423. },
  424. updateType: function() {
  425. if (this.isRealized()) {
  426. var types = [BootstrapDialog.TYPE_DEFAULT,
  427. BootstrapDialog.TYPE_INFO,
  428. BootstrapDialog.TYPE_PRIMARY,
  429. BootstrapDialog.TYPE_SUCCESS,
  430. BootstrapDialog.TYPE_WARNING,
  431. BootstrapDialog.TYPE_DANGER];
  432. this.getModal().removeClass(types.join(' ')).addClass(this.getType());
  433. }
  434. return this;
  435. },
  436. getSize: function() {
  437. return this.options.size;
  438. },
  439. setSize: function(size) {
  440. this.options.size = size;
  441. this.updateSize();
  442. return this;
  443. },
  444. updateSize: function() {
  445. if (this.isRealized()) {
  446. var dialog = this;
  447. // Dialog size
  448. this.getModal().removeClass(BootstrapDialog.SIZE_NORMAL)
  449. .removeClass(BootstrapDialog.SIZE_SMALL)
  450. .removeClass(BootstrapDialog.SIZE_WIDE)
  451. .removeClass(BootstrapDialog.SIZE_LARGE);
  452. this.getModal().addClass(this.getSize());
  453. // Smaller dialog.
  454. this.getModalDialog().removeClass('modal-sm');
  455. if (this.getSize() === BootstrapDialog.SIZE_SMALL) {
  456. this.getModalDialog().addClass('modal-sm');
  457. }
  458. // Wider dialog.
  459. this.getModalDialog().removeClass('modal-lg');
  460. if (this.getSize() === BootstrapDialog.SIZE_WIDE) {
  461. this.getModalDialog().addClass('modal-lg');
  462. }
  463. // Button size
  464. $.each(this.options.buttons, function(index, button) {
  465. var $button = dialog.getButton(button.id);
  466. var buttonSizes = ['btn-lg', 'btn-sm', 'btn-xs'];
  467. var sizeClassSpecified = false;
  468. if (typeof button['cssClass'] === 'string') {
  469. var btnClasses = button['cssClass'].split(' ');
  470. $.each(btnClasses, function(index, btnClass) {
  471. if ($.inArray(btnClass, buttonSizes) !== -1) {
  472. sizeClassSpecified = true;
  473. }
  474. });
  475. }
  476. if (!sizeClassSpecified) {
  477. $button.removeClass(buttonSizes.join(' '));
  478. $button.addClass(dialog.getButtonSize());
  479. }
  480. });
  481. }
  482. return this;
  483. },
  484. getCssClass: function() {
  485. return this.options.cssClass;
  486. },
  487. setCssClass: function(cssClass) {
  488. this.options.cssClass = cssClass;
  489. return this;
  490. },
  491. getTitle: function() {
  492. return this.options.title;
  493. },
  494. setTitle: function(title) {
  495. this.options.title = title;
  496. this.updateTitle();
  497. return this;
  498. },
  499. updateTitle: function() {
  500. if (this.isRealized()) {
  501. var title = this.getTitle() !== null ? this.createDynamicContent(this.getTitle()) : this.getDefaultText();
  502. this.getModalHeader().find('.' + this.getNamespace('title')).html('').append(title).prop('id', this.getId() + '_title');
  503. }
  504. return this;
  505. },
  506. getMessage: function() {
  507. return this.options.message;
  508. },
  509. setMessage: function(message) {
  510. this.options.message = message;
  511. this.updateMessage();
  512. return this;
  513. },
  514. //增加URL
  515. getUrl: function() {
  516. return this.options.url;
  517. },
  518. getHeight: function() {
  519. return this.options.height?this.options.height:$(window).height()-140;
  520. },
  521. getWidth: function() {
  522. return this.options.width?this.options.width:0;
  523. },
  524. get:function(key){
  525. return this.options[key];
  526. },
  527. updateMessage: function() {
  528. if (this.isRealized()) {
  529. var url = this.getUrl(),
  530. message = this.createDynamicContent(this.getMessage());
  531. if(url){
  532. var $iframe = $("<iframe frameborder='0'></iframe>"),
  533. id= this.getId(),
  534. framename = "BootstrapDialog_" + id;
  535. $iframe.attr("name", framename);
  536. $iframe.attr("id",framename);
  537. $iframe[0].dialog = this;//增加窗口对dialog对象的引用
  538. $iframe[0].dialog.callback = this.options.callback;//回调
  539. $iframe[0].dialog.params = this.options.params;//传递的参数
  540. //可以在子窗口这样使用:
  541. // var dialog = frameElement.dialog;
  542. // dialog.close();//关闭dialog
  543. $iframe.attr("src", url);
  544. $iframe.attr("width","100%");
  545. $iframe.attr("height",this.getHeight());
  546. this.getModalBody().addClass("iframe-dialog");//对iframe的边框处理
  547. if(this.getWidth() >0 )
  548. this.getModalDialog().css("width",this.getWidth());
  549. //把页面赋值给展示的页面
  550. message = $iframe;
  551. }
  552. else if(this.options.target){
  553. //把原来的复制一份
  554. message = $(this.options.target).clone(true,true);
  555. //调用事件
  556. if(this.options.initEvent){
  557. this.options.initEvent(message);
  558. }
  559. }
  560. this.getModalBody().find('.' + this.getNamespace('message')).html('').append(message);
  561. }
  562. return this;
  563. },
  564. isClosable: function() {
  565. return this.options.closable;
  566. },
  567. setClosable: function(closable) {
  568. this.options.closable = closable;
  569. this.updateClosable();
  570. return this;
  571. },
  572. setCloseByBackdrop: function(closeByBackdrop) {
  573. this.options.closeByBackdrop = closeByBackdrop;
  574. return this;
  575. },
  576. canCloseByBackdrop: function() {
  577. return this.options.closeByBackdrop;
  578. },
  579. setCloseByKeyboard: function(closeByKeyboard) {
  580. this.options.closeByKeyboard = closeByKeyboard;
  581. return this;
  582. },
  583. canCloseByKeyboard: function() {
  584. return this.options.closeByKeyboard;
  585. },
  586. isAnimate: function() {
  587. return this.options.animate;
  588. },
  589. setAnimate: function(animate) {
  590. this.options.animate = animate;
  591. return this;
  592. },
  593. updateAnimate: function() {
  594. if (this.isRealized()) {
  595. this.getModal().toggleClass('fade', this.isAnimate());
  596. }
  597. return this;
  598. },
  599. getSpinicon: function() {
  600. return this.options.spinicon;
  601. },
  602. setSpinicon: function(spinicon) {
  603. this.options.spinicon = spinicon;
  604. return this;
  605. },
  606. addButton: function(button) {
  607. this.options.buttons.push(button);
  608. return this;
  609. },
  610. addButtons: function(buttons) {
  611. var that = this;
  612. $.each(buttons, function(index, button) {
  613. that.addButton(button);
  614. });
  615. return this;
  616. },
  617. getButtons: function() {
  618. return this.options.buttons;
  619. },
  620. setButtons: function(buttons) {
  621. this.options.buttons = buttons;
  622. this.updateButtons();
  623. return this;
  624. },
  625. /**
  626. * If there is id provided for a button option, it will be in dialog.indexedButtons list.
  627. *
  628. * In that case you can use dialog.getButton(id) to find the button.
  629. *
  630. * @param {type} id
  631. * @returns {undefined}
  632. */
  633. getButton: function(id) {
  634. if (typeof this.indexedButtons[id] !== 'undefined') {
  635. return this.indexedButtons[id];
  636. }
  637. return null;
  638. },
  639. getButtonSize: function() {
  640. if (typeof BootstrapDialog.BUTTON_SIZES[this.getSize()] !== 'undefined') {
  641. return BootstrapDialog.BUTTON_SIZES[this.getSize()];
  642. }
  643. return '';
  644. },
  645. updateButtons: function() {
  646. if (this.isRealized()) {
  647. if (this.getButtons().length === 0) {
  648. this.getModalFooter().hide();
  649. } else {
  650. this.getModalFooter().show().find('.' + this.getNamespace('footer')).html('').append(this.createFooterButtons());
  651. }
  652. }
  653. return this;
  654. },
  655. isAutodestroy: function() {
  656. return this.options.autodestroy;
  657. },
  658. setAutodestroy: function(autodestroy) {
  659. this.options.autodestroy = autodestroy;
  660. },
  661. getDescription: function() {
  662. return this.options.description;
  663. },
  664. setDescription: function(description) {
  665. this.options.description = description;
  666. return this;
  667. },
  668. getDefaultText: function() {
  669. return BootstrapDialog.DEFAULT_TEXTS[this.getType()];
  670. },
  671. getNamespace: function(name) {
  672. return BootstrapDialog.NAMESPACE + '-' + name;
  673. },
  674. createHeaderContent: function() {
  675. var $container = $('<div></div>');
  676. $container.addClass(this.getNamespace('header'));
  677. // title
  678. $container.append(this.createTitleContent());
  679. // Close button
  680. $container.prepend(this.createCloseButton());
  681. return $container;
  682. },
  683. createTitleContent: function() {
  684. var $title = $('<div></div>');
  685. $title.addClass(this.getNamespace('title'));
  686. return $title;
  687. },
  688. createCloseButton: function() {
  689. var $container = $('<div></div>');
  690. $container.addClass(this.getNamespace('close-button'));
  691. var $icon = $('<button class="close">&times;</button>');
  692. $container.append($icon);
  693. $container.on('click', {dialog: this}, function(event) {
  694. event.data.dialog.close();
  695. });
  696. return $container;
  697. },
  698. createBodyContent: function() {
  699. var $container = $('<div></div>');
  700. $container.addClass(this.getNamespace('body'));
  701. // Message
  702. $container.append(this.createMessageContent());
  703. return $container;
  704. },
  705. createMessageContent: function() {
  706. var $message = $('<div></div>');
  707. $message.addClass(this.getNamespace('message'));
  708. return $message;
  709. },
  710. createFooterContent: function() {
  711. var $container = $('<div></div>');
  712. $container.addClass(this.getNamespace('footer'));
  713. return $container;
  714. },
  715. createFooterButtons: function() {
  716. var that = this;
  717. var $container = $('<div></div>');
  718. $container.addClass(this.getNamespace('footer-buttons'));
  719. this.indexedButtons = {};
  720. $.each(this.options.buttons, function(index, button) {
  721. if (!button.id) {
  722. button.id = BootstrapDialog.newGuid();
  723. }
  724. var $button = that.createButton(button);
  725. that.indexedButtons[button.id] = $button;
  726. $container.append($button);
  727. });
  728. return $container;
  729. },
  730. createButton: function(button) {
  731. var $button = $('<button class="btn"></button>');
  732. $button.prop('id', button.id);
  733. $button.data('button', button);
  734. // Icon
  735. if (typeof button.icon !== 'undefined' && $.trim(button.icon) !== '') {
  736. $button.append(this.createButtonIcon(button.icon));
  737. }
  738. // Label
  739. if (typeof button.label !== 'undefined') {
  740. $button.append(button.label);
  741. }
  742. // Css class
  743. if (typeof button.cssClass !== 'undefined' && $.trim(button.cssClass) !== '') {
  744. $button.addClass(button.cssClass);
  745. } else {
  746. $button.addClass('btn-default');
  747. }
  748. // Hotkey
  749. if (typeof button.hotkey !== 'undefined') {
  750. this.registeredButtonHotkeys[button.hotkey] = $button;
  751. }
  752. // Button on click
  753. $button.on('click', {dialog: this, $button: $button, button: button}, function(event) {
  754. var dialog = event.data.dialog;
  755. var $button = event.data.$button;
  756. var button = $button.data('button');
  757. if (typeof button.action === 'function') {
  758. button.action.call($button, dialog, event);
  759. }
  760. if (button.autospin) {
  761. $button.toggleSpin(true);
  762. }
  763. });
  764. // Dynamically add extra functions to $button
  765. this.enhanceButton($button);
  766. return $button;
  767. },
  768. /**
  769. * Dynamically add extra functions to $button
  770. *
  771. * Using '$this' to reference 'this' is just for better readability.
  772. *
  773. * @param {type} $button
  774. * @returns {_L13.BootstrapDialog.prototype}
  775. */
  776. enhanceButton: function($button) {
  777. $button.dialog = this;
  778. // Enable / Disable
  779. $button.toggleEnable = function(enable) {
  780. var $this = this;
  781. if (typeof enable !== 'undefined') {
  782. $this.prop("disabled", !enable).toggleClass('disabled', !enable);
  783. } else {
  784. $this.prop("disabled", !$this.prop("disabled"));
  785. }
  786. return $this;
  787. };
  788. $button.enable = function() {
  789. var $this = this;
  790. $this.toggleEnable(true);
  791. return $this;
  792. };
  793. $button.disable = function() {
  794. var $this = this;
  795. $this.toggleEnable(false);
  796. return $this;
  797. };
  798. // Icon spinning, helpful for indicating ajax loading status.
  799. $button.toggleSpin = function(spin) {
  800. var $this = this;
  801. var dialog = $this.dialog;
  802. var $icon = $this.find('.' + dialog.getNamespace('button-icon'));
  803. if (typeof spin === 'undefined') {
  804. spin = !($button.find('.icon-spin').length > 0);
  805. }
  806. if (spin) {
  807. $icon.hide();
  808. $button.prepend(dialog.createButtonIcon(dialog.getSpinicon()).addClass('icon-spin'));
  809. } else {
  810. $icon.show();
  811. $button.find('.icon-spin').remove();
  812. }
  813. return $this;
  814. };
  815. $button.spin = function() {
  816. var $this = this;
  817. $this.toggleSpin(true);
  818. return $this;
  819. };
  820. $button.stopSpin = function() {
  821. var $this = this;
  822. $this.toggleSpin(false);
  823. return $this;
  824. };
  825. return this;
  826. },
  827. createButtonIcon: function(icon) {
  828. var $icon = $('<span></span>');
  829. $icon.addClass(this.getNamespace('button-icon')).addClass(icon);
  830. return $icon;
  831. },
  832. /**
  833. * Invoke this only after the dialog is realized.
  834. *
  835. * @param {type} enable
  836. * @returns {undefined}
  837. */
  838. enableButtons: function(enable) {
  839. $.each(this.indexedButtons, function(id, $button) {
  840. $button.toggleEnable(enable);
  841. });
  842. return this;
  843. },
  844. /**
  845. * Invoke this only after the dialog is realized.
  846. *
  847. * @returns {undefined}
  848. */
  849. updateClosable: function() {
  850. if (this.isRealized()) {
  851. // Close button
  852. this.getModalHeader().find('.' + this.getNamespace('close-button')).toggle(this.isClosable());
  853. }
  854. return this;
  855. },
  856. /**
  857. * Set handler for modal event 'show.bs.modal'.
  858. * This is a setter!
  859. */
  860. onShow: function(onshow) {
  861. this.options.onshow = onshow;
  862. return this;
  863. },
  864. /**
  865. * Set handler for modal event 'shown.bs.modal'.
  866. * This is a setter!
  867. */
  868. onShown: function(onshown) {
  869. this.options.onshown = onshown;
  870. return this;
  871. },
  872. /**
  873. * Set handler for modal event 'hide.bs.modal'.
  874. * This is a setter!
  875. */
  876. onHide: function(onhide) {
  877. this.options.onhide = onhide;
  878. return this;
  879. },
  880. /**
  881. * Set handler for modal event 'hidden.bs.modal'.
  882. * This is a setter!
  883. */
  884. onHidden: function(onhidden) {
  885. this.options.onhidden = onhidden;
  886. return this;
  887. },
  888. isRealized: function() {
  889. return this.realized;
  890. },
  891. setRealized: function(realized) {
  892. this.realized = realized;
  893. return this;
  894. },
  895. isOpened: function() {
  896. return this.opened;
  897. },
  898. setOpened: function(opened) {
  899. this.opened = opened;
  900. return this;
  901. },
  902. handleModalEvents: function() {
  903. this.getModal().on('show.bs.modal', {dialog: this}, function(event) {
  904. var dialog = event.data.dialog;
  905. dialog.setOpened(true);
  906. if (dialog.isModalEvent(event) && typeof dialog.options.onshow === 'function') {
  907. var openIt = dialog.options.onshow(dialog);
  908. if (openIt === false) {
  909. dialog.setOpened(false);
  910. }
  911. return openIt;
  912. }
  913. });
  914. this.getModal().on('shown.bs.modal', {dialog: this}, function(event) {
  915. var dialog = event.data.dialog;
  916. dialog.isModalEvent(event) && typeof dialog.options.onshown === 'function' && dialog.options.onshown(dialog);
  917. });
  918. this.getModal().on('hide.bs.modal', {dialog: this}, function(event) {
  919. var dialog = event.data.dialog;
  920. dialog.setOpened(false);
  921. if (dialog.isModalEvent(event) && typeof dialog.options.onhide === 'function') {
  922. var hideIt = dialog.options.onhide(dialog);
  923. if (hideIt === false) {
  924. dialog.setOpened(true);
  925. }
  926. return hideIt;
  927. }
  928. });
  929. this.getModal().on('hidden.bs.modal', {dialog: this}, function(event) {
  930. var dialog = event.data.dialog;
  931. dialog.isModalEvent(event) && typeof dialog.options.onhidden === 'function' && dialog.options.onhidden(dialog);
  932. if (dialog.isAutodestroy()) {
  933. delete BootstrapDialog.dialogs[dialog.getId()];
  934. $(this).remove();
  935. }
  936. BootstrapDialog.moveFocus();
  937. });
  938. // Backdrop, I did't find a way to change bs3 backdrop option after the dialog is popped up, so here's a new wheel.
  939. this.handleModalBackdropEvent();
  940. // ESC key support
  941. this.getModal().on('keyup', {dialog: this}, function(event) {
  942. event.which === 27 && event.data.dialog.isClosable() && event.data.dialog.canCloseByKeyboard() && event.data.dialog.close();
  943. });
  944. // Button hotkey
  945. this.getModal().on('keyup', {dialog: this}, function(event) {
  946. var dialog = event.data.dialog;
  947. if (typeof dialog.registeredButtonHotkeys[event.which] !== 'undefined') {
  948. var $button = $(dialog.registeredButtonHotkeys[event.which]);
  949. !$button.prop('disabled') && $button.focus().trigger('click');
  950. }
  951. });
  952. return this;
  953. },
  954. handleModalBackdropEvent: function() {
  955. this.getModal().on('click', {dialog: this}, function(event) {
  956. $(event.target).hasClass('modal-backdrop') && event.data.dialog.isClosable() && event.data.dialog.canCloseByBackdrop() && event.data.dialog.close();
  957. });
  958. return this;
  959. },
  960. isModalEvent: function(event) {
  961. return typeof event.namespace !== 'undefined' && event.namespace === 'bs.modal';
  962. },
  963. makeModalDraggable: function() {
  964. if (this.options.draggable) {
  965. this.getModalHeader().addClass(this.getNamespace('draggable')).on('mousedown', {dialog: this}, function(event) {
  966. var dialog = event.data.dialog;
  967. dialog.draggableData.isMouseDown = true;
  968. var dialogOffset = dialog.getModalDialog().offset();
  969. dialog.draggableData.mouseOffset = {
  970. top: event.clientY - dialogOffset.top,
  971. left: event.clientX - dialogOffset.left
  972. };
  973. });
  974. this.getModal().on('mouseup mouseleave', {dialog: this}, function(event) {
  975. event.data.dialog.draggableData.isMouseDown = false;
  976. });
  977. $('body').on('mousemove', {dialog: this}, function(event) {
  978. var dialog = event.data.dialog;
  979. if (!dialog.draggableData.isMouseDown) {
  980. return;
  981. }
  982. dialog.getModalDialog().offset({
  983. top: event.clientY - dialog.draggableData.mouseOffset.top,
  984. left: event.clientX - dialog.draggableData.mouseOffset.left
  985. });
  986. });
  987. }
  988. return this;
  989. },
  990. realize: function() {
  991. this.initModalStuff();
  992. this.getModal().addClass(BootstrapDialog.NAMESPACE)
  993. .addClass(this.getCssClass());
  994. this.updateSize();
  995. if (this.getDescription()) {
  996. this.getModal().attr('aria-describedby', this.getDescription());
  997. }
  998. this.getModalFooter().append(this.createFooterContent());
  999. this.getModalHeader().append(this.createHeaderContent());
  1000. this.getModalBody().append(this.createBodyContent());
  1001. this.getModal().data('bs.modal', new BootstrapDialogModal(this.getModal(), {
  1002. backdrop: 'static',
  1003. keyboard: false,
  1004. show: false
  1005. }));
  1006. this.makeModalDraggable();
  1007. this.handleModalEvents();
  1008. this.setRealized(true);
  1009. this.updateButtons();
  1010. this.updateType();
  1011. this.updateTitle();
  1012. this.updateMessage();
  1013. this.updateClosable();
  1014. this.updateAnimate();
  1015. this.updateSize();
  1016. return this;
  1017. },
  1018. /**
  1019. * 创建个ifrme,遮盖整个窗口,遮盖office控件
  1020. */
  1021. createIframe:function(){
  1022. var iframeObj=$('<iframe frameborder="0" class="bootstrap_dialog_frame" style="position:absolute;z-index:1;position:absolute; visibility:inherit; top:0px; left:0px;"></iframe>');
  1023. iframeObj.css({width:$('body').width(),height:$('body').height()})
  1024. iframeObj.attr("iframeId",this.getId());
  1025. iframeObj.appendTo('body');
  1026. },
  1027. /**
  1028. * 删除ifrme窗口
  1029. */
  1030. removeIframe:function(){
  1031. $('.bootstrap_dialog_frame[iframeId='+this.getId()+']').remove();
  1032. },
  1033. open: function() {
  1034. !this.isRealized() && this.realize();
  1035. this.getModal().modal('show');
  1036. this.setOpened(true);
  1037. this.createIframe();
  1038. return this;
  1039. },
  1040. close: function() {
  1041. if (this.isAutodestroy()) {
  1042. delete BootstrapDialog.dialogs[this.getId()];
  1043. }
  1044. this.getModal().modal('hide');
  1045. this.setOpened(false);
  1046. this.removeIframe();
  1047. return this;
  1048. }
  1049. };
  1050. // Add compatible methods.
  1051. BootstrapDialog.prototype = $.extend(BootstrapDialog.prototype, BootstrapDialog.METHODS_TO_OVERRIDE[BootstrapDialogModal.getModalVersion()]);
  1052. /**
  1053. * RFC4122 version 4 compliant unique id creator.
  1054. *
  1055. * Added by https://github.com/tufanbarisyildirim/
  1056. *
  1057. * @returns {String}
  1058. */
  1059. BootstrapDialog.newGuid = function() {
  1060. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  1061. var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
  1062. return v.toString(16);
  1063. });
  1064. };
  1065. /* ================================================
  1066. * For lazy people
  1067. * ================================================ */
  1068. /**
  1069. * Shortcut function: show
  1070. *
  1071. * @param {type} options
  1072. * @returns the created dialog instance
  1073. */
  1074. BootstrapDialog.show = function(options) {
  1075. return new BootstrapDialog(options).open();
  1076. };
  1077. /**
  1078. * Alert window
  1079. *
  1080. * @returns the created dialog instance
  1081. */
  1082. BootstrapDialog.alert = function() {
  1083. var options = {};
  1084. var defaultOptions = {
  1085. type: BootstrapDialog.TYPE_PRIMARY,
  1086. title: null,
  1087. message: null,
  1088. closable: true,
  1089. buttonLabel: BootstrapDialog.DEFAULT_TEXTS.OK,
  1090. callback: null
  1091. };
  1092. if (typeof arguments[0] === 'object' ) {
  1093. options = $.extend(true, defaultOptions, arguments[0]);
  1094. } else {
  1095. options = $.extend(true, defaultOptions, {
  1096. message: arguments[0],
  1097. closable: false,
  1098. buttonLabel: BootstrapDialog.DEFAULT_TEXTS.OK,
  1099. callback: typeof arguments[1] !== 'undefined' ? arguments[1] : null
  1100. });
  1101. }
  1102. return new BootstrapDialog({
  1103. type: options.type,
  1104. title: options.title,
  1105. message: options.message,
  1106. closable: options.closable,
  1107. draggable: options.draggable,
  1108. data: {
  1109. callback: options.callback
  1110. },
  1111. onhide: function(dialog) {
  1112. !dialog.getData('btnClicked') && dialog.isClosable() && typeof dialog.getData('callback') === 'function' && dialog.getData('callback')(false);
  1113. },
  1114. buttons: [{
  1115. label: options.buttonLabel,
  1116. cssClass: 'btn-primary',
  1117. action: function(dialog) {
  1118. dialog.setData('btnClicked', true);
  1119. typeof dialog.getData('callback') === 'function' && dialog.getData('callback')(true);
  1120. dialog.close();
  1121. }
  1122. }]
  1123. }).open();
  1124. };
  1125. /**
  1126. * Confirm window
  1127. *
  1128. * @returns the created dialog instance
  1129. */
  1130. BootstrapDialog.confirm = function() {
  1131. var options = {};
  1132. var defaultOptions = {
  1133. type: BootstrapDialog.TYPE_PRIMARY,
  1134. title: BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_DEFAULT],
  1135. message: null,
  1136. closable: true,
  1137. buttons: [{
  1138. label: BootstrapDialog.DEFAULT_TEXTS.CANCEL,
  1139. action: function(dialog) {
  1140. typeof dialog.getData('callback') === 'function' && dialog.getData('callback')(false);
  1141. dialog.close();
  1142. }
  1143. }, {
  1144. label: BootstrapDialog.DEFAULT_TEXTS.OK,
  1145. cssClass: 'btn-primary',
  1146. action: function(dialog) {
  1147. typeof dialog.getData('callback') === 'function' && dialog.getData('callback')(true);
  1148. dialog.close();
  1149. }
  1150. }],
  1151. callback: null
  1152. };
  1153. if (typeof arguments[0] === 'object') {
  1154. options = $.extend(true, defaultOptions, arguments[0]);
  1155. } else {
  1156. var title = BootstrapDialog.DEFAULT_TEXTS[BootstrapDialog.TYPE_DEFAULT],
  1157. callback = null,
  1158. buttons = [{
  1159. label: BootstrapDialog.DEFAULT_TEXTS.CANCEL
  1160. }, {
  1161. label: BootstrapDialog.DEFAULT_TEXTS.OK
  1162. }];
  1163. if(arguments.length == 2){
  1164. if (typeof (arguments[1]) == "function") callback = arguments[1];
  1165. if (typeof (arguments[1]) == "string") title = arguments[1];
  1166. }
  1167. if(arguments.length == 3){
  1168. if (typeof (arguments[1]) == "function") callback = arguments[1];
  1169. if (typeof (arguments[1]) == "string") title = arguments[1];
  1170. if (typeof (arguments[2]) == "function") callback = arguments[2];
  1171. }
  1172. if(arguments.length == 4){
  1173. if (typeof (arguments[1]) == "function") callback = arguments[1];
  1174. if (typeof (arguments[1]) == "string") title = arguments[1];
  1175. if (typeof (arguments[2]) == "function") callback = arguments[2];
  1176. if(arguments[3]){
  1177. buttons = [{
  1178. label: BootstrapDialog.DEFAULT_TEXTS.NO
  1179. }, {
  1180. label: BootstrapDialog.DEFAULT_TEXTS.YES
  1181. }];
  1182. }
  1183. }
  1184. options = $.extend(true, defaultOptions, {
  1185. message: arguments[0],
  1186. closable: false,
  1187. callback: callback,
  1188. title:title,
  1189. buttons:buttons
  1190. });
  1191. }
  1192. return new BootstrapDialog({
  1193. title: options.title,
  1194. message: options.message,
  1195. closable: options.closable,
  1196. data: {
  1197. callback: options.callback
  1198. },
  1199. buttons:options.buttons
  1200. }).open();
  1201. };
  1202. /**
  1203. * Warning window
  1204. *
  1205. * @param {type} message
  1206. * @returns the created dialog instance
  1207. */
  1208. BootstrapDialog.warning = function(message, callback) {
  1209. return new BootstrapDialog({
  1210. type: BootstrapDialog.TYPE_WARNING,
  1211. message: message
  1212. }).open();
  1213. };
  1214. /**
  1215. * Danger window
  1216. *
  1217. * @param {type} message
  1218. * @returns the created dialog instance
  1219. */
  1220. BootstrapDialog.danger = function(message, callback) {
  1221. return new BootstrapDialog({
  1222. type: BootstrapDialog.TYPE_DANGER,
  1223. message: message
  1224. }).open();
  1225. };
  1226. /**
  1227. * Success window
  1228. *
  1229. * @param {type} message
  1230. * @returns the created dialog instance
  1231. */
  1232. BootstrapDialog.success = function(message, callback) {
  1233. return new BootstrapDialog({
  1234. type: BootstrapDialog.TYPE_SUCCESS,
  1235. message: message
  1236. }).open();
  1237. };
  1238. var waittingDialog = null;
  1239. /**
  1240. * Waitting window
  1241. *
  1242. * @param {type} message
  1243. * @returns the created dialog instance
  1244. */
  1245. BootstrapDialog.waitting = function(message, callback) {
  1246. if(waittingDialog)
  1247. waittingDialog.close();
  1248. message =message?message:'加载中...';
  1249. waittingDialog = new BootstrapDialog({
  1250. title:null,
  1251. size:BootstrapDialog.SIZE_SMALL,
  1252. closable:false,
  1253. closeByBackdrop: false,
  1254. message: '<div ><i class=" fa fa-spinner fa-spin fa-2x orange "></i>&nbsp;'+message+'</div>'
  1255. }).open();
  1256. waittingDialog.getModalHeader().hide();
  1257. return waittingDialog;
  1258. };
  1259. /**
  1260. * Close waitting window
  1261. *
  1262. * @param {type} message
  1263. * @returns the created dialog instance
  1264. */
  1265. BootstrapDialog.closeWaitting = function() {
  1266. if(waittingDialog)
  1267. waittingDialog.close();
  1268. };
  1269. return BootstrapDialog;
  1270. }));