Created
October 21, 2014 16:04
-
-
Save Oshuma/23b223a22cefd347f638 to your computer and use it in GitHub Desktop.
Use sweetAlert with Rails UJS.
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
$.rails.allowAction = function(link) { | |
if ( ! link.attr('data-confirm') ) return true; | |
$.rails.showConfirmDialog(link); | |
return false; | |
}; | |
$.rails.confirmed = function(link) { | |
link.removeAttr('data-confirm'); | |
link.trigger('click.rails'); | |
}; | |
$.rails.showConfirmDialog = function(link) { | |
sweetAlert({ | |
title: link.attr('data-confirm'), | |
showCancelButton: true | |
}, function(isConfirmed) { | |
if (isConfirmed) $.rails.confirmed(link); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment