Переглянути джерело

Optimized data-article reference

soyjavi 13 роки тому
батько
коміт
ef86bb903c
3 змінених файлів з 5 додано та 15 видалено
  1. 1 2
      example/index.html
  2. 2 1
      src/boot/Lungo.Boot.Layout.js
  3. 2 12
      src/view/Lungo.View.Article.js

+ 1 - 2
example/index.html

@@ -65,9 +65,8 @@
             <div class="left">
                 <div class="centered title">Lungo Framework</div>
             </div>
-
             <nav class="right box">
-                <a href="#" class="buttons" data-icon="share" data-article="main-article"></a>
+                <a href="#" data-icon="share"></a>
             </nav>
         </header>
 

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

@@ -33,6 +33,8 @@ Lungo.Boot.Layout = (function(lng, undefined) {
         lng.Element.Cache.section = section;
         lng.Element.Cache.article = section.children(ELEMENT.ARTICLE + "." + CLASS.ACTIVE);
 
+        lng.View.Article.switchReferenceItems(lng.Element.Cache.article.attr("id"), section);
+
         var section_id = '#' + section.attr(ATTRIBUTE.ID);
         lng.Router.History.add(section_id);
     };
@@ -52,7 +54,6 @@ Lungo.Boot.Layout = (function(lng, undefined) {
         }
     };
 
-
     var _scrollFix = function(element) {
         element[0].addEventListener('touchstart', function(event) {
             scrollTop = this.scrollTop;

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

@@ -47,18 +47,8 @@ Lungo.View.Article = (function(lng, undefined) {
     };
 
     var switchReferenceItems = function(article_id, section) {
-        article_id = article_id.replace('#', '');
-
-        var links = section.find(SELECTORS.REFERENCE_LINK);
-
-        for (var i = 0, len = links.length; i < len; i++) {
-            var link = lng.dom(links[i]);
-            if (link.data(ATTRIBUTE.ARTICLE) === article_id) {
-                link.show();
-            } else {
-                link.hide();
-            }
-        }
+        var reference = "[data-article=" + article_id.replace('#', '') + "]";
+        section.find(SELECTORS.REFERENCE_LINK).hide().siblings(reference).show();
     };
 
     return {