Created
February 29, 2012 18:10
-
-
Save hinrik/1943094 to your computer and use it in GitHub Desktop.
Bootstrap modal confirmation dialog for Rails
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
# Replace Rails' confirmation dialog with a translatable Bootstrap modal dialog. | |
# Requires jQuery 1.7, Bootstrap, and i18n-js (https://github.com/fnando/i18n-js) | |
# Translation strings used: confirm.title, confirm.ok, confirm.cancel | |
$ -> | |
$.rails.confirm = (message) -> | |
$("#confirm_dialog > .modal-body").html("<p><i class='icon-warning-sign'></i> " + message + '</p>') | |
false | |
if $('[data-confirm]') | |
$('body').append("<div class='modal hide' id='confirm_dialog'><div class='modal-header'><a class='close' data-dismiss='modal'>×</a><h3>" + I18n.t('confirm.title') + "</h3></div><div class='modal-body'></div><div class='modal-footer'><a class='btn btn-primary'></a><a href='#' data-dismiss='modal' class='btn'>" + I18n.t('confirm.cancel') + "</a></div></div>") | |
$('[data-confirm]').each -> | |
link_elem = $(this) | |
link_elem.click (e) -> | |
e.preventDefault() | |
confirm = $('#confirm_dialog > .modal-footer > .btn-primary') | |
new_confirm = link_elem.clone() | |
new_confirm.removeAttr('data-confirm id') | |
new_confirm.attr('class', 'btn btn-primary') | |
new_confirm.html(I18n.t('confirm.ok')) | |
confirm.replaceWith(new_confirm) | |
$('#confirm_dialog').modal() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment