Ver Fonte

New boot rutine

soyjavi há 13 anos atrás
pai
commit
7e058d3b46

+ 6 - 2
src/Lungo.Constants.js

@@ -16,8 +16,12 @@ Lungo.Constants = {
         BODY: 'body',
         DIV: 'div',
         LIST: '<ul></ul>',
-        LI: 'li',
-        SPAN: '<span>&nbsp;</span>'
+        LI: 'li'
+    },
+
+    QUERY: {
+        LIST_IN_ARTICLE: 'article.list, aside.list',
+        ARTICLE_SCROLLABLE: 'article.scroll'
     },
 
     CLASS: {

+ 3 - 4
src/Lungo.Init.js

@@ -9,11 +9,10 @@
 
 Lungo.init = function(config) {
     if (config && config.resources) {
-        Lungo.Boot.Resources.init(config.resources);
+        Lungo.Resource.load(config.resources);
     }
-    Lungo.Boot.Layout.init();
+
     Lungo.Boot.Events.init();
     Lungo.Boot.Data.init();
-    Lungo.Boot.Section.init();
-    Lungo.Boot.Article.init();
+    Lungo.Boot.Layout.init();
 };

+ 0 - 67
src/boot/Lungo.Boot.Article.js

@@ -1,67 +0,0 @@
-/**
- * Initialize the <article> element
- *
- * @namespace Lungo.Boot
- * @class Article
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
-
-Lungo.Boot.Article = (function(lng, undefined) {
-
-    var ATTRIBUTE = lng.Constants.ATTRIBUTE;
-    var ELEMENT = lng.Constants.ELEMENT;
-    var SELECTORS = {
-        LIST_IN_ARTICLE: 'article.list, aside.list',
-        CHECKBOX_IN_ARTICLE: '.checkbox',
-        ARTICLE_SCROLLABLE: 'article.scroll'
-    };
-
-    /**
-     * Initializes the markup elements of an article
-     *
-     * @method init
-     */
-    var init = function() {
-        _initElement(SELECTORS.LIST_IN_ARTICLE, _createListElement);
-        _initElement(SELECTORS.CHECKBOX_IN_ARTICLE, _createCheckboxElement);
-        _initElement(SELECTORS.ARTICLE_SCROLLABLE, _scrollFix);
-    };
-
-    var _initElement = function(selector, callback) {
-        var found_elements = lng.dom(selector);
-        for (var i = 0, len = found_elements.length; i < len; i++) {
-            var element = lng.dom(found_elements[i]);
-            lng.Core.execute(callback, element);
-        }
-    };
-
-    var _createListElement = function(article) {
-        if (article.children().length === 0) {
-            var article_id = article.attr(ATTRIBUTE.ID);
-            article.append(ELEMENT.LIST);
-        }
-    };
-
-    var _createCheckboxElement = function(checkbox) {
-        checkbox.append(ELEMENT.SPAN);
-    };
-
-    var _scrollFix = function(article) {
-        article[0].addEventListener('touchstart', function(event) {
-            scrollTop = this.scrollTop;
-            if(scrollTop <= 1) {
-                this.scrollTop = 1;
-            }
-            if(scrollTop + this.offsetHeight >= this.scrollHeight) {
-                this.scrollTop = this.scrollHeight - this.offsetHeight - 1;
-            }
-        }, false);
-    };
-
-    return {
-        init: init
-    };
-
-})(Lungo);

+ 1 - 1
src/boot/Lungo.Boot.Events.js

@@ -74,7 +74,7 @@ Lungo.Boot.Events = (function(lng, undefined) {
 
     var _loadAsyncTarget = function(link) {
         lng.Notification.show();
-        lng.Boot.Resources.load(link.data("async"));
+        lng.Resource.load(link.data("async"));
         link[0].removeAttribute("data-async");
         lng.Boot.Data.init( link.attr(ATTRIBUTE.HREF) );
 

+ 38 - 33
src/boot/Lungo.Boot.Layout.js

@@ -9,56 +9,61 @@
 
 Lungo.Boot.Layout = (function(lng, undefined) {
 
-    var _window = null;
-    var _document = null;
-
     var ELEMENT = lng.Constants.ELEMENT;
+    var CLASS = lng.Constants.CLASS;
     var ATTRIBUTE = lng.Constants.ATTRIBUTE;
+    var QUERY = lng.Constants.QUERY;
 
     /**
-     * Initializes the automatic subscription events by markup of the project.
+     * Initializes all <section> & <article> of the project
      *
      * @method init
      *
      */
     var init = function() {
-        if (lng.Core.isMobile()) {
-            _resizeLayout();
-        }
+        lng.Element.Cache.asides = lng.dom(ELEMENT.ASIDE);
+        lng.Fallback.fixPositionInAndroid();
+
+        _initFirstSection();
+        _initArticleElement(QUERY.LIST_IN_ARTICLE, _createListElement);
+        _initArticleElement(QUERY.ARTICLE_SCROLLABLE, _scrollFix);
     };
 
-    var _resizeLayout = function() {
-        _window = window;
-        if (_window.innerHeight == 356) {
-            var _height = 416;
+    var _initFirstSection = function() {
+        var section = lng.dom(ELEMENT.SECTION).first().addClass(CLASS.SHOW);
+        lng.Element.Cache.section = section;
+        lng.Element.Cache.article = section.children(ELEMENT.ARTICLE + "." + CLASS.ACTIVE);
 
-            lng.dom(ELEMENT.BODY).style(ATTRIBUTE.HEIGHT, _height + ATTRIBUTE.PIXEL);
-            _hideNavigationBar();
-        }
+        var section_id = '#' + section.attr(ATTRIBUTE.ID);
+        lng.Router.History.add(section_id);
     };
 
-    var _hideNavigationBar = function() {
-        if( !location.hash || !_window.addEventListener ) {
-            _document = _window.document;
+    var _initArticleElement = function(selector, callback) {
+        var found_elements = lng.dom(selector);
+        for (var i = 0, len = found_elements.length; i < len; i++) {
+            var element = lng.dom(found_elements[i]);
+            lng.Core.execute(callback, element);
+        }
+    };
 
-            _window.scrollTo( 0, 1 );
-            var scrollTop = 1,
+    var _createListElement = function(article) {
+        if (article.children().length === 0) {
+            var article_id = article.attr(ATTRIBUTE.ID);
+            article.append(ELEMENT.LIST);
+        }
+    };
 
-            //reset to 0 on bodyready, if needed
-            bodycheck = setInterval(function(){
-                if( _document.body ){
-                    clearInterval( bodycheck );
-                    scrollTop = 'scrollTop' in _document.body ? _document.body.scrollTop : 1;
-                    _window.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
-                }
-            }, 15 );
 
-            _window.addEventListener('load', function(){
-                setTimeout(function(){
-                    _window.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
-                }, 0);
-            }, false );
-        }
+    var _scrollFix = function(article) {
+        article[0].addEventListener('touchstart', function(event) {
+            scrollTop = this.scrollTop;
+            if(scrollTop <= 1) {
+                this.scrollTop = 1;
+            }
+            if(scrollTop + this.offsetHeight >= this.scrollHeight) {
+                this.scrollTop = this.scrollHeight - this.offsetHeight - 1;
+            }
+        }, false);
     };
 
     return {

+ 0 - 46
src/boot/Lungo.Boot.Section.js

@@ -1,46 +0,0 @@
-/**
- * Initialize the <section> element
- *
- * @namespace Lungo.Boot
- * @class Section
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
-
-Lungo.Boot.Section = (function(lng, undefined) {
-
-    var ELEMENT = lng.Constants.ELEMENT;
-    var CLASS = lng.Constants.CLASS;
-    var ATTRIBUTE = lng.Constants.ATTRIBUTE;
-
-    /**
-     * Initializes all <section>s of the project
-     *
-     * @method init
-     */
-    var init = function() {
-        _cacheDOMElements();
-        lng.Fallback.fixPositionInAndroid();
-
-        _initFirstSection();
-    };
-
-    var _initFirstSection = function() {
-        var section = lng.dom(ELEMENT.SECTION).first().addClass(CLASS.SHOW);
-        lng.Element.Cache.section = section;
-        lng.Element.Cache.article = section.children(ELEMENT.ARTICLE + "." + CLASS.ACTIVE);
-
-        var section_id = '#' + section.attr(ATTRIBUTE.ID);
-        lng.Router.History.add(section_id);
-    };
-
-    var _cacheDOMElements = function() {
-        lng.Element.Cache.asides = lng.dom(ELEMENT.ASIDE);
-    };
-
-    return {
-        init: init
-    };
-
-})(Lungo);

+ 1 - 1
vendor/build.sh

@@ -78,7 +78,7 @@ decho "============================ LUNGO COMPILER ============================"
     #Boot
     DIR=$LUNGO_SOURCES"boot/"$LUNGO_NAMESPACE"Boot."
     decho "  [DIR]: ${LUNGO_SOURCES}boot/"
-    FILES="Layout.js Events.js Data.js Section.js Article.js"
+    FILES="Events.js Data.js Layout.js"
     for file in ${FILES} ; do
         FILES_TO_COMPILE=$FILES_TO_COMPILE" --js "$DIR$file
         FILES_TO_JOIN=$FILES_TO_JOIN" "$DIR$file