Lungo.Boot.Section.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * Initialize the <section> element
  3. *
  4. * @namespace LUNGO.Boot
  5. * @class Section
  6. *
  7. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  8. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  9. */
  10. LUNGO.Boot.Section = (function(lng, undefined) {
  11. var SELECTORS = {
  12. ARTICLE: 'article',
  13. SECTION: 'section'
  14. };
  15. var ACTIVE_CLASS = 'current';
  16. /**
  17. * Initializes all <section>s of the project
  18. *
  19. * @method init
  20. */
  21. var start = function() {
  22. var sections = lng.dom(SELECTORS.SECTION);
  23. _initFirstSection(sections);
  24. _initAllSections(sections);
  25. _initAllAsides();
  26. lng.View.Resize.toolbars();
  27. };
  28. var _initFirstSection = function(sections) {
  29. var first_section = sections.first();
  30. var first_section_id = '#' + first_section.attr('id');
  31. first_section.addClass(ACTIVE_CLASS);
  32. lng.Router.History.add(first_section_id);
  33. };
  34. var _initAllSections = function(sections) {
  35. if (lng.Core.isMobile()) {
  36. _setPositionFixedInIOS(sections);
  37. }
  38. for (var i = 0, len = sections.length; i < len; i++) {
  39. var section = lng.dom(sections[i]);
  40. _initArticles(section);
  41. }
  42. };
  43. var _initArticles = function(section) {
  44. var articles = section.children(SELECTORS.ARTICLE);
  45. _calculateArticleHeight(section, articles);
  46. var first_article = articles.first();
  47. first_article.addClass(ACTIVE_CLASS);
  48. var first_article_id = first_article.attr('id');
  49. var section_id = '#' + section.attr('id');
  50. lng.View.Article.showReferenceLinks(section_id, first_article_id);
  51. };
  52. var _calculateArticleHeight = function(section, articles) {
  53. var footer = section.children('footer');
  54. var header = section.children('header');
  55. var articles_height = window.innerHeight;
  56. if (footer.length > 0) {
  57. articles_height -= footer.height();
  58. }
  59. if (header.length > 0) {
  60. articles_height -= header.height();
  61. }
  62. articles.style('height', articles_height + 'px');
  63. }
  64. var _initAllAsides = function() {
  65. lng.dom('aside').addClass('show');
  66. };
  67. var _setPositionFixedInIOS = function(sections) {
  68. var environment = lng.Core.environment();
  69. if (environment.os.name === 'ios' && environment.os.version >= '4.') {
  70. sections.style('position', 'fixed');
  71. }
  72. }
  73. return {
  74. start: start
  75. };
  76. })(LUNGO);