-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: remove when foundation/foundation-sites#12464 is released
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |