Lungo.View.Article.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 SELECTORS = {
  15. NAVIGATION_ITEM: 'a[href][data-router="article"]',
  16. REFERENCE_LINK: ' a[href][data-article]',
  17. TITLE_OF_ARTICLE: 'header .title, footer .title',
  18. ASIDE_REFERENCE_LIST: 'li a.current, li.current'
  19. };
  20. /**
  21. * ?
  22. *
  23. * @method show
  24. */
  25. var title = function(value) {
  26. if (value) {
  27. lng.Element.Cache.section.find(SELECTORS.TITLE_OF_ARTICLE).text(value);
  28. }
  29. //@todo: Fallback android Inputs
  30. //lng.Fallback.androidInputs(current_active_article_id, false);
  31. //lng.Fallback.androidInputs(article_id, true);
  32. };
  33. var switchNavItems = function(article_id) {
  34. lng.Element.Cache.section.find(SELECTORS.NAVIGATION_ITEM).removeClass(CLASS.CURRENT);
  35. var active_nav_items = 'a[href="' + article_id + '"][data-router="article"]';
  36. lng.Element.Cache.section.find(active_nav_items).addClass(CLASS.CURRENT);
  37. if (lng.Element.Cache.aside) {
  38. aside = lng.Element.Cache.aside;
  39. aside.find(SELECTORS.ASIDE_REFERENCE_LIST).removeClass(CLASS.CURRENT);
  40. aside.find(active_nav_items).addClass(CLASS.CURRENT).parent().addClass(CLASS.CURRENT);
  41. }
  42. };
  43. var switchReferenceItems = function(article_id, section) {
  44. article_id = article_id.replace('#', '');
  45. var links = section.find(SELECTORS.REFERENCE_LINK);
  46. for (var i = 0, len = links.length; i < len; i++) {
  47. var link = lng.dom(links[i]);
  48. if (link.data(ATTRIBUTE.ARTICLE) === article_id) {
  49. link.show();
  50. } else {
  51. link.hide();
  52. }
  53. }
  54. };
  55. return {
  56. title: title,
  57. switchReferenceItems: switchReferenceItems,
  58. switchNavItems: switchNavItems
  59. };
  60. })(Lungo);