Parcourir la source

New method in CORE : parseUrl

… to return a correct URL using hashtag character
@soyjavi il y a 14 ans
Parent
commit
e33cb8f946
3 fichiers modifiés avec 31 ajouts et 22 suppressions
  1. 20 1
      src/Lungo.Core.js
  2. 4 2
      src/boot/Lungo.Boot.Events.js
  3. 7 19
      src/router/Lungo.Router.js

+ 20 - 1
src/Lungo.Core.js

@@ -11,6 +11,7 @@
 LUNGO.Core = (function(lng, $$, undefined) {
 
     var ARRAY_PROTO = Array.prototype;
+    var HASHTAG_CHARACTER = '#';
 
     /**
      * Console system to display messages when you are in debug mode.
@@ -157,6 +158,23 @@ LUNGO.Core = (function(lng, $$, undefined) {
         );
     };
 
+    /**
+     * Returns a correct URL using hashtag character
+     *
+     * @method parseUrl
+     *
+     * @return {string} Href
+     */
+    var parseUrl = function(href) {
+        var href_hashtag = href.lastIndexOf(HASHTAG_CHARACTER);
+        if (href_hashtag > 0) {
+            href = href.substring(href_hashtag);
+        } else if (href_hashtag === -1) {
+            href = HASHTAG_CHARACTER + href ;
+        }
+        return href;
+    };
+
     return {
         log: log,
         execute: execute,
@@ -167,7 +185,8 @@ LUNGO.Core = (function(lng, $$, undefined) {
         toArray: toArray,
         isMobile: isMobile,
         environment: environment,
-        orderByProperty: orderByProperty
+        orderByProperty: orderByProperty,
+        parseUrl: parseUrl
     };
 
 })(LUNGO, Quo);

+ 4 - 2
src/boot/Lungo.Boot.Events.js

@@ -18,12 +18,12 @@ LUNGO.Boot.Events = (function(lng, undefined) {
      */
     var start = function() {
         var touch_move_event  = 'touchmove';
-        var orientation_change = 'orientationchange';
+        var resize = 'resize';
         var target_selector = 'a[href][data-target]';
         var target_selector_from_aside = 'aside a[href][data-target]';
 
         lng.dom(document).on(touch_move_event, _iScroll);
-        lng.dom(window).on(orientation_change, _changeOrientation);
+        lng.dom(window).on(resize, _changeOrientation);
         lng.dom(target_selector_from_aside).tap(_loadTargetFromAside);
         lng.dom(target_selector).tap(_loadTarget);
 
@@ -83,6 +83,8 @@ LUNGO.Boot.Events = (function(lng, undefined) {
     };
 
     var _goSection = function(id) {
+        id = lng.Core.parseUrl(id);
+
         if (id === '#back') {
             lng.Router.back();
         } else {

+ 7 - 19
src/router/Lungo.Router.js

@@ -22,8 +22,6 @@ LUNGO.Router = (function(lng, undefined) {
         ASIDE: 'aside'
     }
 
-    var HASHTAG_CHARACTER = '#';
-
     /**
      * Navigate to a <section>.
      *
@@ -32,7 +30,7 @@ LUNGO.Router = (function(lng, undefined) {
      * @param {string} Id of the <section>
      */
     var section = function(section_id) {
-        var section_id = _parseUrl(section_id);
+        var section_id = lng.Core.parseUrl(section_id);
         var target = ELEMENT.SECTION + section_id;
 
         if (_existsTarget(target)) {
@@ -52,9 +50,9 @@ LUNGO.Router = (function(lng, undefined) {
      * @param {string} <article> Id
      */
     var article = function(section_id, article_id) {
-        var section_id = _parseUrl(section_id);
-        var article_id = _parseUrl(article_id);
-        var target = ELEMENT.SECTION + section_id + ' ' + ELEMENT.ARTICLE + _parseUrl(article_id);
+        var section_id = lng.Core.parseUrl(section_id);
+        var article_id = lng.Core.parseUrl(article_id);
+        var target = ELEMENT.SECTION + section_id + ' ' + ELEMENT.ARTICLE + article_id;
 
         if (_existsTarget(target)) {
             lng.View.Article.show(section_id, article_id);
@@ -70,9 +68,9 @@ LUNGO.Router = (function(lng, undefined) {
      * @param {string} <aside> Id
      */
     var aside = function(section_id, aside_id) {
-        var section_id = _parseUrl(section_id);
-        var aside_id = _parseUrl(aside_id);
-        var target = ELEMENT.ASIDE + _parseUrl(aside_id);
+        var section_id = lng.Core.parseUrl(section_id);
+        var aside_id = lng.Core.parseUrl(aside_id);
+        var target = ELEMENT.ASIDE + aside_id;
 
         if (_existsTarget(target)) {
             var is_visible = lng.dom(target).hasClass(CSS_CLASSES.ACTIVE);
@@ -96,16 +94,6 @@ LUNGO.Router = (function(lng, undefined) {
         lng.dom(_getHistoryCurrent()).removeClass(CSS_CLASSES.HIDE).addClass(CSS_CLASSES.SHOW);
     };
 
-    var _parseUrl = function(href) {
-        var href_hashtag = href.lastIndexOf(HASHTAG_CHARACTER);
-        if (href_hashtag > 0) {
-            href = href.substring(href_hashtag);
-        } else if (href_hashtag === -1) {
-            href = HASHTAG_CHARACTER + href ;
-        }
-        return href;
-    };
-
     var _existsTarget = function(target) {
         var exists = false;