]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fix: ensure Tab deep-linking to redirect to hash with "#"
authorNicolas Coden <nicolas@ncoden.fr>
Tue, 9 Oct 2018 22:36:54 +0000 (00:36 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Tue, 9 Oct 2018 22:36:54 +0000 (00:36 +0200)
Related to https://github.com/zurb/foundation-sites/issues/11527

js/foundation.tabs.js

index 151312461db09cb1fc45b7ec4f0f692eff44e6f2..cf86e5d4e69c3efdb2e06445ac1015186f759f09 100644 (file)
@@ -258,8 +258,9 @@ class Tabs extends Plugin {
     var $oldTab = this.$element.
           find(`.${this.options.linkClass}.${this.options.linkActiveClass}`),
           $tabLink = $target.find('[role="tab"]'),
-          hash = $tabLink.attr('data-tabs-target') || $tabLink[0].hash.slice(1),
-          $targetContent = this.$tabContent.find(`#${hash}`);
+          target = $tabLink.attr('data-tabs-target'),
+          anchor = target && target.length ? `#${target}` : $tabLink[0].hash,
+          $targetContent = this.$tabContent.find(anchor);
 
     //close old tab
     this._collapseTab($oldTab);
@@ -270,9 +271,9 @@ class Tabs extends Plugin {
     //either replace or update browser history
     if (this.options.deepLink && !historyHandled) {
       if (this.options.updateHistory) {
-        history.pushState({}, '', hash);
+        history.pushState({}, '', anchor);
       } else {
-        history.replaceState({}, '', hash);
+        history.replaceState({}, '', anchor);
       }
     }