Created
June 11, 2015 10:01
-
-
Save mhingston/b266816fc8645f83bfc8 to your computer and use it in GitHub Desktop.
Override native alert, confirm and prompt functions with prettier versions and optional callbacks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Include SweetAlert before this script | |
http://t4t5.github.io/sweetalert | |
*/ | |
function alert(message, callback) | |
{ | |
callback = callback || function(){} | |
var options = | |
{ | |
title: "", | |
text: message, | |
type: "info" | |
} | |
if(typeof(message) === "object") | |
{ | |
options = message | |
} | |
sweetAlert(options, callback) | |
} | |
function confirm(message, callback) | |
{ | |
callback = callback || function(){} | |
var options = | |
{ | |
title: "Are you sure?", | |
text: message, | |
type: "warning", | |
showCancelButton: true | |
} | |
if(typeof(message) === "object") | |
{ | |
options = message | |
} | |
sweetAlert(options, function(isConfirm) | |
{ | |
return callback(isConfirm) | |
}) | |
} | |
function prompt(message, value, callback) | |
{ | |
var options = | |
{ | |
title: "", | |
text: message, | |
type: "input", | |
showCancelButton: true, | |
inputValue: value | |
} | |
if(typeof(message) === "object") | |
{ | |
options = message | |
} | |
sweetAlert(options, function(inputValue) | |
{ | |
return callback ? callback(inputValue) : inputValue | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment