Lungo.Router.History.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Stores the displayed <sections> as a historical.
  3. *
  4. * @namespace Lungo.Router
  5. * @class History
  6. *
  7. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  8. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  9. */
  10. Lungo.Router.History = (function(undefined) {
  11. var _history = [];
  12. /**
  13. * Create a new element to the browsing history based on the current section id.
  14. *
  15. * @method add
  16. *
  17. * @param {string} Id of the section
  18. */
  19. var add = function(section_id) {
  20. if (section_id !== current()) {
  21. _history.push(section_id);
  22. }
  23. };
  24. /**
  25. * Returns the current browsing history section id.
  26. *
  27. * @method current
  28. *
  29. * @return {string} Current section id
  30. */
  31. var current = function() {
  32. return _history[_history.length - 1];
  33. };
  34. /**
  35. * Removes the current item browsing history.
  36. *
  37. * @method removeLast
  38. */
  39. var removeLast = function() {
  40. _history.length -= 1;
  41. };
  42. return {
  43. add: add,
  44. current: current,
  45. removeLast: removeLast
  46. };
  47. })();