Lungo.View.Article.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. REFERENCE_LINK: 'a[href][data-article]'
  15. };
  16. var CSS_CLASSES = {
  17. ACTIVE: 'current'
  18. };
  19. /**
  20. * ?
  21. *
  22. * @method show
  23. */
  24. var show = function(section_id, article_id) {
  25. var nav_items = section_id + ' ' + SELECTORS.NAVIGATION_ITEM;
  26. _disableNavItems(nav_items);
  27. var current_nav_item = lng.dom(nav_items + '[href="' + article_id + '"]');
  28. current_nav_item.addClass(CSS_CLASSES.ACTIVE);
  29. _setTitle(section_id, current_nav_item);
  30. showReferenceLinks(section_id, article_id.replace('#', ''));
  31. _showContainer(section_id, article_id);
  32. };
  33. /**
  34. * ?
  35. *
  36. * @method showReferenceLinks
  37. */
  38. var showReferenceLinks = function(section_id, article_id) {
  39. var links = lng.dom('section' + section_id + ' ' + SELECTORS.REFERENCE_LINK);
  40. for (var i = 0, len = links.length; i < len; i++) {
  41. var link = lng.dom(links[i]);
  42. (link.data('article') === article_id) ? link.show() : link.hide();
  43. }
  44. };
  45. var _disableNavItems = function(items) {
  46. lng.dom(items).removeClass(CSS_CLASSES.ACTIVE);
  47. };
  48. var _showContainer = function(section_id, article_id) {
  49. var section_articles = section_id + ' ' + SELECTORS.ARTICLE;
  50. lng.dom(section_articles).removeClass(CSS_CLASSES.ACTIVE);
  51. lng.dom(article_id).addClass(CSS_CLASSES.ACTIVE);
  52. };
  53. var _setTitle = function(id, item) {
  54. var title = item.data('title');
  55. if (title) {
  56. var section_title = id + ' header .title, ' + id + ' footer .title';
  57. lng.dom(section_title).text(title);
  58. }
  59. };
  60. return {
  61. show: show,
  62. showReferenceLinks: showReferenceLinks
  63. };
  64. })(LUNGO);