Lungo.View.Article.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Initialize the <articles> layout of a certain <section>
  3. *
  4. * @namespace LUNGO.View
  5. * @class Article
  6. *
  7. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  8. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  9. */
  10. LUNGO.View.Article = (function(lng, undefined) {
  11. var SELECTORS = {
  12. ARTICLE: 'article',
  13. NAVIGATION_ITEM: 'nav a'
  14. };
  15. var CSS_CLASSES = {
  16. ACTIVE: 'current'
  17. };
  18. var show = function(section_id, article_id) {
  19. var nav_items = section_id + ' ' + SELECTORS.NAVIGATION_ITEM;
  20. _disableNavItems(nav_items);
  21. var current_nav_item = lng.Dom.query(nav_items + '[href="' + article_id + '"]');
  22. current_nav_item.addClass(CSS_CLASSES.ACTIVE);
  23. _setTitle(section_id, current_nav_item);
  24. _showContainer(section_id, article_id);
  25. };
  26. var _disableNavItems = function(items) {
  27. lng.Dom.query(items).removeClass(CSS_CLASSES.ACTIVE);
  28. };
  29. var _showContainer = function(section_id, article_id) {
  30. var section_articles = section_id + ' ' + SELECTORS.ARTICLE;
  31. lng.Dom.query(section_articles).removeClass(CSS_CLASSES.ACTIVE);
  32. lng.Dom.query(article_id).addClass(CSS_CLASSES.ACTIVE);
  33. };
  34. var _setTitle = function(id, item) {
  35. var title = item.data('title');
  36. if (title) {
  37. var section_title = id + ' header .title, ' + id + ' footer .title';
  38. lng.Dom.query(section_title).text(title);
  39. }
  40. };
  41. return {
  42. show: show
  43. };
  44. })(LUNGO);