Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lancefisher/11099746 to your computer and use it in GitHub Desktop.
Save lancefisher/11099746 to your computer and use it in GitHub Desktop.
$.rails.allowAction = function(link) {
if (!link.attr('data-confirm')) {
return true;
}
$.rails.showConfirmDialog(link);
return false;
};
$.rails.confirmed = function(link) {
link.removeAttr('data-confirm');
return link.trigger('click.rails');
};
$.rails.showConfirmDialog = function(link) {
var html, message;
message = link.attr('data-confirm');
html = "<div class='modal fade'>\n <div class='modal-dialog'>\n <div class='modal-content'>\n <div class='modal-header'>\n <a class='close' data-dismiss='modal'>&times;</a>\n <h3>Request confirmation</h3>\n </div>\n <div class='modal-body'>\n <p>" + message + "</p>\n </div>\n <div class='modal-footer'>\n <a data-dismiss='modal' class='btn btn-huge btn-default'>Cancel</a>\n <a data-dismiss='modal' class='btn btn-huge btn-danger confirm'>Confirm</a>\n </div>\n </div>\n </div>\n</div>";
$html = $(html)
$html.modal();
var $dialog = $html.find('.confirm');
return $dialog.on('click', function(a) {
return $.rails.confirmed(link);
});
};
@lancefisher
Copy link
Author

This updates the HTML to Bootstrap 3. It also gets rid of the id on the modal, and adds the click handler using the reference to the jQuery object already holding the form HTML in $html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment