瀏覽代碼

Some issues fixed

@soyjavi 14 年之前
父節點
當前提交
45af5038ea
共有 5 個文件被更改,包括 51 次插入45 次删除
  1. 5 6
      src/Lungo.Fallback.js
  2. 20 30
      src/boot/Lungo.Boot.Events.js
  3. 0 6
      src/boot/Lungo.Boot.Section.js
  4. 23 1
      src/router/Lungo.Router.js
  5. 3 2
      src/view/Lungo.View.Article.js

+ 5 - 6
src/Lungo.Fallback.js

@@ -9,19 +9,18 @@
 
 LUNGO.Fallback = (function(lng, undefined) {
 
-	var _environment;
 
     var androidButtons = function() {
-    	_environment = !! lng.Core.environment();
-        if (_environment.isMobile && _environment.os.name === 'android') {
+    	environment = lng.Core.environment();
+        if (environment.isMobile && environment.os.name === 'android') {
             lng.dom(document.body).on('touchstart', '.button', _addClassActiveToButton);
             lng.dom(document.body).on('touchend', '.button', _removeClassActiveToButton);
         }
     };
 
-    var positionFixed = function(section) {
-    	_environment = !! lng.Core.environment();
-        if (_environment.isMobile && _environment.os.name === 'ios' && _environment.os.version >= '4.2') {
+    var positionFixed = function(sections) {
+    	environment = lng.Core.environment();
+        if (environment.isMobile && environment.os.name === 'ios' && environment.os.version >= '4.2') {
             sections.style('position', 'fixed');
         }
     };

+ 20 - 30
src/boot/Lungo.Boot.Events.js

@@ -24,10 +24,10 @@ LUNGO.Boot.Events = (function(lng, undefined) {
 
         lng.dom(document).on(touch_move_event, _iScroll);
         lng.dom(window).on(orientation_change, _changeOrientation);
-        lng.dom(target_selector_from_aside).tap(_toggleAside);
+        lng.dom(target_selector_from_aside).tap(_loadTargetFromAside);
         lng.dom(target_selector).tap(_loadTarget);
 
-        _buttonsFeedbackInAndroid();
+        lng.Fallback.androidButtons();
     };
 
     var _iScroll = function(event) {
@@ -38,12 +38,22 @@ LUNGO.Boot.Events = (function(lng, undefined) {
         lng.View.Resize.toolbars();
     };
 
-    var _toggleAside = function(event) {
+    var _loadTargetFromAside = function(event) {
         var link = lng.dom(this);
-        var section_id =  _getParentIdOfElement(link);
-        lng.View.Aside.toggle(section_id);
+        var aside_id = '#' + link.parent('aside').attr('id');
+        var section_id = '#' + lng.dom('section.aside').first().attr('id');
+
+        if (link.data('target') === 'article') {
+            lng.dom('aside' + aside_id + ' a[href][data-target="article"]').removeClass('current');
+            link.addClass('current');
+        }
+        lng.View.Aside.hide(section_id, aside_id);
+
+        setTimeout(function() {
+
+            //event.preventDefault();
+        }, 1000);
 
-        event.preventDefault();
     };
 
     var _loadTarget = function(event) {
@@ -53,22 +63,6 @@ LUNGO.Boot.Events = (function(lng, undefined) {
         event.preventDefault();
     };
 
-    var _buttonsFeedbackInAndroid = function() {
-        var environment = lng.Core.environment();
-        if (environment.isMobile && environment.os.name === 'android') {
-            lng.dom(document.body).on('touchstart', '.button', _addClassActiveToButton);
-            lng.dom(document.body).on('touchend', '.button', _removeClassActiveToButton);
-        }
-    };
-
-    var _addClassActiveToButton = function(element) {
-        lng.dom(this).addClass('active');
-    };
-
-    var _removeClassActiveToButton = function(element) {
-        lng.dom(this).removeClass('active');
-    };
-
     var _selectTarget = function(link) {
         var target_type = link.data('target');
 
@@ -97,20 +91,16 @@ LUNGO.Boot.Events = (function(lng, undefined) {
     };
 
     var _goArticle = function(element) {
-        var section_id =  _getParentIdOfElement(element);
+        section_id = lng.Router.History.current();
         var article_id =  element.attr('href');
 
         lng.Router.article(section_id, article_id);
     };
 
     var _goAside = function(element) {
-        var section_id = _getParentIdOfElement(element);
-        lng.View.Aside.toggle(section_id);
-    };
-
-    var _getParentIdOfElement = function(element) {
-        var parent_id = '#' + element.parent('section').attr('id');
-        return parent_id;
+        var section_id = lng.Router.History.current();
+        var aside_id = element.attr('href');
+        lng.Router.aside(section_id, aside_id);
     };
 
     return {

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

@@ -24,10 +24,8 @@ LUNGO.Boot.Section = (function(lng, undefined) {
      */
     var start = function() {
         var sections = lng.dom(SELECTORS.SECTION);
-
         _initFirstSection(sections);
         _initAllSections(sections);
-        _initAllAsides();
 
         lng.View.Resize.toolbars();
     };
@@ -58,10 +56,6 @@ LUNGO.Boot.Section = (function(lng, undefined) {
         lng.View.Article.showReferenceLinks(section_id, first_article_id);
     };
 
-    var _initAllAsides = function() {
-        //lng.dom('aside').addClass('show');
-    };
-
     return {
         start: start
     };

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

@@ -12,7 +12,8 @@ LUNGO.Router = (function(lng, undefined) {
 
     var CSS_CLASSES = {
         SHOW: 'show',
-        HIDE: 'hide'
+        HIDE: 'hide',
+        ACTIVE: 'current'
     };
 
     /**
@@ -50,6 +51,26 @@ LUNGO.Router = (function(lng, undefined) {
         }
     };
 
+    /**
+     * Displays the <aside> in a particular <section>.
+     *
+     * @method aside
+     *
+     * @param {string} <section> Id
+     * @param {string} <aside> Id
+     */
+    var aside = function(section_id, aside_id) {
+        var target = 'aside' + aside_id;
+        if (aside_id !== '#' && _existsTarget(target)) {
+            var is_visible = lng.dom(target).hasClass(CSS_CLASSES.ACTIVE);
+            if (is_visible) {
+                lng.View.Aside.hide(section_id, aside_id);
+            } else {
+                lng.View.Aside.show(section_id, aside_id);
+            }
+        }
+    };
+
     /**
      * Return to previous section.
      *
@@ -80,6 +101,7 @@ LUNGO.Router = (function(lng, undefined) {
     return {
         section: section,
         article: article,
+        aside: aside,
         back: back
     };
 

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

@@ -12,8 +12,9 @@ LUNGO.View.Article = (function(lng, undefined) {
 
     var SELECTORS = {
         ARTICLE: 'article',
+        SECTION: 'section',
         NAVIGATION_ITEM: 'a',
-        REFERENCE_LINK: 'a[href][data-article]'
+        REFERENCE_LINK: ' a[href][data-article]'
     };
 
     var CSS_CLASSES = {
@@ -37,7 +38,7 @@ LUNGO.View.Article = (function(lng, undefined) {
      * @method showReferenceLinks
      */
     var showReferenceLinks = function(section_id, article_id) {
-        var links = lng.dom('section' + section_id + ' ' + SELECTORS.REFERENCE_LINK);
+        var links = lng.dom(SELECTORS.SECTION + section_id + SELECTORS.REFERENCE_LINK);
 
         for (var i = 0, len = links.length; i < len; i++) {
             var link = lng.dom(links[i]);