Bootstrap 4 Pop-up (Live Demo)
Replaces the native JavaScript alert, confirm, and prompt with non-blocking Bootstrap alternatives!
- Bootstrap 4 (just in case you did not read the name)
- Native JavaScript Promise
- Display non blocking pop-ups
- Modals are queued and shown one at a time
/**
* @description Inspired by https://www.bootply.com/PoVEEtvPZt. Used to display a pop up with bootstrap elements
* @param {object} options - Options
* @param {string} [options.type="alert"] - alert, prompt, confirm
* @param {string} [options.modalSize="modal-sm"] - modal-sm, modal-lg
* @param {string} [options.okButtonText="Ok"]
* @param {string} [options.cancelButtonText="Cancel"]
* @param {string} [options.yesButtonText="Yes"]
* @param {string} [options.noButtonText="No"] - empty string to hide the No button
* @param {string} [options.headerText="Attention"]
* @param {string} [options.messageText="Message"]
* @param {string} [options.bootstrapStyle="default"] - default, primary, success, info, warning, danger
* @param {string} [options.inputFieldType="text"] - could ask for number, email, etc
* @param {string} [options.inputFieldDefault=""] - default value for the input
* @return {Promise<undefined|boolean|string>} Alert returns undefined. Confirm returns boolean or undefined if the close button is pressed. Prompt returns a string or undefined if the close button is pressed.
*/
BootstrapPopUp(options: object): Promise<undefined|boolean|string>
/**
* Bootstrap 4 default pop-ups
*/
$('#default-alert-bootstrap').on('click', function () {
BootstrapPopUp({})
.then(function (result) {
console.info(result);
return;
});
return;
});
$('#default-confirm-bootstrap').on('click', function () {
BootstrapPopUp({
type: "confirm"
})
.then(function (result) {
console.info(result);
return;
});
return;
});
$('#default-prompt-bootstrap').on('click', function () {
BootstrapPopUp({
type: "prompt"
})
.then(function (result) {
console.info(result);
return;
});
return;
});
/**
* Bootstrap 4 custom pop-ups
*/
$('#alert-bootstrap').on('click', function () {
BootstrapPopUp({
type: "alert",
messageText: "Bootstrap alert",
okButtonText: "Dismiss Alert",
modalSize: "modal-sm",
headerText: "Attention Custom Pop-up Header!"
})
.then(function (result) {
console.info(result);
return;
});
return;
});
$('#confirm-bootstrap').on('click', function () {
BootStrapPopUp({
type: "confirm",
messageText: "BootStrap confirm",
yesButtonText: "Dismiss with Yes",
noButtonText: "Dismiss with No",
modalSize: "modal-sm",
headerText: "Attention Custom Pop-up Header!"
})
.then(function (result) {
console.info(result);
return;
});
return;
});
$('#prompt-bootstrap').on('click', function () {
BootStrapPopUp({
type: "prompt",
messageText: "BootStrap prompt",
okButtonText: "Submit",
cancelButtonText: "No Thanks",
inputFieldType: "text",
inputFieldDefault: "default value",
modalSize: "modal-sm",
headerText: "Attention Custom Pop-up Header!"
})
.then(function (result) {
console.info(result);
return;
});
return;
});