bootstrap-dialog.js 47 KB

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