modals.js.coffee 733 B

123456789101112131415161718192021222324252627
  1. $ ->
  2. modal_holder_selector = '#modal-holder'
  3. modal_selector = '.modal'
  4. $(document).on 'click', 'a[data-modal]', ->
  5. location = $(this).attr('href')
  6. #Load modal dialog from server
  7. $.get location, (data)->
  8. $(modal_holder_selector).html(data).
  9. find(modal_selector).modal()
  10. false
  11. $(document).on 'ajax:success',
  12. 'form[data-modal]', (event, data, status, xhr)->
  13. url = xhr.getResponseHeader('Location')
  14. if url
  15. # Redirect to url
  16. window.location = url
  17. else
  18. # Remove old modal backdrop
  19. $('.modal-backdrop').remove()
  20. # Replace old modal with new one
  21. $(modal_holder_selector).html(data).
  22. find(modal_selector).modal()
  23. false