An extender for SweetAlert buttons. Allows you to add more than two buttons.
3/17/2017 - Recent update. Need to reference a function which calls swal.
4/5/2017 - Fixed issue with click functions.
6/22/2017 - Added individual color options, new params for function parameters, removed hasCallBack.
11/28/2018 - Wow long time, but not forgotten! - Added option to stop sweet alert closing on confirm from Samuel1989
<script src="swalExtend.js"></script>
<link rel="stylesheet" type="text/css" href="swalExtend.css">
- Specify how many buttons you want
- Give an array of button titles
- If your SweetAlert has a cancel button mark hasCancelButton as true
- Optional list of classNames for each button
- Array of functions for each buttons' click
Note: SweetAlerts' callback function will still work for the original two buttons.
var swalFunction = function(){
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
},
function(){
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
};
$("button").click(function() {
swalExtend({
swalFunction: swalFunction,
hasCancelButton: true,
buttonNum: 2,
buttonColor: ["blue", "green"]
buttonNames: ["maybe delete", "probably/partially delete"],
clickFunctionList: [
function() {
console.debug('ONE BUTTON');
},
function() {
console.debug('TWO BUTTON');
}
]
});
});