BSD requires jQuery v1.9.1+, Bootstrap 4 modal component, and Bootstrap's CSS.
Several quick start options are available:
git clone https://github.com/bgaze/bootstrap4-dialogs.gitnpm install TODOyarn add TODOcomposer require bgaze/bootstrap4-dialogsbower install TODOTODO
Just make sure to include required dependencies into your app, then the library script bootstrap4-dialogs.min.js.
That's it! You can use the globally declared bsd object :
"./src/doc/demo.html"
HTML
"!./src/doc/demo.html"
Javascript
"!./src/doc/demo.js"
This section applies to all provided dialog functions (bsd.alert, bsd.confirm, bsd.prompt).
When called, a customized Boostrap 4 modal will be dynamically built and inserted into the document.
Unless explicitly specified through options, the modal is automatically shown when created, and destroyed then removed from the DOM when closed.
There is no stylesheet provided with BSD, as it rely on Bootstrap styles.
To ease dialogs theming, two CSS classes are automatically added to each dialog :
bsd-dialog and bsd-[dialogName] (for instance bsd-alert for alert dialogs).
Arguments
Dialog functions accept two arguments:
"!./src/doc/usage-arguments.js"
Handling dialogs
Each dialog function returns it's modal element as a jQuery object, so Bootstrap modal events and method can be directly used.
"!./src/doc/usage-handling.js"
BSD defaults options are stored into the bsd.defaults object and organized this way:
bsd.defaults.dialog: common options that apply to all dialogs.bsd.defaults.[dialogName]: options that apply to a specific dialog only.You can easily make application wide customizations:
"!./src/doc/options.js"
Here is the list of available common options:
"!./src/dialogs/common-defaults.js"
Usage :
When using a callback function, it will receive as argument the original "modal dismiss" event.
"!./src/doc/alert.js"
Default options :
You can customize these options as described in the options section.
"!./src/dialogs/alert-defaults.js"
Default template :
If you need to change this template, just make sure to keep required bsd-* classes.
"!./src/dialogs/alert.html"
Usage :
The callback function will receive two arguments:
It must return a boolean indicating if the dialog should be closed.
"!./src/doc/confirm.js"
Default options :
You can customize these options as described in the options section.
"!./src/dialogs/confirm-defaults.js"
Default template :
If you need to change this template, just make sure to keep required bsd-* classes.
"!./src/dialogs/confirm.html"
Usage :
The callback function will receive two arguments:
null if canceled.It must return a boolean indicating if the dialog should be closed.
"!./src/doc/prompt.js"
Default options :
You can customize these options as described in the options section.
"!./src/dialogs/prompt-defaults.js"
Default template :
If you need to change this template, just make sure to keep required bsd-* classes.
"!./src/dialogs/prompt.html"
If you need to create custom dialogs, you can easily extend BSD.
Please find below a detailed example.
Define your dialog options and defaults.
Simply append them to bsd.defaults. The key MUST be your dialog name.
Remember that your dialog options inherit from bsd.defaults.dialog, so you can override them.
The only required option that must be provided is the dialog template (template key).
"!./src/doc/custom-defaults.js"
Create the dialog function.
You can easily generate the dialog thanks to the bsd.dialog function wich :
hidden.bs.modal event based on destroy option.show.bs.modal event based on show option.show option.It requires three arguments :
bsd.defaults."!./src/doc/custom-function.js"
Usage:
Simply use your function like this:
"!./src/doc/custom-usage.js"