Explorar el Código

New attribute data-article for reference links to determinate <article>

@soyjavi hace 14 años
padre
commit
6e0c765e5a
Se han modificado 2 ficheros con 33 adiciones y 5 borrados
  1. 8 3
      src/boot/Lungo.Boot.Section.js
  2. 25 2
      src/view/Lungo.View.Article.js

+ 8 - 3
src/boot/Lungo.Boot.Section.js

@@ -47,12 +47,17 @@ LUNGO.Boot.Section = (function(lng, undefined) {
 
         for (var i = 0, len = sections.length; i < len; i++) {
             var section = lng.dom(sections[i]);
-            _initFirstArticle(section);
+            _initArticles(section);
         }
     };
 
-    var _initFirstArticle = function(section) {
-        section.children(SELECTORS.ARTICLE).first().addClass(ACTIVE_CLASS);
+    var _initArticles = function(section) {
+        var first_article = section.children(SELECTORS.ARTICLE).first();
+        first_article.addClass(ACTIVE_CLASS);
+
+        var first_article_id = first_article.attr('id');
+        var section_id = '#' + section.attr('id');
+        lng.View.Article.showReferenceLinks(section_id, first_article_id);
     };
 
     var _initAllAsides = function() {

+ 25 - 2
src/view/Lungo.View.Article.js

@@ -12,13 +12,19 @@ LUNGO.View.Article = (function(lng, undefined) {
 
     var SELECTORS = {
         ARTICLE: 'article',
-        NAVIGATION_ITEM: 'a'
+        NAVIGATION_ITEM: 'a',
+        REFERENCE_LINK: 'a[href][data-article]'
     };
 
     var CSS_CLASSES = {
         ACTIVE: 'current'
     };
 
+    /**
+     * ?
+     *
+     * @method show
+     */
     var show = function(section_id, article_id) {
         var nav_items = section_id + ' ' + SELECTORS.NAVIGATION_ITEM;
         _disableNavItems(nav_items);
@@ -27,9 +33,25 @@ LUNGO.View.Article = (function(lng, undefined) {
         current_nav_item.addClass(CSS_CLASSES.ACTIVE);
         _setTitle(section_id, current_nav_item);
 
+        showReferenceLinks(section_id, article_id.replace('#', ''));
+
         _showContainer(section_id, article_id);
     };
 
+    /**
+     * ?
+     *
+     * @method showReferenceLinks
+     */
+    var showReferenceLinks = function(section_id, article_id) {
+        var links = lng.dom('section' + section_id + ' ' + SELECTORS.REFERENCE_LINK);
+
+        for (var i = 0, len = links.length; i < len; i++) {
+            var link = lng.dom(links[i]);
+            (link.data('article') === article_id) ? link.show() : link.hide();
+        }
+    };
+
     var _disableNavItems = function(items) {
         lng.dom(items).removeClass(CSS_CLASSES.ACTIVE);
     };
@@ -50,7 +72,8 @@ LUNGO.View.Article = (function(lng, undefined) {
     };
 
     return {
-        show: show
+        show: show,
+        showReferenceLinks: showReferenceLinks
     };
 
 })(LUNGO);