]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fix: prevent Tabs/Accordion to scroll to others components' anchors
authorNicolas Coden <nicolas@ncoden.fr>
Tue, 9 Oct 2018 22:35:17 +0000 (00:35 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Tue, 9 Oct 2018 22:35:17 +0000 (00:35 +0200)
Related to https://github.com/zurb/foundation-sites/issues/11527

js/foundation.accordion.js
js/foundation.tabs.js

index 13ab360d61d63b30d6cd31d31410f7468df61376..a8aa3b43a849b75fd0ae9bf954ebc20d8be12714 100644 (file)
@@ -81,6 +81,8 @@ class Accordion extends Plugin {
 
       var $anchor = anchor && $(anchor);
       var $link = anchor && this.$element.find(`[href$="${anchor}"]`);
+      // Whether the anchor element that has been found is part of this element
+      var isOwnAnchor = !!($anchor.length && $link.length);
 
       // If there is an anchor for the hash, open it (if not already active)
       if ($anchor && $link && $link.length) {
@@ -93,15 +95,15 @@ class Accordion extends Plugin {
         this._closeAllTabs();
       }
 
-      // Roll up a little to show the titles
-      if (this.options.deepLinkSmudge) {
-        onLoad($(window), () => {
-          var offset = this.$element.offset();
-          $('html, body').animate({ scrollTop: offset.top }, this.options.deepLinkSmudgeDelay);
-        });
-      }
+      if (isOwnAnchor) {
+        // Roll up a little to show the titles
+        if (this.options.deepLinkSmudge) {
+          onLoad($(window), () => {
+            var offset = this.$element.offset();
+            $('html, body').animate({ scrollTop: offset.top }, this.options.deepLinkSmudgeDelay);
+          });
+        }
 
-      if ($anchor && $link) {
         /**
          * Fires when the plugin has deeplinked at pageload
          * @event Accordion#deeplink
index d780646c0a9ac3f4baea77396dae5da9da1b09aa..151312461db09cb1fc45b7ec4f0f692eff44e6f2 100644 (file)
@@ -116,6 +116,8 @@ class Tabs extends Plugin {
       var anchorNoHash = anchor.indexOf('#') >= 0 ? anchor.slice(1) : anchor;
       var $anchor = anchorNoHash && $(`#${anchorNoHash}`);
       var $link = anchor && this.$element.find(`[href$="${anchor}"],[data-tabs-target="${anchorNoHash}"]`).first();
+      // Whether the anchor element that has been found is part of this element
+      var isOwnAnchor = !!($anchor.length && $link.length);
 
       // If there is an anchor for the hash, select it
       if ($anchor && $anchor.length && $link && $link.length) {
@@ -126,13 +128,13 @@ class Tabs extends Plugin {
         this._collapse();
       }
 
-      // Roll up a little to show the titles
-      if (this.options.deepLinkSmudge) {
-        var offset = this.$element.offset();
-        $('html, body').animate({ scrollTop: offset.top }, this.options.deepLinkSmudgeDelay);
-      }
+      if (isOwnAnchor) {
+        // Roll up a little to show the titles
+        if (this.options.deepLinkSmudge) {
+          var offset = this.$element.offset();
+          $('html, body').animate({ scrollTop: offset.top }, this.options.deepLinkSmudgeDelay);
+        }
 
-      if ($anchor && $link) {
         /**
          * Fires when the plugin has deeplinked at pageload
          * @event Tabs#deeplink