Skip to content

Commit

Permalink
Improve alert window, customizing title, type and more options are no…
Browse files Browse the repository at this point in the history
…w possible.
nakupanda committed Mar 4, 2014

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e483f86 commit 2af6b41
Showing 5 changed files with 85 additions and 16 deletions.
39 changes: 32 additions & 7 deletions examples/assets/bootstrap-dialog/js/bootstrap-dialog.js
Original file line number Diff line number Diff line change
@@ -734,20 +734,45 @@
/**
* Alert window
*
* @param {type} message
* @param {type} callback
* @returns the created dialog instance
*/
BootstrapDialog.alert = function(message, callback) {
BootstrapDialog.alert = function() {
var options = {};
var defaultOptions = {
type: BootstrapDialog.TYPE_PRIMARY,
title: null,
message: null,
closable: true,
buttonLabel: 'OK',
callback: null
};

if (typeof arguments[0] === 'object' && arguments[0].constructor === {}.constructor) {
options = $.extend(true, defaultOptions, arguments[0]);
} else {
options = $.extend(true, defaultOptions, {
message: arguments[0],
closable: false,
buttonLabel: 'OK',
callback: typeof arguments[1] !== 'undefined' ? arguments[1] : null
});
}

return new BootstrapDialog({
message: message,
type: options.type,
title: options.title,
message: options.message,
closable: options.closable,
data: {
'callback': callback
callback: options.callback
},
onhide: function(dialog) {
!dialog.getData('btnClicked') && dialog.isClosable() && typeof dialog.getData('callback') === 'function' && dialog.getData('callback')(false);
},
closable: false,
buttons: [{
label: 'OK',
label: options.buttonLabel,
action: function(dialog) {
dialog.setData('btnClicked', true);
typeof dialog.getData('callback') === 'function' && dialog.getData('callback')(true);
dialog.close();
}

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -592,6 +592,25 @@ <h3>Alert with callback</h3>
-->
</div>

<a name="advanced-alert-window"></a>
<h3>Customizing dialog type, title, and more.</h3>
<p>All options shown below are optional.</p>
<div class="source-code runnable">
<!--
BootstrapDialog.alert({
title: 'WARNING',
message: 'Warning! No Banana!',
type: BootstrapDialog.TYPE_WARNING, // <-- Default value is BootstrapDialog.TYPE_PRIMARY
closable: true, // <-- Default value is true
buttonLabel: 'Roar! Why!', // <-- Default value is 'OK',
callback: function(result) {
// result will be true if button was click, while it will be false if users close the dialog directly.
alert('Result is: ' + result);
}
});
-->
</div>

<h3>Confirm</h3>
<div class="source-code runnable">
<!--
39 changes: 32 additions & 7 deletions js/bootstrap-dialog.js
Original file line number Diff line number Diff line change
@@ -734,20 +734,45 @@
/**
* Alert window
*
* @param {type} message
* @param {type} callback
* @returns the created dialog instance
*/
BootstrapDialog.alert = function(message, callback) {
BootstrapDialog.alert = function() {
var options = {};
var defaultOptions = {
type: BootstrapDialog.TYPE_PRIMARY,
title: null,
message: null,
closable: true,
buttonLabel: 'OK',
callback: null
};

if (typeof arguments[0] === 'object' && arguments[0].constructor === {}.constructor) {
options = $.extend(true, defaultOptions, arguments[0]);
} else {
options = $.extend(true, defaultOptions, {
message: arguments[0],
closable: false,
buttonLabel: 'OK',
callback: typeof arguments[1] !== 'undefined' ? arguments[1] : null
});
}

return new BootstrapDialog({
message: message,
type: options.type,
title: options.title,
message: options.message,
closable: options.closable,
data: {
'callback': callback
callback: options.callback
},
onhide: function(dialog) {
!dialog.getData('btnClicked') && dialog.isClosable() && typeof dialog.getData('callback') === 'function' && dialog.getData('callback')(false);
},
closable: false,
buttons: [{
label: 'OK',
label: options.buttonLabel,
action: function(dialog) {
dialog.setData('btnClicked', true);
typeof dialog.getData('callback') === 'function' && dialog.getData('callback')(true);
dialog.close();
}
2 changes: 1 addition & 1 deletion js/bootstrap-dialog.min.js

Large diffs are not rendered by default.

0 comments on commit 2af6b41

Please sign in to comment.