Lungo.View.Article.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 ELEMENT = lng.Constants.ELEMENT;
  12. var CLASS = lng.Constants.CLASS;
  13. var ATTRIBUTE = lng.Constants.ATTRIBUTE;
  14. var TRIGGER = lng.Constants.TRIGGER;
  15. var SELECTORS = {
  16. NAVIGATION_ITEM: 'a[href][data-target="article"]',
  17. REFERENCE_LINK: ' a[href][data-article]'
  18. };
  19. /**
  20. * ?
  21. *
  22. * @method show
  23. */
  24. var show = function(section_id, article_id, element) {
  25. if (element) {
  26. _setTitle(section_id, element);
  27. }
  28. _toggleNavItems(section_id, article_id);
  29. _showReferenceLinks(section_id, article_id.replace('#', ''));
  30. //@todo: Fallback android Inputs
  31. //lng.Fallback.androidInputs(current_active_article_id, false);
  32. //lng.Fallback.androidInputs(article_id, true);
  33. };
  34. var _showReferenceLinks = function(section_id, article_id) {
  35. var links = lng.dom(ELEMENT.SECTION + section_id + SELECTORS.REFERENCE_LINK);
  36. for (var i = 0, len = links.length; i < len; i++) {
  37. var link = lng.dom(links[i]);
  38. if (link.data(ATTRIBUTE.ARTICLE) === article_id) {
  39. link.show();
  40. } else {
  41. link.hide();
  42. }
  43. }
  44. };
  45. var _toggleNavItems = function(section_id, article_id) {
  46. var links = lng.dom(ELEMENT.SECTION + section_id + ' ' + SELECTORS.NAVIGATION_ITEM);
  47. links.removeClass(CLASS.CURRENT);
  48. active_items = ELEMENT.SECTION + section_id + ' a[href="' + article_id + '"][data-target="article"]';
  49. links = lng.dom(active_items);
  50. links.addClass(CLASS.CURRENT);
  51. };
  52. var _setTitle = function(id, item) {
  53. var title = item.data(ATTRIBUTE.TITLE);
  54. if (title) {
  55. var section_title = id + ' header .title, ' + id + ' footer .title';
  56. lng.dom(section_title).text(title);
  57. }
  58. };
  59. return {
  60. show: show
  61. };
  62. })(LUNGO);