Created
May 29, 2012 09:27
-
-
Save cedricdekimpe/2823526 to your computer and use it in GitHub Desktop.
How-to override window.confirm() dialog with Rails 3 and bootbox.js
This file contains hidden or 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
//= require bootbox.min |
This file contains hidden or 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
$(document).ready(function() { | |
$.rails.allowAction = function(element) { | |
var message = element.data('confirm'), | |
answer = false, callback; | |
if (!message) { return true; } | |
if ($.rails.fire(element, 'confirm')) { | |
myCustomConfirmBox(message, function() { | |
callback = $.rails.fire(element, | |
'confirm:complete', [answer]); | |
if(callback) { | |
var oldAllowAction = $.rails.allowAction; | |
$.rails.allowAction = function() { return true; }; | |
element.trigger('click'); | |
$.rails.allowAction = oldAllowAction; | |
} | |
}); | |
} | |
return false; | |
} | |
function myCustomConfirmBox(message, callback) { | |
bootbox.confirm(message, "Cancel", "Yes", function(confirmed) { | |
if(confirmed){ | |
callback(); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not working in case of
In short when the method is 'GET', it is not working. Can you pls confirm.