}
});
- //use browser to open a tab, if it exists in this tabset
- if (this.options.deepLink) {
- this._checkDeepLink();
- }
-
if(this.options.matchHeight) {
var $images = this.$tabContent.find('img');
}
}
- this._checkDeepLink = this._checkDeepLink.bind(this);
- this._events();
- }
-
- _checkDeepLink() {
- var anchor = window.location.hash;
- //need a hash and a relevant anchor in this tabset
- if(anchor.length) {
- var $link = this.$element.find('[href="'+anchor+'"]');
- if ($link.length) {
- this.selectTab($(anchor));
-
- //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);
- }
+ //current context-bound function to open tabs on page load or history popstate
+ this._checkDeepLink = () => {
+ var anchor = window.location.hash;
+ //need a hash and a relevant anchor in this tabset
+ if(anchor.length) {
+ var $link = this.$element.find('[href="'+anchor+'"]');
+ if ($link.length) {
+ this.selectTab($(anchor), true);
+
+ //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);
+ }
- /**
- * Fires when the zplugin has deeplinked at pageload
- * @event Tabs#deeplink
- */
- this.$element.trigger('deeplink.zf.tabs', [$link, $(anchor)]);
+ /**
+ * Fires when the zplugin has deeplinked at pageload
+ * @event Tabs#deeplink
+ */
+ this.$element.trigger('deeplink.zf.tabs', [$link, $(anchor)]);
+ }
}
}
- }
+
+ //use browser to open a tab, if it exists in this tabset
+ if (this.options.deepLink) {
+ this._checkDeepLink();
+ }
+
+ this._events();
+ }
+
/**
* Adds event handlers for items within the tabs.
* @private
* @fires Tabs#change
* @function
*/
- _handleTabChange($target) {
+ _handleTabChange($target, historyHandled) {
/**
* Check for active class on target. Collapse if exists.
this._openTab($target);
//either replace or update browser history
- if (this.options.deepLink) {
+ if (this.options.deepLink && !historyHandled) {
var anchor = $target.find('a').attr('href');
if (this.options.updateHistory) {
* @param {jQuery | String} elem - jQuery object or string of the id of the pane to display.
* @function
*/
- selectTab(elem) {
+ selectTab(elem, historyHandled) {
var idStr;
if (typeof elem === 'object') {
var $target = this.$tabTitles.find(`[href="${idStr}"]`).parent(`.${this.options.linkClass}`);
- this._handleTabChange($target);
+ this._handleTabChange($target, historyHandled);
};
/**
* Sets the height of each panel to the height of the tallest panel.
}
}
- $(window).off('popstate', this._checkDeepLink);
+ if (this.options.deepLink) {
+ $(window).off('popstate', this._checkDeepLink);
+ }
+
Foundation.unregisterPlugin(this);
}
}