/** * Accessible Tabs - jQuery plugin for accessible, unobtrusive tabs * Build to seemlessly work with the CCS-Framework YAML (yaml.de) not depending on YAML though * @requires jQuery - tested with 1.9.1, 1.7 and 1.4.2 but might as well work with older versions * * english article: http://blog.ginader.de/archives/2009/02/07/jQuery-Accessible-Tabs-How-to-make-tabs-REALLY-accessible.php * german article: http://blog.ginader.de/archives/2009/02/07/jQuery-Accessible-Tabs-Wie-man-Tabs-WIRKLICH-zugaenglich-macht.php * * code: http://github.com/ginader/Accessible-Tabs * please report issues at: http://github.com/ginader/Accessible-Tabs/issues * * Copyright (c) 2007 Dirk Ginader (ginader.de) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ (function($) { var debugMode = true; $.fn.extend({ // We assume there could be multiple sets of tabs on a page, so, // the unique id for each invididual tab's heading is identified with params q and r (e.g., id="accessibletabscontent0-2") getUniqueId: function(p, q, r){ if (r===undefined) {r='';} else {r='-'+r;} return p + q + r; }, accessibleTabs: function(config) { var defaults = { wrapperClass: 'content', // Classname to apply to the div that is wrapped around the original Markup currentClass: 'current', // Classname to apply to the LI of the selected Tab tabhead: 'h4', // Tag or valid Query Selector of the Elements to Transform the Tabs-Navigation from (originals are removed) tabheadClass: 'tabhead', // Classname to apply to the target heading element for each tab div tabbody: '.tabbody', // Tag or valid Query Selector of the Elements to be treated as the Tab Body fx:'show', // can be "fadeIn", "slideDown", "show" fxspeed: 'normal', // speed (String|Number): "slow", "normal", or "fast") or the number of milliseconds to run the animation currentInfoText: 'current tab: ', // text to indicate for screenreaders which tab is the current one currentInfoPosition: 'prepend', // Definition where to insert the Info Text. Can be either "prepend" or "append" currentInfoClass: 'current-info', // Class to apply to the span wrapping the CurrentInfoText tabsListClass:'tabs-list', // Class to apply to the generated list of tabs above the content syncheights:false, // syncs the heights of the tab contents when the SyncHeight plugin is available http://blog.ginader.de/dev/jquery/syncheight/index.php syncHeightMethodName:'syncHeight', // set the Method name of the plugin you want to use to sync the tab contents. Defaults to the SyncHeight plugin: http://github.com/ginader/syncHeight cssClassAvailable:false, // Enable individual css classes for tabs. Gets the appropriate class name of a tabhead element and apply it to the tab list element. Boolean value saveState:false, // save the selected tab into a cookie so it stays selected after a reload. This requires that the wrapping div needs to have an ID (so we know which tab we're saving) autoAnchor:false, // will move over any existing id of a headline in tabs markup so it can be linked to it pagination:false, // adds buttons to each tab to switch to the next/previous tab position:'top', // can be 'top' or 'bottom'. Defines where the tabs list is inserted. wrapInnerNavLinks: '', // inner wrap for a-tags in tab navigation. See http://api.jquery.com/wrapInner/ for further informations firstNavItemClass: 'first', // Classname of the first list item in the tab navigation lastNavItemClass: 'last', // Classname of the last list item in the tab navigation clearfixClass: 'clearfix' // Name of the Class that is used to clear/contain floats }; var keyCodes = { 37 : -1, //LEFT 38 : -1, //UP 39 : +1, //RIGHT 40 : +1 //DOWN }; var positions = { top : 'prepend', bottom : 'append' }; this.options = $.extend(defaults, config); var tabsCount = 0; if($("body").data('accessibleTabsCount') !== undefined){ tabsCount = $("body").data('accessibleTabsCount'); } $("body").data('accessibleTabsCount',this.size()+tabsCount); var o = this; return this.each(function(t) { var el = $(this); var list = ''; var tabCount = 0; var ids = []; $(el).wrapInner('
'); $(el).find(o.options.tabhead).each(function(i){ var id = ''; var elId = $(this).attr('id'); if(elId){ // Skip this item if it already exists. if(elId.indexOf('accessibletabscontent') === 0) { return; } id =' id="'+elId+'"'; } var tabId = o.getUniqueId('accessibletabscontent', tabsCount+t, i);//get a unique id to assign to this tab's heading var navItemId = o.getUniqueId('accessibletabsnavigation', tabsCount+t, i);//get a unique id for this navigation item ids.push(tabId); if(o.options.cssClassAvailable === true) { var cssClass = ''; if($(this).attr('class')) { cssClass = $(this).attr('class'); cssClass = ' class="'+cssClass+'"'; } list += '