Skip to content

Instantly share code, notes, and snippets.

@jpzwarte
Created October 12, 2012 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpzwarte/3878172 to your computer and use it in GitHub Desktop.
Save jpzwarte/3878172 to your computer and use it in GitHub Desktop.
jquery_ujs async confirm
$ ->
$.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">&times;</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