## Basics
-There are two pieces to a tabbed interface: the tabs themselves, and the content for each tab. The tabs are an element with the class `.tabs`, and each item has the class `.tabs-title`. Each tab contains a link to a tab. The `href` of each link should match the ID of a tab.
+There are two pieces to a tabbed interface: the tabs themselves, and the content for each tab. The tabs are an element with the class `.tabs`, and each item has the class `.tabs-title`. Each tab contains a link to a tab. The `href` of each link should match the ID of a tab. Alternatively, the ID can be specified with the attribute `data-tabs-target`.
```html
<ul class="tabs" data-tabs id="example-tabs">
<li class="tabs-title is-active"><a href="#panel1" aria-selected="true">Tab 1</a></li>
- <li class="tabs-title"><a href="#panel2">Tab 2</a></li>
+ <li class="tabs-title"><a data-tabs-target="#panel2" href="#/tabs/panel2">Tab 2</a></li>
</ul>
```
var $elem = $(this),
$link = $elem.find('a'),
isActive = $elem.hasClass(`${_this.options.linkActiveClass}`),
- hash = $link[0].hash.slice(1),
+ hash = $link.attr('data-tabs-target') || $link[0].hash.slice(1),
linkId = $link[0].id ? $link[0].id : `${hash}-label`,
$tabContent = $(`#${hash}`);
var $oldTab = this.$element.
find(`.${this.options.linkClass}.${this.options.linkActiveClass}`),
$tabLink = $target.find('[role="tab"]'),
- hash = $tabLink[0].hash,
- $targetContent = this.$tabContent.find(hash);
+ hash = $tabLink.attr('data-tabs-target') || $tabLink[0].hash.slice(1),
+ $targetContent = this.$tabContent.find(`#${hash}`);
//close old tab
this._collapseTab($oldTab);
*/
_openTab($target) {
var $tabLink = $target.find('[role="tab"]'),
- hash = $tabLink[0].hash,
- $targetContent = this.$tabContent.find(hash);
+ hash = $tabLink.attr('data-tabs-target') || $tabLink[0].hash.slice(1),
+ $targetContent = this.$tabContent.find(`#${hash}`);
$target.addClass(`${this.options.linkActiveClass}`);
<ul class="tabs" data-tabs id="example-tabs">
<li class="tabs-title is-active"><a href="#panel1" aria-selected="true">Tab 1</a></li>
<li class="tabs-title"><a href="#panel2">Tab 2</a></li>
- <li class="tabs-title"><a href="#panel3">Tab 3</a></li>
+ <li class="tabs-title"><a data-tabs-target="panel3" href="#/panel3">Tab 3</a></li>
</ul>
<div class="tabs-content" data-tabs-content="example-tabs">
plugin.selectTab('#panel2');
$html.find('#panel2').should.be.visible;
});
+ it('opens the selected tab with data-tabs-target attribute', function() {
+ $html = $(template).appendTo('body');
+ plugin = new Foundation.Tabs($html.find('[data-tabs]'), {});
+
+ plugin.selectTab('#/panel3');
+ $html.find('#panel3').should.be.visible;
+ });
});
describe('_handleTabChange()', function() {
});
});
-});
\ No newline at end of file
+});