Browse Source

Code improvements.

Dante 12 years ago
parent
commit
d54e43c133
3 changed files with 46 additions and 21 deletions
  1. 31 0
      examples/hotkey.html
  2. 1 1
      examples/index.html
  3. 14 20
      js/bootstrap-dialog.js

+ 31 - 0
examples/hotkey.html

@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="assets/jquery/jquery-1.10.2.min.js"></script>
+<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/bootstrap-dialog/css/bootstrap-dialog.css" rel="stylesheet" type="text/css" />
+<script src="../js/bootstrap-dialog.js"></script>
+<meta charset="utf-8" />
+<title>BootstrapDialog examples</title>
+</head>
+<body style="padding-bottom: 100px;">
+    <script>
+        BootstrapDialog.show({
+            buttons: [{
+                    label: 'Cancel',
+                    action: function(dialog){
+                        alert('Canceling...');
+                    }
+            }, {
+                    label: 'Confirm',
+                    cssClass: 'btn-primary',
+                    action: function(dialog){
+                        alert('Confirming...');
+                    }
+            }]
+        });
+    </script>
+</body>
+</html>

+ 1 - 1
examples/index.html

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

+ 14 - 20
js/bootstrap-dialog.js

@@ -112,6 +112,7 @@ var BootstrapDialog = null;
         createModal: function() {
             var $modal = $('<div class="modal fade" tabindex="-1"></div>');
             $modal.prop('id', this.getId());
+            this.updateModalBackdrop($modal);
 
             return $modal;
         },
@@ -123,6 +124,19 @@ var BootstrapDialog = null;
 
             return this;
         },
+        updateModalBackdrop: function($modal) {
+            // Backdrop, I did't find a way to change bs3 backdrop option after the dialog is popped up, so here's a new wheel.
+            $modal.on('click', {dialog: this}, function(event) {
+                event.target === this && event.data.dialog.isClosable() && event.data.dialog.close();
+            });
+
+            // ESC key support
+            $modal.on('keyup', {dialog: this}, function(event) {
+                event.which === 27 && event.data.dialog.isClosable() && event.data.dialog.close();
+            });
+
+            return this;
+        },
         createModalDialog: function() {
             return $('<div class="modal-dialog"></div>');
         },
@@ -448,15 +462,6 @@ var BootstrapDialog = null;
                 }
             });
 
-            // Button hotKey
-            if (button.hotKey)
-                this.getModalDialog().on('keypress', function(event) {
-                    if (!event || !event.which)
-                        return;
-                    if (event.which === button.hotKey)
-                        $button.trigger('click');
-                });
-
             return $button;
         },
         /**
@@ -546,19 +551,8 @@ var BootstrapDialog = null;
          */
         updateClosable: function() {
             if (this.isRealized()) {
-                // Backdrop, I did't find a way to change bs3 backdrop option after the dialog is popped up, so here's a new wheel.
-                var $theBigMask = this.getModal();
-                $theBigMask.off('click').on('click', {dialog: this}, function(event) {
-                    event.target === this && event.data.dialog.isClosable() && event.data.dialog.close();
-                });
-
                 // Close button
                 this.getModalHeader().find('.' + this.getNamespace('close-button')).toggle(this.isClosable());
-
-                // ESC key support
-                $theBigMask.off('keyup').on('keyup', {dialog: this}, function(event) {
-                    event.which === 27 && event.data.dialog.isClosable() && event.data.dialog.close();
-                });
             }
 
             return this;