1
0

search.js.coffee 1.0 KB

1234567891011121314151617181920212223242526272829
  1. $ ->
  2. $agentNavigate = $('#agent-navigate')
  3. # initialize typeahead listener
  4. $agentNavigate.bind "typeahead:selected", (event, object, name) ->
  5. item = object['value']
  6. $agentNavigate.typeahead('val', '')
  7. if window.agentPaths[item]
  8. $(".spinner").show()
  9. navigationData = window.agentPaths[item]
  10. if !(navigationData instanceof Object) || !navigationData.method || navigationData.method == 'GET'
  11. window.location = navigationData.url || navigationData
  12. else
  13. $("<a href='#{navigationData.url}' data-method='#{navigationData.method}'></a>").appendTo($("body")).click()
  14. # substring matcher for typeahead
  15. substringMatcher = (strings) ->
  16. findMatches = (query, callback) ->
  17. matches = []
  18. substrRegex = new RegExp(query, "i")
  19. $.each strings, (i, str) ->
  20. matches.push value: str if substrRegex.test(str)
  21. callback(matches.slice(0,6))
  22. $agentNavigate.typeahead
  23. minLength: 1,
  24. highlight: true,
  25. ,
  26. source: substringMatcher(window.agentNames)