From: Nicolas Coden Date: Tue, 9 Oct 2018 22:35:17 +0000 (+0200) Subject: fix: prevent Tabs/Accordion to scroll to others components' anchors X-Git-Tag: v6.6.0~3^2~84^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d4a13ead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git fix: prevent Tabs/Accordion to scroll to others components' anchors Related to https://github.com/zurb/foundation-sites/issues/11527 --- diff --git a/js/foundation.accordion.js b/js/foundation.accordion.js index 13ab360d6..a8aa3b43a 100644 --- a/js/foundation.accordion.js +++ b/js/foundation.accordion.js @@ -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 diff --git a/js/foundation.tabs.js b/js/foundation.tabs.js index d780646c0..151312461 100644 --- a/js/foundation.tabs.js +++ b/js/foundation.tabs.js @@ -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