From: Nicolas Coden Date: Tue, 9 Oct 2018 21:49:11 +0000 (+0200) Subject: fix: fix scroll to deep-linking default anchor on initialization in Tabs/Accordion X-Git-Tag: v6.6.0~3^2~84^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=33c55db80;p=thirdparty%2Ffoundation%2Ffoundation-sites.git fix: fix scroll to deep-linking default anchor on initialization in Tabs/Accordion Related to https://github.com/zurb/foundation-sites/issues/11527 --- diff --git a/js/foundation.accordion.js b/js/foundation.accordion.js index 78bf35aa8..13ab360d6 100644 --- a/js/foundation.accordion.js +++ b/js/foundation.accordion.js @@ -40,6 +40,8 @@ class Accordion extends Plugin { * @private */ _init() { + this._isInitializing = true; + this.$element.attr('role', 'tablist'); this.$tabs = this.$element.children('[data-accordion-item]'); @@ -70,9 +72,11 @@ class Accordion extends Plugin { this._checkDeepLink = () => { var anchor = window.location.hash; - // If there is no anchor, return to the initial panel - if (!anchor.length && this._initialAnchor) { - anchor = this._initialAnchor; + if (!anchor.length) { + // If we are still initializing and there is no anchor, then there is nothing to do + if (this._isInitializing) return; + // Otherwise, move to the initial anchor + if (this._initialAnchor) anchor = this._initialAnchor; } var $anchor = anchor && $(anchor); @@ -112,6 +116,8 @@ class Accordion extends Plugin { } this._events(); + + this._isInitializing = false; } /** diff --git a/js/foundation.tabs.js b/js/foundation.tabs.js index ba35f4afc..d780646c0 100644 --- a/js/foundation.tabs.js +++ b/js/foundation.tabs.js @@ -45,6 +45,7 @@ class Tabs extends Plugin { */ _init() { var _this = this; + this._isInitializing = true; this.$element.attr({'role': 'tablist'}); this.$tabTitles = this.$element.find(`.${this.options.linkClass}`); @@ -105,9 +106,11 @@ class Tabs extends Plugin { this._checkDeepLink = () => { var anchor = window.location.hash; - // If there is no anchor, return to the initial panel - if (!anchor.length && this._initialAnchor) { - anchor = this._initialAnchor; + if (!anchor.length) { + // If we are still initializing and there is no anchor, then there is nothing to do + if (this._isInitializing) return; + // Otherwise, move to the initial anchor + if (this._initialAnchor) anchor = this._initialAnchor; } var anchorNoHash = anchor.indexOf('#') >= 0 ? anchor.slice(1) : anchor; @@ -144,6 +147,8 @@ class Tabs extends Plugin { } this._events(); + + this._isInitializing = false; } /**