|
|
@@ -1,5 +1,5 @@
|
|
|
/* ================================================
|
|
|
- * Make use of Twitter Bootstrap's modal more monkey-friendly
|
|
|
+ * Make use of Twitter Bootstrap's modal more monkey-friendly.
|
|
|
*
|
|
|
* For Bootstrap 3.
|
|
|
*
|
|
|
@@ -13,6 +13,7 @@ var BootstrapDialog = null;
|
|
|
|
|
|
BootstrapDialog = function(options) {
|
|
|
this.defaultOptions = {
|
|
|
+ id: BootstrapDialog.newGuid(),
|
|
|
type: BootstrapDialog.TYPE_PRIMARY,
|
|
|
size: BootstrapDialog.SIZE_NORMAL,
|
|
|
title: null,
|
|
|
@@ -28,8 +29,12 @@ var BootstrapDialog = null;
|
|
|
this.indexedButtons = {};
|
|
|
this.realized = false;
|
|
|
this.initOptions(options);
|
|
|
+ this.holdThisInstance();
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * Some constants.
|
|
|
+ */
|
|
|
BootstrapDialog.NAMESPACE = 'bootstrap-dialog';
|
|
|
|
|
|
BootstrapDialog.TYPE_DEFAULT = 'type-default';
|
|
|
@@ -56,6 +61,21 @@ var BootstrapDialog = null;
|
|
|
|
|
|
BootstrapDialog.ICON_SPINNER = 'glyphicon glyphicon-asterisk';
|
|
|
|
|
|
+ /**
|
|
|
+ * Open / Close all created dialogs all at once.
|
|
|
+ */
|
|
|
+ BootstrapDialog.dialogs = {};
|
|
|
+ BootstrapDialog.openAll = function() {
|
|
|
+ $.each(BootstrapDialog.dialogs, function(id, dialogInstance) {
|
|
|
+ dialogInstance.open();
|
|
|
+ });
|
|
|
+ };
|
|
|
+ BootstrapDialog.closeAll = function() {
|
|
|
+ $.each(BootstrapDialog.dialogs, function(id, dialogInstance) {
|
|
|
+ dialogInstance.close();
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
BootstrapDialog.prototype = {
|
|
|
constructor: BootstrapDialog,
|
|
|
initOptions: function(options) {
|
|
|
@@ -63,6 +83,11 @@ var BootstrapDialog = null;
|
|
|
|
|
|
return this;
|
|
|
},
|
|
|
+ holdThisInstance: function() {
|
|
|
+ BootstrapDialog.dialogs[this.getId()] = this;
|
|
|
+
|
|
|
+ return this;
|
|
|
+ },
|
|
|
initModalStuff: function() {
|
|
|
this.setModal(this.createModal())
|
|
|
.setModalDialog(this.createModalDialog())
|
|
|
@@ -81,7 +106,7 @@ var BootstrapDialog = null;
|
|
|
return this;
|
|
|
},
|
|
|
createModal: function() {
|
|
|
- return $('<div class="modal fade" tabindex="-1"></div>');
|
|
|
+ return $('<div class="modal fade" tabindex="-1" id="' + this.getId() + '"></div>');
|
|
|
},
|
|
|
getModal: function() {
|
|
|
return this.$modal;
|
|
|
@@ -170,6 +195,14 @@ var BootstrapDialog = null;
|
|
|
getData: function(key) {
|
|
|
return this.options.data[key];
|
|
|
},
|
|
|
+ setId: function(id) {
|
|
|
+ this.options.id = id;
|
|
|
+
|
|
|
+ return this;
|
|
|
+ },
|
|
|
+ getId: function() {
|
|
|
+ return this.options.id;
|
|
|
+ },
|
|
|
getType: function() {
|
|
|
return this.options.type;
|
|
|
},
|
|
|
@@ -501,11 +534,28 @@ var BootstrapDialog = null;
|
|
|
},
|
|
|
close: function() {
|
|
|
this.getModal().modal('hide');
|
|
|
-
|
|
|
+ if(this.isAutodestroy()) {
|
|
|
+ delete BootstrapDialog.dialogs[this.getId()];
|
|
|
+ }
|
|
|
+
|
|
|
return this;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * RFC4122 version 4 compliant unique id creator.
|
|
|
+ *
|
|
|
+ * Added by https://github.com/tufanbarisyildirim/
|
|
|
+ *
|
|
|
+ * @returns {String}
|
|
|
+ */
|
|
|
+ BootstrapDialog.newGuid = function() {
|
|
|
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
|
+ var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
|
+ return v.toString(16);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
/* ================================================
|
|
|
* For lazy people
|
|
|
* ================================================ */
|