-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjquery.accTabs.min.js
More file actions
11 lines (11 loc) · 3.66 KB
/
jquery.accTabs.min.js
File metadata and controls
11 lines (11 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
/*!
* jQuery Accessible Tabs
*
* @description: Creates accessible tabs - a single content area with multiple panels
* @source: https://github.com/nomensa/jquery.accessible-tabs.git
* @version: '0.1.2'
*
* @author: Nomensa
* @license: licenced under MIT - http://opensource.org/licenses/mit-license.php
*/
!function(a,b,c,d){"use strict";function e(b,c){function d(){i.controlsWrapper=a('<ul class="'+i.options.tabControlsClass+'" role="tablist" />'),a("> div",i.element).each(function(b,c){var d=i.options.tabControlId+h+b,g=i.options.tabPanelId+h+b,j=a(a(c).prev()),k=j.html(),l=a('<li role="presentation"><button aria-selected="false" data-controls="'+g+'" id="'+d+'" role="tab">'+k+"</button></li>");j.hide(),a("button",l).click(e(i)).keydown(f(i)),i.controlsWrapper.append(l)}),i.element.prepend(i.controlsWrapper),a("> div",i.element).each(function(b,c){a(c).addClass(i.options.tabPanelClass).attr({"aria-hidden":"true","aria-labelledby":i.options.tabControlId+h+b,id:i.options.tabPanelId+h+b,role:"tabpanel"}).hide()}),i.controlsTextWrapper=a('<p class="'+i.options.controlsTextClass+'">'+i.options.controlsText+"</p>"),i.element.prepend(i.controlsTextWrapper),i.activateTab(a("button",i.controlsWrapper).eq(i.options.defaultTab)),i.element.addClass(i.options.containerClass),h++,i.options.callbackCreate()}function e(){return i.handleClick=function(a){a.preventDefault(),i.activateTab(this),i.options.callbackTabActivated()},i.handleClick}function f(){return i.handleKeyDown=function(b){switch(b.which){case 37:case 38:b.preventDefault(),0!==a(this).parent().prev().length?a(this).parent().prev().find("> button").focus().click():a(i.controlsWrapper).find("li:last > button").focus().click();break;case 39:case 40:b.preventDefault(),0!==a(this).parent().next().length?a(this).parent().next().find("> button").focus().click():a(i.controlsWrapper).find("li:first > button").focus().click()}},i.handleKeyDown}var i=this;i.element=a(b),i.options=a.extend({},g,c),d()}var f,g,h=0;f="accTabs",g={defaultTab:0,callbackCreate:function(){},callbackDestroy:function(){},containerClass:"js-tabs",controlActiveClass:"js-tabs_control-item--active",controlsText:"Use the tab and enter or arrow keys to move between tabs",controlsTextClass:"js-tabs_control-text",panelActiveClass:"js-tabs_panel--active",tabControlsClass:"js-tabs_control",tabControlId:"js-tabs_control-item--",tabPanelClass:"js-tabs_panel",tabPanelId:"js-tabs_panel--",callbackTabActivated:function(){}},e.prototype.activateTab=function(b){if("false"===a(b).attr("aria-selected")){var c=this.options.controlActiveClass,d="#"+a(b).attr("data-controls");0!==a('[aria-selected="true"]',this.controlsWrapper).length&&(a('[aria-selected="true"]',this.controlsWrapper).attr("aria-selected","false").parent("li").removeClass(c),a('> [aria-hidden="false"]',this.element).attr("aria-hidden","true").hide().removeClass(this.options.panelActiveClass)),a(b,this.element).attr("aria-selected","true"),a(b,this.element).parent("li").addClass(c),a(d,this.element).attr("aria-hidden","false").show().addClass(this.options.panelActiveClass)}},e.prototype.rebuild=function(){return new e(this.element,this.options)},e.prototype.destroy=function(){var b=this;this.element.removeClass(this.options.containerClass),a("> ."+this.options.controlsTextClass,this.element).remove(),a("> ."+this.options.tabControlsClass,this.element).remove(),a("> div",this.element).prev().removeAttr("style"),a("> div",this.element).each(function(c,d){a(d).removeAttr("aria-hidden aria-labelledby id role style").removeClass(b.options.tabPanelClass)}),this.options.callbackDestroy()},a.fn[f]=function(b){return this.each(function(){a.data(this,"plugin_"+f)||a.data(this,"plugin_"+f,new e(this,b))})}}(jQuery,window,document);