Last active
January 25, 2016 12:46
-
-
Save stevenspiel/af1c25835b716205cad2 to your computer and use it in GitHub Desktop.
Replace Rails confirm with sweetalert2 popup. (https://github.com/limonte/sweetalert2). It overrides the default javascript (from jquery_ujs), which skips any other popup.
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
# Override the default confirm dialog by rails | |
$.rails.allowAction = (link) -> | |
if link.data('confirm') | |
$.rails.showConfirmationDialog(link) | |
false | |
else | |
true | |
# User click confirm button | |
$.rails.confirmed = (link) -> | |
link.data('confirm', null) | |
link.trigger('click') | |
# Display the confirmation dialog | |
$.rails.showConfirmationDialog = (link) -> | |
message = link.data('confirm') | |
title = link.data('title') || 'Warning' | |
sweetAlert | |
title: title | |
html: message | |
type: 'warning' | |
showCancelButton: true | |
confirmButtonColor: '#DD6B55' | |
confirmButtonText: 'Yes' | |
closeOnConfirm: true | |
animation: false | |
, -> | |
$.rails.confirmed(link) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment