Skip to content

Commit

Permalink
add fix for Foundation Tabs plugin
Browse files Browse the repository at this point in the history
TODO: remove when foundation/foundation-sites#12464 is released
  • Loading branch information
ameotoko committed Aug 5, 2022
1 parent 624cc73 commit 973c2d5
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions frontend/overrides/foundation.tabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

import { Tabs } from 'foundation-sites/js/foundation.tabs';

/**
* Correctly handle history changing if the page has `<base>` tag
*/
export default class LocationAwareTabs extends Tabs {
/**
* @inheritDoc
*/
_handleTabChange($target, historyHandled) {

// With `activeCollapse`, if the target is the active Tab, collapse it.
if ($target.hasClass(`${this.options.linkActiveClass}`)) {
if(this.options.activeCollapse) {
this._collapse();
}
return;
}

var $oldTab = this.$element.
find(`.${this.options.linkClass}.${this.options.linkActiveClass}`),
$tabLink = $target.find('[role="tab"]'),
target = $tabLink.attr('data-tabs-target'),
anchor = target && target.length ? `#${target}` : $tabLink[0].hash,
$targetContent = this.$tabContent.find(anchor);

//close old tab
this._collapseTab($oldTab);

//open new tab
this._openTab($target);

//either replace or update browser history
if (this.options.deepLink && !historyHandled) {
if (this.options.updateHistory) {
history.pushState({}, '', location.pathname + location.search + anchor);
} else {
history.replaceState({}, '', location.pathname + location.search + anchor);
}
}

/**
* Fires when the plugin has successfully changed tabs.
* @event Tabs#change
*/
this.$element.trigger('change.zf.tabs', [$target, $targetContent]);

//fire to children a mutation event
$targetContent.find("[data-mutate]").trigger("mutateme.zf.trigger");
}
}

0 comments on commit 973c2d5

Please sign in to comment.