Created
October 12, 2012 08:55
-
-
Save jpzwarte/3878172 to your computer and use it in GitHub Desktop.
jquery_ujs async confirm
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
$ -> | |
$.rails.confirm = (message) -> | |
answer = $.Deferred(); | |
modal = $ """ | |
<div class="modal hide fade"> | |
<div class="modal-header"> | |
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> | |
<h3>Delete</h3> | |
</div> | |
<div class="modal-body"> | |
<p>#{message}</p> | |
</div> | |
<div class="modal-footer"> | |
<a href="#" class="btn" data-dismiss="modal">Close</a> | |
<a href="#" class="btn btn-primary">Delete</a> | |
</div> | |
</div> | |
""" | |
modal.on 'click', 'a.btn-primary', (event) -> | |
event.preventDefault() | |
answer.resolve() | |
modal.on 'hidden', -> | |
answer.reject() | |
modal.modal() | |
answer.promise() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment