Lungo.View.Article.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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: '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(nav_items + '[href="' + article_id + '"]');
  22. if(current_nav_item.length > 0) {
  23. current_nav_item.addClass(CSS_CLASSES.ACTIVE);
  24. _setTitle(section_id, current_nav_item);
  25. }
  26. _showContainer(section_id, article_id);
  27. };
  28. var _disableNavItems = function(items) {
  29. lng.dom(items).removeClass(CSS_CLASSES.ACTIVE);
  30. };
  31. var _showContainer = function(section_id, article_id) {
  32. var section_articles = section_id + ' ' + SELECTORS.ARTICLE;
  33. lng.dom(section_articles).removeClass(CSS_CLASSES.ACTIVE);
  34. lng.dom(article_id).addClass(CSS_CLASSES.ACTIVE);
  35. };
  36. var _setTitle = function(id, item) {
  37. var title = item.data('title');
  38. if (title) {
  39. var section_title = id + ' header .title, ' + id + ' footer .title';
  40. lng.dom(section_title).text(title);
  41. }
  42. };
  43. return {
  44. show: show
  45. };
  46. })(LUNGO);