Last active
April 3, 2019 03:17
-
-
Save makeusabrew/6223814 to your computer and use it in GitHub Desktop.
Potential Bootbox v4.x API and usage examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* alert | |
*/ | |
bootbox.alert("Hello world"); | |
bootbox.alert("Hello world", function() { | |
console.log("dialog dismissed with OK or escape button"); | |
}); | |
bootbox.alert({ | |
message: "Hello world", | |
callback: function() {} | |
}); | |
bootbox.alert({ | |
// alert and confirm can supply an optional dialog title | |
title: "Alert! Alert!", | |
message: "Hello world", | |
buttons: { | |
ok: { | |
label: "Hi there!", | |
className "btn-warning" | |
} | |
} | |
// callback is always optional for alerts but not for prompts or confirms | |
}); | |
// I'd like to be able to hoist button declarations up to the top level options object | |
// for the wrapper methods, e.g. ideally this will be doable though maybe not for 4.0.0 | |
bootbox.alert({ | |
message: "Hello world", | |
// NOT yet implemented, have to provide buttons object | |
ok: { | |
label: "Hi there!", | |
className "btn-warning" | |
} | |
}); | |
/** | |
* confirm | |
*/ | |
bootbox.confirm("Sure?", function(result) { | |
console.log("dialog dismissed with OK, cancel or escape button", result); | |
}); | |
bootbox.confirm({ | |
message: "Sure?", | |
callback: function(result) { | |
console.log(result); | |
} | |
}); | |
bootbox.confirm({ | |
message: "Sure?", | |
callback: function(result) { | |
console.log(result); | |
}, | |
buttons: { | |
cancel: { | |
label: "No" | |
}, | |
confirm: { | |
label: "Yes!" | |
} | |
} | |
}); | |
/** | |
* prompt | |
*/ | |
bootbox.prompt("What is your name?", function(result) { | |
console.log("dialog dismissed with OK, cancel or escape button", result); | |
}); | |
bootbox.prompt({ | |
// prompts can't supply a message; just a title | |
title: "Sure?", | |
callback: function(result) { | |
console.log(result); | |
}, | |
// default input value | |
value: "Bob" | |
}); | |
/** | |
* base dialog method | |
*/ | |
bootbox.dialog({ | |
title: "Dialog title", | |
message: "Dialog message", | |
closeButton: true, | |
buttons: { | |
exit: { | |
label: "Exit now", | |
className: "btn-danger", | |
callback: function() { | |
// exit | |
} | |
}, | |
continue: { | |
label: "Continue", | |
className: "btn-success", | |
callback: function() { | |
// carry on | |
} | |
}, | |
// short form of label -> callback not yet implemented | |
// but it will be shortly... | |
"Help!": function() { | |
// display help text | |
} | |
}, | |
onEscape: function() { | |
// user pressed escape | |
}, | |
// show immediately? | |
show: true, | |
// animate? | |
animate: true, | |
// show backdrop? | |
backdrop: true, | |
// locale stuff | |
locale: "fr", | |
// outer dialog class | |
className "my-dialog" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment