Skip to content

Commit

Permalink
Improved onshow and onhide
Browse files Browse the repository at this point in the history
  • Loading branch information
nakupanda committed Jun 13, 2014
1 parent ae7f9ca commit 1260702
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 9 deletions.
8 changes: 6 additions & 2 deletions dist/js/bootstrap-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dist/js/bootstrap-dialog.min.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions examples/assets/bootstrap-dialog/js/bootstrap-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,33 @@ <h3>Dialog events</h3>
-->
</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>
Expand Down
8 changes: 6 additions & 2 deletions js/bootstrap-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion js/bootstrap-dialog.min.js

Large diffs are not rendered by default.

0 comments on commit 1260702

Please sign in to comment.