Skip to content

Instantly share code, notes, and snippets.

@mhingston
Created June 11, 2015 10:01
Show Gist options
  • Save mhingston/b266816fc8645f83bfc8 to your computer and use it in GitHub Desktop.
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
/*
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