Parcourir la source

New namespace for Device

soyjavi il y a 13 ans
Parent
commit
6dea66a7e4

+ 31 - 0
src/boot/Lungo.Boot.Device.js

@@ -0,0 +1,31 @@
+/**
+ * @todo
+ *
+ * @namespace Lungo.Boot
+ * @class Device
+ *
+ * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
+ */
+
+Lungo.Boot.Device = (function(lng, undefined) {
+
+    var DEVICE = lng.Constants.DEVICE;
+
+    /**
+     * @todo
+     *
+     * @method init
+     *
+     */
+    var init = function() {
+        env = lng.Core.environment();
+        lng.DEVICE = env.screen.width < 768 ? DEVICE.PHONE: DEVICE.TABLET;
+
+        lng.dom(document.body).data("data", lng.DEVICE);
+    };
+
+    return {
+        init: init
+    };
+
+})(Lungo);

+ 0 - 1
src/boot/Lungo.Boot.Layout.js

@@ -21,7 +21,6 @@ Lungo.Boot.Layout = (function(lng, undefined) {
      *
      */
     var init = function() {
-        lng.Fallback.detectDevice();
         lng.Fallback.fixPositionInAndroid();
 
         _initFirstSection();

+ 5 - 4
src/modules/Lungo.Constants.js

@@ -22,7 +22,8 @@ Lungo.Constants = {
 
     QUERY: {
         LIST_IN_ELEMENT: 'article.list, aside.list',
-        ELEMENT_SCROLLABLE: 'aside.scroll, article.scroll'
+        ELEMENT_SCROLLABLE: 'aside.scroll, article.scroll',
+        HREF_ASIDE: 'header a[href][data-router=aside]'
     },
 
     CLASS: {
@@ -70,9 +71,9 @@ Lungo.Constants = {
     },
 
     DEVICE: {
-        phone: 'phone',
-        tablet: 'tablet',
-        tv: 'tv'
+        PHONE: 'phone',
+        TABLET: 'tablet',
+        TV: 'tv'
     },
 
     ERROR: {

+ 1 - 8
src/modules/Lungo.Fallback.js

@@ -14,19 +14,12 @@ Lungo.Fallback = (function(lng, undefined) {
         _data("position", (env.isMobile && env.os.name === 'Android' && env.os.version < "3") ? "absolute" : "fixed");
     };
 
-    var detectDevice = function() {
-        env = lng.Core.environment();
-        lng.DEVICE = env.screen.width < 768 ? "phone": "tablet";
-        _data("device", lng.DEVICE);
-    };
-
     var _data = function(key, value) {
         lng.dom(document.body).data(key, value);
     };
 
     return {
-        fixPositionInAndroid: fixPositionInAndroid,
-        detectDevice: detectDevice
+        fixPositionInAndroid: fixPositionInAndroid
     };
 
 })(Lungo);

+ 1 - 0
src/modules/Lungo.Init.js

@@ -12,6 +12,7 @@ Lungo.init = function(config) {
         Lungo.Resource.load(config.resources);
     }
 
+    Lungo.Boot.Device.init();
     Lungo.Boot.Events.init();
     Lungo.Boot.Data.init();
     Lungo.Boot.Layout.init();

+ 1 - 1
src/router/Lungo.Router.js

@@ -171,7 +171,7 @@ Lungo.Router = (function(lng, undefined) {
 
     var _asideAttached = function(target) {
         if (lng.Element.Cache.aside) lng.Element.Cache.aside.removeClass(CLASS.SHOW);
-        if (target.data("aside") && lng.DEVICE != DEVICE.phone) {
+        if (target.data("aside") && lng.DEVICE != DEVICE.PHONE) {
             lng.View.Aside.show(target.data("aside"));
         }
     };

+ 12 - 4
src/view/Lungo.View.Aside.js

@@ -13,6 +13,8 @@ Lungo.View.Aside = (function(lng, undefined) {
     var CLASS = lng.Constants.CLASS;
     var ATTRIBUTE = lng.Constants.ATTRIBUTE;
     var DEVICE = lng.Constants.DEVICE;
+    var QUERY = lng.Constants.QUERY;
+
 
     /**
      * Toggle an aside element
@@ -47,7 +49,7 @@ Lungo.View.Aside = (function(lng, undefined) {
             lng.Element.Cache.aside = aside;
 
             aside.addClass(CLASS.SHOW);
-            if (lng.DEVICE == DEVICE.phone) {
+            if (lng.DEVICE == DEVICE.PHONE) {
                 var aside_stylesheet = _asideStylesheet(aside);
                 lng.Element.Cache.section.addClass(aside_stylesheet).addClass(CLASS.ASIDE);
             }
@@ -62,7 +64,7 @@ Lungo.View.Aside = (function(lng, undefined) {
      * @method hide
      */
     var hide = function(target) {
-        if (lng.DEVICE == DEVICE.phone) {
+        if (lng.DEVICE == DEVICE.PHONE) {
 
             var aside = target || lng.Element.Cache.aside;
             if (aside) {
@@ -82,9 +84,15 @@ Lungo.View.Aside = (function(lng, undefined) {
         }
     };
 
-    var suscribeEvents = function(hrefs) {
+    /**
+     * @todo
+     *
+     * @method suscribeEvents
+     */
+    var suscribeEvents = function() {
+
         var MIN_XDIFF = parseInt(document.body.getBoundingClientRect().width / 3, 10);
-        hrefs.each(function() {
+        lng.dom(QUERY.HREF_ASIDE).each(function() {
             var STARTED = false;
             var a = lng.dom(this);
             var section = a.closest("section");