jquery.autotabs.js - A jquery plugin that automatically generates navigable tabs based on the markup in the page.
jquery.autotabs.js automatically generates tabs based on the markup in your DOM element to which it is applied.
A tab is created for each child element in the designated element. Which children are used to generate tabs can be customized.
A set of navigable tabs is added to the page. The location of the tabs is cusotmizable.
Each tab can contain either static or dynamic content.
See demo/docs in docs/index.html.
- jQuery >= 1.9.1
If you want autotabs to remember the state of you tabs, you also need the jquery.cookie plugin:
- jquery.cookie.js: >= 1.4
Add the following lines to your bower.json configuration:
"dependencies": {
"autotabs": "~2.0",
}
Or download from:
<script src="../dist/js/jquery.js"></script>
<script src="../dist/js/jquery.cookie.js"></script> <!-- optional -->
<script src="../dist/js/jquery.autotabs.min.js"></script>
<link rel="stylesheet" type="text/css" href="../dist/css/jquery.autotabs.min.css" />
For vertical tabs, include the custom stylesheet provided:
<link rel="stylesheet" type="text/css" href="../dist/css/jquery.autotabs.vertical.min.css" />
Add the following logic to your page or to a plugin included to your page:
$( "#mytabs" ).autotabs(/* { options } */));
The tabs settings can be configured directly inside the markup. The following attributes are supported:
The tab label.
The remote url for the tab content.
The tab label.
This attribute is deprecated in favour of the data-autotabs-label
attribute and may be removed in future releases.
The remote url for the tab content.
This attribute is deprecated in favour of the data-autotabs-url
attribute and may be removed in future releases.
Simply set the data-autotabs-url
attribute of the tab pane to the url of the page holding the content.
To style the tabs with the bootstrap stylesheet, use the following options:
tabs_class: "nav nav-tabs",
tab_class: null,
active_class: "active"
To style the tabs as pills:
tabs_class: "nav nav-pills",
tab_class: null,
active_class: "active"
Defines the selector for identifying tab panes.
Default value: div, section, .tab-pane
Defines the selector for identifying the label/title of the tab from an element of the tab pane.
Default value: h1, h2, h3, h4
The CSS class to set on the generated tabs element.
Default value: autotabs
The CSS class ot set on each generated tab element
Default value: autotab
The selector for identifying the element in which the generated tabs should be appended.
Default value: none
The CSS class to add to the tab currently selected.
Default value: current
The index of the tab to set as active when the plugin loads.
Default value: null
The name of the cookie in which to store the state of the tabs. This option requires the jquery.cookie.js plugin.
Default value: active_tab
The path to set on the cookie. This option requires the jquery.cookie.js plugin.
Default value: /
Forces each tab to be refreshed when clicked.
Default value: false
Whether to treat an single (orphan) tab-pane as a tab or not.
Default value: false
The selector for the element containing the loading icon.
Default value: #loading
A function responsible for generating a tab id if not suplied in the markup.
Default value:
function( id ) { return "__" + id; }
A function responsible for generating each tab's label ifnot supplied in the markup.
Default value:
function( index ) { return "Tab " + ( index + 1 ); },
A function responsible for generating the id of each tab pane if not supplied in the markup.
Default value:
function( index ) { return "___" + ( index + 1 ); },
Whether the tabs are vertically aligned.
Default value: false
Defines the callbacks to apply when a tab is clicked. This option can be
- a function, in which case it is applied to all tabs
- an object, where the property is the id of a tab, and the value the function to act as callback for that tab.
All functions are applied to the tab pane element. this
therefore refers to the tab pane element.