custom-alert.js
Override the alert() and confirm() functions of JavaScript, allowing you to customize them. This application does not use jQuery or another framework, just JavaScript and CSS. Responsive design.
Demo
Install
NPM
npm install --save custom-alert
Bower
bower install --save custom-alert
Apply
Default style
Default bootstrap style
and script
<!--<script src="YOU/PATH/dist/js/custom-alert.min.js">-->
Use
There are two ways to apply customAlert.
The first is to start the function by allowing it to automatically override the alert()
and confirm()
global (window.alert
, window.confirm
).
;
The second returning the functions in an object, so it passes false
as an attribute of customAlert()
var custom = false; custom
alert(dialog, options || callback, callback)
Simply.
Editing title and button text;
Performing a callback after the operation.
confirm(dialog, callback || {callbacks}, options)
Calling a callback to handle the result. In this case, the callback receives an argument with true
or false
Defining different callbacks for different results.
Setting Title and Text of Buttons.
Arguments and options
Alert
options
- title: The title.
- done: The button text.
Confirm
options
- title.text The title.
- title.default If true, set the default as default.
- title.bold Add bold text.
- done.text The done text.
- done.default If true, set the default as default.
- done.bold Add bold text.
- cancel: The cancel text.
callback
- success: if button done press.
- cancel: if button calcel press.
- only function: Gets an attribute with true or false.
Keyboard events
The ENTER key performs the default button.
"cancel": "default" : true
In this example, the default button will be "Cancel", so by clicking ENTER on the keyboard, this button will be executed. By default the "default button" is done.
I see an example on the demo page