Lungo.Router.History.coffee 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ###
  2. Stores the displayed <sections> as a historical.
  3. @namespace Lungo.Router
  4. @class History
  5. @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  6. @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  7. ###
  8. Lungo.Router.History = do (lng = Lungo) ->
  9. _history = []
  10. ###
  11. Create a new element to the browsing history based on the current section id.
  12. @method add
  13. @param {string} Id of the section
  14. ###
  15. add = (section_id) ->
  16. _history.push section_id if section_id isnt current()
  17. ###
  18. Returns the current browsing history section id.
  19. @method current
  20. @return {string} Current section id
  21. ###
  22. current = ->
  23. _history[_history.length - 1]
  24. ###
  25. Removes the current item browsing history.
  26. @method removeLast
  27. ###
  28. removeLast = ->
  29. _history.length -= 1
  30. ###
  31. @todo
  32. ###
  33. url = ->
  34. _url = ""
  35. _url += "#{section}/" for section in _history
  36. _url += lng.Element.Cache.article.attr "id"
  37. setTimeout (-> window.location.hash = _url), 0
  38. add: add
  39. current: current
  40. removeLast: removeLast
  41. url: url