Skip to content

Commit

Permalink
Two more events are supported: onshown, onhidden.
Browse files Browse the repository at this point in the history
  • Loading branch information
nakupanda committed Apr 10, 2014
1 parent ef5c97d commit e5def1f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 21 deletions.
38 changes: 29 additions & 9 deletions examples/assets/bootstrap-dialog/js/bootstrap-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
buttons: [],
data: {},
onshow: null,
onhide: null
onshown: null,
onhide: null,
onhidden: null
}, BootstrapDialog.defaultOptions);
this.indexedButtons = {};
this.registeredButtonHotkeys = {};
Expand Down Expand Up @@ -582,29 +584,41 @@
return this;
},
/**
* Set handler for modal event 'show'.
* Set handler for modal event 'show.bs.modal'.
* This is a setter!
*
* @param {type} onopen
* @returns {_L9.BootstrapDialog.prototype}
*/
onShow: function(onshow) {
this.options.onshow = onshow;

return this;
},
/**
* Set handler for modal event 'hide'.
* Set handler for modal event 'shown.bs.modal'.
* This is a setter!
*/
onShown: function(onshown) {
this.options.onshown = onshown;

return this;
},
/**
* Set handler for modal event 'hide.bs.modal'.
* This is a setter!
*
* @param {type} onclose
* @returns {_L9.BootstrapDialog.prototype}
*/
onHide: function(onhide) {
this.options.onhide = onhide;

return this;
},
/**
* Set handler for modal event 'hidden.bs.modal'.
* This is a setter!
*/
onHidden: function(onhidden) {
this.options.onhidden = onhidden;

return this;
},
isRealized: function() {
return this.realized;
},
Expand All @@ -627,12 +641,18 @@
typeof dialog.options.onshow === 'function' && dialog.options.onshow(dialog);
dialog.showPageScrollBar(true);
});
this.getModal().on('shown.bs.modal', {dialog: this}, function(event) {
var dialog = event.data.dialog;
typeof dialog.options.onshown === 'function' && dialog.options.onshown(dialog);
dialog.showPageScrollBar(true);
});
this.getModal().on('hide.bs.modal', {dialog: this}, function(event) {
var dialog = event.data.dialog;
typeof dialog.options.onhide === 'function' && dialog.options.onhide(dialog);
});
this.getModal().on('hidden.bs.modal', {dialog: this}, function(event) {
var dialog = event.data.dialog;
typeof dialog.options.onhidden === 'function' && dialog.options.onhidden(dialog);
dialog.isAutodestroy() && $(this).remove();
dialog.showPageScrollBar(false);
});
Expand Down

Large diffs are not rendered by default.

25 changes: 24 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ <h3>Data binding</h3>

<h3>Dialog events</h3>
<p>
Two dialog level events are supported currently: onshow, onhide. <br />
Please note that if you're going to use setters to configure event handlers, use dialog.onShow(function) and dialog.onHide(function).
</p>
<div class="source-code runnable">
Expand All @@ -567,8 +566,14 @@ <h3>Dialog events</h3>
onshow: function(dialogRef){
alert('Dialog is popping up, its message is ' + dialogRef.getMessage());
},
onshown: function(dialogRef){
alert('Dialog is popped up.');
},
onhide: function(dialogRef){
alert('Dialog is popping down, its message is ' + dialogRef.getMessage());
},
onhidden: function(dialogRef){
alert('Dialog is popped down.');
}
});
-->
Expand Down Expand Up @@ -842,6 +847,15 @@ <h2>Available options</h2>
If provided, it will be invoked when the dialog is popping up. <br />
</td>
</tr>
<tr>
<td>onshown</td>
<td>
function
</td>
<td>
If provided, it will be invoked when the dialog is popped up. <br />
</td>
</tr>
<tr>
<td>onhide</td>
<td>
Expand All @@ -851,6 +865,15 @@ <h2>Available options</h2>
If provided, it will be invoked when the dialog is popping down. <br />
</td>
</tr>
<tr>
<td>onhidden</td>
<td>
function
</td>
<td>
If provided, it will be invoked when the dialog is popped down. <br />
</td>
</tr>
<tr>
<td>autodestroy</td>
<td>
Expand Down
38 changes: 29 additions & 9 deletions js/bootstrap-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
buttons: [],
data: {},
onshow: null,
onhide: null
onshown: null,
onhide: null,
onhidden: null
}, BootstrapDialog.defaultOptions);
this.indexedButtons = {};
this.registeredButtonHotkeys = {};
Expand Down Expand Up @@ -582,29 +584,41 @@
return this;
},
/**
* Set handler for modal event 'show'.
* Set handler for modal event 'show.bs.modal'.
* This is a setter!
*
* @param {type} onopen
* @returns {_L9.BootstrapDialog.prototype}
*/
onShow: function(onshow) {
this.options.onshow = onshow;

return this;
},
/**
* Set handler for modal event 'hide'.
* Set handler for modal event 'shown.bs.modal'.
* This is a setter!
*/
onShown: function(onshown) {
this.options.onshown = onshown;

return this;
},
/**
* Set handler for modal event 'hide.bs.modal'.
* This is a setter!
*
* @param {type} onclose
* @returns {_L9.BootstrapDialog.prototype}
*/
onHide: function(onhide) {
this.options.onhide = onhide;

return this;
},
/**
* Set handler for modal event 'hidden.bs.modal'.
* This is a setter!
*/
onHidden: function(onhidden) {
this.options.onhidden = onhidden;

return this;
},
isRealized: function() {
return this.realized;
},
Expand All @@ -627,12 +641,18 @@
typeof dialog.options.onshow === 'function' && dialog.options.onshow(dialog);
dialog.showPageScrollBar(true);
});
this.getModal().on('shown.bs.modal', {dialog: this}, function(event) {
var dialog = event.data.dialog;
typeof dialog.options.onshown === 'function' && dialog.options.onshown(dialog);
dialog.showPageScrollBar(true);
});
this.getModal().on('hide.bs.modal', {dialog: this}, function(event) {
var dialog = event.data.dialog;
typeof dialog.options.onhide === 'function' && dialog.options.onhide(dialog);
});
this.getModal().on('hidden.bs.modal', {dialog: this}, function(event) {
var dialog = event.data.dialog;
typeof dialog.options.onhidden === 'function' && dialog.options.onhidden(dialog);
dialog.isAutodestroy() && $(this).remove();
dialog.showPageScrollBar(false);
});
Expand Down
Loading

0 comments on commit e5def1f

Please sign in to comment.