Jelajahi Sumber

Fixed some issues visualizing active <nav> items

@soyjavi 14 tahun lalu
induk
melakukan
2d8f33599e

+ 7 - 2
src/boot/Lungo.Boot.Article.js

@@ -16,6 +16,11 @@ LUNGO.Boot.Article = (function(lng, undefined) {
         CHECKBOX_IN_ARTICLE: '.checkbox, .radio'
     };
 
+    var ELEMENT = {
+        LIST: '<ul></ul>',
+        SPAN: '<span>&nbsp;</span>'
+    }
+
     /**
      * Initializes the markup elements of an article
      *
@@ -39,7 +44,7 @@ LUNGO.Boot.Article = (function(lng, undefined) {
     var _createListElement = function(article) {
         if (article.children().length === 0) {
             var article_id = article.attr('id');
-            article.append('<ul></ul>');
+            article.append(ELEMENT.LIST);
         }
     };
 
@@ -49,7 +54,7 @@ LUNGO.Boot.Article = (function(lng, undefined) {
     };
 
     var _createCheckboxElement = function(checkbox) {
-        checkbox.append('<span>&nbsp;</span>');
+        checkbox.append(ELEMENT.SPAN);
     };
 
     return {

+ 0 - 6
src/boot/Lungo.Boot.Events.js

@@ -48,12 +48,6 @@ LUNGO.Boot.Events = (function(lng, undefined) {
             link.addClass('current');
         }
         lng.View.Aside.hide(section_id, aside_id);
-
-        setTimeout(function() {
-
-            //event.preventDefault();
-        }, 1000);
-
     };
 
     var _loadTarget = function(event) {

+ 11 - 7
src/view/Lungo.View.Article.js

@@ -13,7 +13,7 @@ LUNGO.View.Article = (function(lng, undefined) {
     var SELECTORS = {
         ARTICLE: 'article',
         SECTION: 'section',
-        NAVIGATION_ITEM: 'a',
+        NAVIGATION_ITEM: 'a[href][data-target="article"]',
         REFERENCE_LINK: ' a[href][data-article]'
     };
 
@@ -47,13 +47,17 @@ LUNGO.View.Article = (function(lng, undefined) {
     };
 
     var _toggleNavItems = function(section_id, article_id) {
-        var nav_items = section_id + ' ' + SELECTORS.NAVIGATION_ITEM;
-        lng.dom(nav_items).removeClass(CSS_CLASSES.ACTIVE);
+        var nav_items = lng.dom(section_id + ' ' + SELECTORS.NAVIGATION_ITEM);
+        nav_items.removeClass(CSS_CLASSES.ACTIVE);
 
-        var current_nav_item = lng.dom(nav_items + '[href="' + article_id + '"]');
-        if (current_nav_item.length > 0) {
-            current_nav_item.addClass(CSS_CLASSES.ACTIVE);
-            _setTitle(section_id, current_nav_item);
+        for (var i = 0, len = nav_items.length; i < len; i++) {
+            var nav_item = lng.dom(nav_items[i]);
+            var nav_item_parsed_url = lng.Core.parseUrl(nav_item.attr('href'));
+
+            if (nav_item_parsed_url === article_id) {
+                nav_item.addClass(CSS_CLASSES.ACTIVE);
+                _setTitle(section_id, nav_item);
+            }
         }
     };