public
Created

jquery_ujs async confirm

  • Download Gist
behaviors.js.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
$ ->
$.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()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.