]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fix: fix scroll to deep-linking default anchor on initialization in Tabs/Accordion
authorNicolas Coden <nicolas@ncoden.fr>
Tue, 9 Oct 2018 21:49:11 +0000 (23:49 +0200)
committerNicolas Coden <nicolas@ncoden.fr>
Tue, 9 Oct 2018 21:49:11 +0000 (23:49 +0200)
Related to https://github.com/zurb/foundation-sites/issues/11527

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

index 78bf35aa8f50fea507799f7315234e477f3f8b52..13ab360d61d63b30d6cd31d31410f7468df61376 100644 (file)
@@ -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;
   }
 
   /**
index ba35f4afc3bb039de8ed1fc78638d2eac7236c82..d780646c0a9ac3f4baea77396dae5da9da1b09aa 100644 (file)
@@ -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;
   }
 
   /**