Browse Source

Giving dialog an ID.
Store dialog instances in array BootstrapDialog.dialogs.
Added functions BootstrapDialog.openAll() and BootstrapDialog.closeAll().

Dante 12 years ago
parent
commit
d8f07c3c0e
3 changed files with 55 additions and 3 deletions
  1. 1 0
      examples/assets/prettify/prettify.css
  2. 1 0
      examples/index.html
  3. 53 3
      js/bootstrap-dialog.js

File diff suppressed because it is too large
+ 1 - 0
examples/assets/prettify/prettify.css


+ 1 - 0
examples/index.html

@@ -5,6 +5,7 @@
 <link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
 <script src="assets/bootstrap/js/bootstrap.min.js"></script>
 <script src="assets/prettify/run_prettify.js"></script>
+<link href="assets/prettify/prettify.css" rel="stylesheet" type="text/css" />
 <link href="../css/bootstrap-dialog.css" rel="stylesheet" type="text/css" />
 <script src="../js/bootstrap-dialog.js"></script>
 <meta charset="utf-8" />

+ 53 - 3
js/bootstrap-dialog.js

@@ -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
      * ================================================ */