]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
Use pull request #10837 from nicolasv/bugfix/10836-magellan-clear-hash for v6.5.0
authorNicolas Venegas <nvenegas@atlassian.com>
Sat, 16 Jun 2018 07:09:37 +0000 (09:09 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Sat, 16 Jun 2018 07:09:37 +0000 (09:09 +0200)
9b8129a10 chore: Fix != comparison in Magellan.
6fb7092fd Clear hash in Magellan deep linking when there is no active link.
ba938ce7b fix: prevent to loose query params when reseting hash in magellan

Co-Authored-By: Nicolas Coden <nicolas@ncoden.fr>
Signed-off-by: Nicolas Coden <nicolas@ncoden.fr>
js/foundation.magellan.js

index c6c9c94210fda00ed25e02d3dda44819db474781..91bdf8bb123535164f10917cff02aa27fd443c09 100644 (file)
@@ -165,16 +165,23 @@ class Magellan extends Plugin {
     }
 
     this.$active.removeClass(this.options.activeClass);
-    this.$active = this.$links.filter('[href="#' + this.$targets.eq(curIdx).data('magellan-target') + '"]').addClass(this.options.activeClass);
+    if(curIdx !== undefined){
+      this.$active = this.$links.filter('[href="#' + this.$targets.eq(curIdx).data('magellan-target') + '"]').addClass(this.options.activeClass);
+    }else{
+      this.$active = $();
+    }
 
     if(this.options.deepLinking){
       var hash = "";
-      if(curIdx != undefined){
+      if(curIdx !== undefined){
         hash = this.$active[0].getAttribute('href');
       }
       if(hash !== window.location.hash) {
         if(window.history.pushState){
-          window.history.pushState(null, null, hash);
+          // If there is no active idx, move to the same url without hash
+          // https://stackoverflow.com/a/5298684/4317384
+          var url = curIdx !== undefined ? hash : window.location.pathname + window.location.search;
+          window.history.pushState(null, null, url);
         }else{
           window.location.hash = hash;
         }