Lungo.View.Article.coffee 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ###
  2. Initialize the <articles> layout of a certain <section>
  3. @namespace Lungo.View
  4. @class Article
  5. @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  6. @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  7. ###
  8. Lungo.View.Article = do(lng = Lungo) ->
  9. ELEMENT = lng.Constants.ELEMENT
  10. CLASS = lng.Constants.CLASS
  11. ATTRIBUTE = lng.Constants.ATTRIBUTE
  12. SELECTORS =
  13. NAVIGATION_ITEM: "a[href][data-router=\"article\"]"
  14. REFERENCE_LINK: " a[href][data-article]"
  15. TITLE_OF_ARTICLE: "header .title, footer .title"
  16. ASIDE_REFERENCE_LIST: "li a.active, li.active"
  17. ###
  18. ?
  19. @method show
  20. ###
  21. title = (value) ->
  22. lng.Element.Cache.section.find(SELECTORS.TITLE_OF_ARTICLE).text value if value
  23. switchNavItems = (article_id) ->
  24. lng.Element.Cache.section.find(SELECTORS.NAVIGATION_ITEM).removeClass CLASS.ACTIVE
  25. active_nav_items = "a[href=\"" + article_id + "\"][data-router=\"article\"]"
  26. lng.Element.Cache.section.find(active_nav_items).addClass CLASS.ACTIVE
  27. if lng.Element.Cache.aside
  28. aside = lng.Element.Cache.aside
  29. aside.find(SELECTORS.ASIDE_REFERENCE_LIST).removeClass CLASS.ACTIVE
  30. aside.find(active_nav_items).addClass(CLASS.ACTIVE).parent().addClass CLASS.ACTIVE
  31. switchReferenceItems = (article_id, section) ->
  32. reference = "[data-article=" + article_id.replace("#", "") + "]"
  33. section.find(SELECTORS.REFERENCE_LINK).hide().siblings(reference).show()
  34. title: title
  35. switchReferenceItems: switchReferenceItems
  36. switchNavItems: switchNavItems