Browse Source

Improved onshow and onhide

Dante 11 years ago
parent
commit
1260702f61

+ 6 - 2
dist/js/bootstrap-dialog.js

@@ -656,8 +656,10 @@
         handleModalEvents: function() {
             this.getModal().on('show.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;
-                typeof dialog.options.onshow === 'function' && dialog.options.onshow(dialog);
                 dialog.showPageScrollBar(true);
+                if (typeof dialog.options.onshow === 'function') {
+                    return dialog.options.onshow(dialog);
+                }
             });
             this.getModal().on('shown.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;
@@ -666,7 +668,9 @@
             });
             this.getModal().on('hide.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;
-                typeof dialog.options.onhide === 'function' && dialog.options.onhide(dialog);
+                if (typeof dialog.options.onhide === 'function') {
+                    return dialog.options.onhide(dialog);
+                }
             });
             this.getModal().on('hidden.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;

File diff suppressed because it is too large
+ 1 - 1
dist/js/bootstrap-dialog.min.js


+ 6 - 2
examples/assets/bootstrap-dialog/js/bootstrap-dialog.js

@@ -656,8 +656,10 @@
         handleModalEvents: function() {
             this.getModal().on('show.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;
-                typeof dialog.options.onshow === 'function' && dialog.options.onshow(dialog);
                 dialog.showPageScrollBar(true);
+                if (typeof dialog.options.onshow === 'function') {
+                    return dialog.options.onshow(dialog);
+                }
             });
             this.getModal().on('shown.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;
@@ -666,7 +668,9 @@
             });
             this.getModal().on('hide.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;
-                typeof dialog.options.onhide === 'function' && dialog.options.onhide(dialog);
+                if (typeof dialog.options.onhide === 'function') {
+                    return dialog.options.onhide(dialog);
+                }
             });
             this.getModal().on('hidden.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;

File diff suppressed because it is too large
+ 1 - 1
examples/assets/bootstrap-dialog/js/bootstrap-dialog.min.js


+ 27 - 0
examples/index.html

@@ -639,6 +639,33 @@
         -->
     </div>
     
+    <a name="stop-closing-dialog"></a>
+    <h3>Stop closing your dialog.</h3>
+    <p>
+        Option 'onhide' gives you an opportunity to stop closing the dialog according to some conditions, making your 'onhide' callback returns false to stop closing the dialog. <br />
+        In the following example, the dialog closes only when your most favorite fruit is '<strong>banana</strong>' (Case insensitive).
+    </p>
+    <div class="source-code runnable">
+        <!--
+        BootstrapDialog.show({
+            message: 'Your most favorite fruit: <input type="text" class="form-control">',
+            onhide: function(dialogRef){
+                var fruit = dialogRef.getModalBody().find('input').val();
+                if($.trim(fruit.toLowerCase()) !== 'banana') {
+                    alert('Need banana!');
+                    return false;
+                }
+            },
+            buttons: [{
+                label: 'Close',
+                action: function(dialogRef) {
+                    dialogRef.close();
+                }
+            }]
+        });
+        -->
+    </div>
+    
     <h2>More shortcut methods</h2>
     <hr />
     <h3>Alert</h3>

+ 6 - 2
js/bootstrap-dialog.js

@@ -656,8 +656,10 @@
         handleModalEvents: function() {
             this.getModal().on('show.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;
-                typeof dialog.options.onshow === 'function' && dialog.options.onshow(dialog);
                 dialog.showPageScrollBar(true);
+                if (typeof dialog.options.onshow === 'function') {
+                    return dialog.options.onshow(dialog);
+                }
             });
             this.getModal().on('shown.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;
@@ -666,7 +668,9 @@
             });
             this.getModal().on('hide.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;
-                typeof dialog.options.onhide === 'function' && dialog.options.onhide(dialog);
+                if (typeof dialog.options.onhide === 'function') {
+                    return dialog.options.onhide(dialog);
+                }
             });
             this.getModal().on('hidden.bs.modal', {dialog: this}, function(event) {
                 var dialog = event.data.dialog;

File diff suppressed because it is too large
+ 1 - 1
js/bootstrap-dialog.min.js