utils.js.coffee 1.3KB

123456789101112131415161718192021222324252627282930313233343536
  1. class @Utils
  2. @navigatePath: (path) ->
  3. path = "/" + path unless path.match(/^\//)
  4. window.location.href = path
  5. @currentPath: ->
  6. window.location.href.replace(/https?:\/\/.*?\//g, '')
  7. @registerPage: (klass, options = {}) ->
  8. if options.forPathsMatching?
  9. if Utils.currentPath().match(options.forPathsMatching)
  10. window.currentPage = new klass()
  11. else
  12. new klass()
  13. @showDynamicModal: (content = '', { title, body, onHide } = {}) ->
  14. $("body").append """
  15. <div class="modal fade" tabindex="-1" id='dynamic-modal' role="dialog" aria-labelledby="dynamic-modal-label" aria-hidden="true">
  16. <div class="modal-dialog modal-lg">
  17. <div class="modal-content">
  18. <div class="modal-header">
  19. <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  20. <h4 class="modal-title" id="dynamic-modal-label"></h4>
  21. </div>
  22. <div class="modal-body">#{content}</div>
  23. </div>
  24. </div>
  25. </div>
  26. """
  27. modal = document.querySelector('#dynamic-modal')
  28. $(modal).find('.modal-title').text(title || '').end().on 'hidden.bs.modal', ->
  29. $('#dynamic-modal').remove()
  30. onHide?()
  31. body?(modal.querySelector('.modal-body'))
  32. $(modal).modal('show')