From: Nicolas Venegas Date: Sat, 16 Jun 2018 07:09:37 +0000 (+0200) Subject: Use pull request #10837 from nicolasv/bugfix/10836-magellan-clear-hash for v6.5.0 X-Git-Tag: v6.5.0-rc.1^2~172 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73ea6007a865cfaf271b35099ad8183241836a5e;p=thirdparty%2Ffoundation%2Ffoundation-sites.git Use pull request #10837 from nicolasv/bugfix/10836-magellan-clear-hash for v6.5.0 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 Signed-off-by: Nicolas Coden --- diff --git a/js/foundation.magellan.js b/js/foundation.magellan.js index c6c9c9421..91bdf8bb1 100644 --- a/js/foundation.magellan.js +++ b/js/foundation.magellan.js @@ -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; }