Forked from stevenspiel/rails_confirm_override.js.coffee
Last active
January 26, 2016 04:37
-
-
Save shah743/62f4815c7457fc4360c1 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
$.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' | |
swal { | |
title: title | |
text: message | |
type: 'warning' | |
showCancelButton: true | |
confirmButtonColor: '#3085d6' | |
cancelButtonColor: '#d33' | |
confirmButtonText: 'Yes, delete it!' | |
closeOnConfirm: false | |
}, -> | |
swal 'Deleted!', 'Record deleted successfully', 'success' | |
$.rails.confirmed(link) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment