bootstrap-show-modal
jQuery plugin to create bootstrap modals in pure JavaScript.
Demo Page
This version is compatible with Bootstrap 5, but we remain a Bootstrap 4 compatible version with the branch
bootstrap4-compatible.
npm package versions 3.x are Bootstrap 5 compatible, versions 1.x Bootstrap 4 compatible.
Installation
npm install bootstrap-show-modal
Or just download this repository and include src/bootstrap-show-modal.js
.
Usage
Simple Modal
$.showModal({title: "Hello World!", body: "A very simple modal dialog without buttons."})
Alert Dialog
$.showAlert({title: "Hi", body: "Please press ok, if you like or dislike cookies."})
Confirm Dialog
$.showConfirm({
title: "Please confirm", body: "Do you like cats?", textTrue: "Yes", textFalse: "No",
onSubmit: function (result) {
if (result) {
$.showAlert({title: "Result: " + result, body: "You like cats."})
} else {
$.showAlert({title: "Result: " + result, body: "You don't like cats."})
}
},
onDispose: function() {
console.log("The confirm dialog vanished")
}
})
Properties
this.props = {
title: "",
body: "",
footer: "",
modalClass: "fade",
modalDialogClass: "",
options: {
backdrop: 'static'
},
onCreate: null,
onShown: null,
onDispose: null,
onSubmit: null
}
See the Bootstrap 4 Modal documentation for possible
values of options
, modalClass
and modalDialogClass
.
Minified version
I don't provide a minified version because I think it should be up to the using programmer
to create minified versions, with all the used script sources concatenated to one file.
But, if you want it, it is easy to create your minified version with uglify: https://www.npmjs.com/package/uglify-js
Just install uglify
npm install uglify-js -g
and then in the src-folder
uglifyjs bootstrap-show-modal.js --compress --mangle > bootstrap-show-modal.min.js
Browser support
It works in all modern browsers and in the Internet Explorer. Not tested with IE < 11.
You may want to check out my further Bootstrap and HTML extensions