core.js.coffee 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. $ ->
  2. # Flash
  3. if $(".flash").length
  4. setTimeout((-> $(".flash").slideUp(-> $(".flash").remove())), 5000)
  5. # Help popovers
  6. $('.hover-help').popover(trigger: 'hover', html: true)
  7. # Pressing '/' selects the search box.
  8. $("body").on "keypress", (e) ->
  9. if e.keyCode == 47 # The '/' key
  10. if e.target.nodeName == "BODY"
  11. e.preventDefault()
  12. $agentNavigate.focus()
  13. # Select2 Selects
  14. $(".select2").select2(width: 'resolve')
  15. $(".select2-linked-tags").select2(
  16. width: 'resolve',
  17. formatSelection: (obj) ->
  18. "<a href=\"#{this.element.data('urlPrefix')}/#{obj.id}/edit\" onClick=\"Utils.select2TagClickHandler(event, this)\">#{Utils.escape(obj.text)}</a>"
  19. )
  20. # Helper for selecting text when clicked
  21. $('.selectable-text').each ->
  22. $(this).click ->
  23. range = document.createRange()
  24. range.setStartBefore(this.firstChild)
  25. range.setEndAfter(this.lastChild)
  26. sel = window.getSelection()
  27. sel.removeAllRanges();
  28. sel.addRange(range)
  29. # Agent navbar dropdown
  30. $('.navbar .dropdown.dropdown-hover').hover (-> $(this).addClass('open')), (-> $(this).removeClass('open'))