Bläddra i källkod

DOMHandler Perfomance: Aside Element

@soyjavi 14 år sedan
förälder
incheckning
a7e8f015f0
2 ändrade filer med 21 tillägg och 37 borttagningar
  1. 10 24
      src/router/Lungo.Router.js
  2. 11 13
      src/view/Lungo.View.Aside.js

+ 10 - 24
src/router/Lungo.Router.js

@@ -37,7 +37,7 @@ LUNGO.Router = (function(lng, undefined) {
 
         if (_notCurrentTarget(section_id, current)) {
             var target = lng.dom(ELEMENT.SECTION + section_id);
-            if (target) {
+            if (target.length > 0) {
                 current.removeClass(CLASS.SHOW).addClass(CLASS.HIDE).trigger(TRIGGER.UNLOAD);
                 target.addClass(CLASS.SHOW).trigger(TRIGGER.LOAD);
                 lng.Element.Current.section = target;
@@ -61,7 +61,7 @@ LUNGO.Router = (function(lng, undefined) {
 
         if (_notCurrentTarget(article_id, current)) {
             var target = lng.dom(ELEMENT.SECTION + section_id + ' ' + ELEMENT.ARTICLE + article_id);
-            if (target) {
+            if (target.length > 0) {
                 current.removeClass(CLASS.CURRENT).trigger(TRIGGER.UNLOAD);
                 target.addClass(CLASS.CURRENT).trigger(TRIGGER.LOAD);
                 lng.Element.Current.article = target;
@@ -82,16 +82,18 @@ LUNGO.Router = (function(lng, undefined) {
     var aside = function(section_id, aside_id) {
         section_id = lng.Core.parseUrl(section_id);
         aside_id = lng.Core.parseUrl(aside_id);
-        var target = ELEMENT.ASIDE + aside_id;
+        var target = lng.dom(ELEMENT.ASIDE + aside_id);
 
-        if (_exists(target)) {
-            var is_visible = lng.dom(target).hasClass(CLASS.CURRENT);
+        if (target.length > 0) {
+            var is_visible = target.hasClass(CLASS.CURRENT);
             if (is_visible) {
-                lng.View.Aside.hide(section_id, aside_id);
+                lng.View.Aside.hide(section_id, target);
             } else {
-                lng.View.Aside.show(section_id, aside_id);
+                lng.View.Aside.show(section_id, target);
             }
         }
+
+        target = null;
     };
 
     /**
@@ -105,7 +107,7 @@ LUNGO.Router = (function(lng, undefined) {
 
         lng.Router.History.removeLast();
 
-        target = lng.dom(_getHistoryCurrent());
+        target = lng.dom(lng.Router.History.current());
         target.removeClass(CLASS.HIDE).addClass(CLASS.SHOW);
         lng.Element.Current.section = target;
     };
@@ -114,22 +116,6 @@ LUNGO.Router = (function(lng, undefined) {
         return (target !== HASHTAG_CHARACTER + element.attr('id')) ? true : false;
     };
 
-    var _exists = function(target) {
-        var exists = false;
-
-        if (lng.dom(target).length > 0) {
-            exists = true;
-        } else {
-            lng.Core.log(3, ERROR.ROUTER + target);
-        }
-
-        return exists;
-    };
-
-    var _getHistoryCurrent = function() {
-        return lng.Router.History.current();
-    };
-
     return {
         section: section,
         article: article,

+ 11 - 13
src/view/Lungo.View.Aside.js

@@ -22,13 +22,12 @@ LUNGO.View.Aside = (function(lng, undefined) {
      * @param  {string} Section id
      * @param  {string} Aside id
      */
-    var show = function(section_id, aside_id) {
-        var aside = lng.dom(ELEMENT.ASIDE + aside_id);
-        var aside_class = _asideClass(aside);
+    var show = function(section_id, aside) {
+        var aside_stylesheet = _asideStylesheet(aside);
         var section = lng.dom(ELEMENT.SECTION + section_id);
 
         aside.addClass(CLASS.CURRENT);
-        section.addClass(aside_class).addClass(CLASS.ASIDE);
+        section.addClass(aside_stylesheet).addClass(CLASS.ASIDE);
     };
 
     /**
@@ -39,26 +38,25 @@ LUNGO.View.Aside = (function(lng, undefined) {
      * @param  {string} Element query selector
      * @param  {string} Value for counter
      */
-    var hide = function(section_id, aside_id) {
-        var aside = lng.dom(ELEMENT.ASIDE + aside_id);
-        var aside_class = _asideClass(aside);
+    var hide = function(section_id, aside) {
+        var aside_stylesheet = _asideStylesheet(aside);
         var section = lng.dom(ELEMENT.SECTION + section_id);
 
-        section.removeClass(CLASS.ASIDE).removeClass(aside_class);
+        section.removeClass(CLASS.ASIDE).removeClass(aside_stylesheet);
 
         setTimeout(function() {
             aside.removeClass(CLASS.CURRENT);
         }, 300);
     };
 
-    var _asideClass = function(aside) {
-        var aside_class = aside.attr(ATTRIBUTE.CLASS);
+    var _asideStylesheet = function(aside) {
+        var aside_stylesheet = aside.attr(ATTRIBUTE.CLASS);
         var classes = '';
 
         //@todo: Refactor
-        if (aside_class) {
-            classes += (aside_class.indexOf(CLASS.RIGHT) > -1) ? CLASS.RIGHT : '';
-            classes += (aside_class.indexOf(CLASS.SMALL) > -1) ? CLASS.SMALL : '';
+        if (aside_stylesheet) {
+            classes += (aside_stylesheet.indexOf(CLASS.RIGHT) > -1) ? CLASS.RIGHT : '';
+            classes += (aside_stylesheet.indexOf(CLASS.SMALL) > -1) ? CLASS.SMALL : '';
         }
 
         return classes;