diff --git a/aria-tabs.min.js b/aria-tabs.min.js index d577997..2412701 100644 --- a/aria-tabs.min.js +++ b/aria-tabs.min.js @@ -1 +1 @@ -!function(e,t,n){"use strict";function o(e,t,n){return n=void 0!==n?n:"",e.is("[id]")||e.attr("id",t+n),e.attr("id")}function r(e){return e.shiftKey||e.ctrlKey||e.altKey||e.metaKey?!1:!0}function d(t,n){var s=this;s.element=e(t),s.settings=e.extend({},e.fn[a].defaultSettings,n),s.elementId=o(s.element,s.settings.tabGroupIdPrefix,i),s.nav=s.element.find("."+s.settings.navClass),s.list=s.element.find("."+s.settings.listClass),s.panelsContainer=s.element.find("."+s.settings.panelsContainerClass),s.elements={listItems:s.list.find("."+s.settings.listItemClass),btn:s.list.find("."+s.settings.btnClass),panel:s.panelsContainer.find("."+s.settings.panelClass),content:s.panelsContainer.find("."+s.settings.contentClass)},s.elementsLenght=s.elements.panel.length,s.selectedTab=0,s.init()}var a="ariaTabs",s={aHi:"aria-hidden",aSe:"aria-selected",aCs:"aria-controls",aLab:"aria-labelledby",aOr:"aria-orientation",tbI:"tabindex",r:"role",t:"true",f:"false"},i=0,l=e(t);e.extend(d.prototype,{init:function(){var t=this,n=t.settings,r=t.elements,c=r.btn,d=r.panel;t.nav.attr(s.r,"tablist"),c.attr(s.r,"tab"),t.list.attr(s.r,"none presentation"),r.listItems.attr(s.r,"none presentation"),n.verticalMode&&t.nav.attr(s.aOr,"vertical"),c.each(function(e){o(c.eq(e),t.elementId+"__btn--",i),o(d.eq(e),t.elementId+"__panel--",i),c.eq(e).attr(s.aCs,d.eq(e).attr("id")),d.eq(e).attr(s.aLab,c.eq(e).attr("id"))}),"string"==typeof n.contentRole?r.content.attr(s.r,n.contentRole):Array.isArray(n.contentRole)&&r.content.each(function(t){e(this).attr(s.r,n.contentRole[t])}),c.each(function(e){e>0?t.hide(e):t.show(e,!1)}),t.element.on("click."+a+".count","."+n.btnClass,function(){var n=c.index(e(this));n!==t.selectedTab&&t.toggle(n,!0)}),t.element.on("keydown."+a+"."+i,"."+n.btnClass,function(e){t.keyboardNavigation(e)}),l.trigger(a+".initialised",[t.element]),i+=1},toggle:function(e,t){var n=this;n.hide(n.selectedTab),n.show(e,t)},keyboardNavigation:function(e){var t=this,n=t.elementsLenght,a=t.selectedTab,s=e.keyCode,i=0,l=t.settings.verticalMode;if(!r(e))return!1;switch(s){case 37:i=0===a?n-1:a-1;break;case 39:i=a===n-1?0:a+1;break;case 36:i=0;break;case 35:i=n;break;case 38:i=l?0===a?n-1:a-1:!1;break;case 40:i=l?a===n-1?0:a+1:!1;break;default:i=!1}i!==!1&&(e.preventDefault(),t.elements.btn.eq(i).focus(),t.toggle(i,!0))},select:function(e){var t=this,n=t.settings,a=t.elements;a.btn.eq(e).addClass(n.btnSelectedClass).attr(s.tbI,"0").attr(s.aSe,s.t),a.panel.eq(e).addClass(n.panelSelectedClass).attr(s.aHi,s.f),t.selectedTab=e},deselect:function(e){var t=this,n=t.settings,a=t.elements;a.btn.eq(e).removeClass(n.btnSelectedClass).attr(s.tbI,"-1").attr(s.aSe,s.f),a.panel.eq(e).removeClass(n.panelSelectedClass).attr(s.aHi,s.t)},show:function(e,t){var n=this,s=t?n.settings.fadeSpeed:0;n.settings.cssTransitions||n.elements.panel.eq(e).fadeIn(s),n.select(e),l.trigger(a+".select",[n.element,e])},hide:function(e){var t=this;t.settings.cssTransitions||t.elements.panel.eq(e).hide(),t.deselect(e),l.trigger(a+".deselect",[t.element,e])},methodCaller:function(t,n){var a=this;"number"!=typeof n&&("string"==typeof n&&(n=e(n)),"object"==typeof n&&1===n.length&&n.hasClass(a.settings.btnClass)&&1===n.closest(a.element).length&&(n=a.nav.index(n))),"select"===t&&a.toggle(n,!0)}}),e.fn[a]=function(t,n){return this.each(function(){var s=this;e.data(s,"plugin_"+a)||"object"!=typeof t&&"undefined"!=typeof t?"string"==typeof t&&"undefined"!=typeof n&&e.data(s,"plugin_"+a).methodCaller(t,n):e.data(s,"plugin_"+a,new d(s,t))})},e.fn[a].defaultSettings={tabGroupIdPrefix:"tab-group--",navClass:"tab-group__tab-nav",listClass:"tab-group__tab-ul",listItemClass:"tab-group__tab-li",btnClass:"tab-group__tab-btn",panelsContainerClass:"tab-group__tabs-cont",panelClass:"tab-group__tabpanel",contentClass:"tab-group__tab-content",contentRole:"document",btnSelectedClass:"tab-group__tab-btn_selected",panelSelectedClass:"tab-group__tabpanel_selected",verticalMode:!1,fadeSpeed:300,cssTransitions:!1}}(jQuery,window,document); \ No newline at end of file +!function(e,t,n){"use strict";function r(e,t,n){return n=void 0!==n?n:"",e.is("[id]")||e.attr("id",t+n),e.attr("id")}function o(e){return e.shiftKey||e.ctrlKey||e.altKey||e.metaKey?!1:!0}function c(t,n){var s=this;s.element=e(t),s.settings=e.extend({},e.fn[a].defaultSettings,n),s.elementId=r(s.element,s.settings.tabGroupIdPrefix,i),s.nav=s.element.find("."+s.settings.navClass),s.list=s.element.find("."+s.settings.listClass),s.panelsContainer=s.element.find("."+s.settings.panelsContainerClass),s.elements={listItems:s.list.find("."+s.settings.listItemClass),btn:s.list.find("."+s.settings.btnClass),panel:s.panelsContainer.find("."+s.settings.panelClass),content:s.panelsContainer.find("."+s.settings.contentClass)},s.elementsLenght=s.elements.panel.length,s.selectedTab=0,s.init()}var a="ariaTabs",s={aHi:"aria-hidden",aSe:"aria-selected",aCs:"aria-controls",aLab:"aria-labelledby",aOr:"aria-orientation",tbI:"tabindex",r:"role",t:"true",f:"false"},i=0,l=e(t);e.extend(c.prototype,{init:function(){var t=this,n=t.settings,o=t.elements,f=o.btn,c=o.panel;t.nav.attr(s.r,"tablist"),f.attr(s.r,"tab"),t.list.attr(s.r,"none presentation"),o.listItems.attr(s.r,"none presentation"),n.verticalMode&&t.nav.attr(s.aOr,"vertical"),f.each(function(e){r(f.eq(e),t.elementId+"__btn--",i),r(c.eq(e),t.elementId+"__panel--",i),f.eq(e).attr(s.aCs,c.eq(e).attr("id")),c.eq(e).attr(s.aLab,f.eq(e).attr("id"))}),"string"==typeof n.contentRole?o.content.attr(s.r,n.contentRole):Array.isArray(n.contentRole)&&o.content.each(function(t){e(this).attr(s.r,n.contentRole[t])}),f.each(function(e){e>0?t.hide(e):t.show(e,!1)}),t.element.on("click."+a+".count","."+n.btnClass,function(){var n=f.index(e(this));n!==t.selectedTab&&t.toggle(n,!0)}),t.element.on("keydown."+a+"."+i,"."+n.btnClass,function(e){t.keyboardNavigation(e)}),l.trigger(a+".initialised",[t.element]),i+=1},toggle:function(e,t){var n=this;n.hide(n.selectedTab),n.show(e,t)},keyboardNavigation:function(e){var t=this,n=t.elementsLenght,a=t.selectedTab,s=e.keyCode,i=0,l=t.settings.verticalMode;if(!o(e))return!1;switch(s){case 37:i=0===a?n-1:a-1;break;case 39:i=a===n-1?0:a+1;break;case 36:i=0;break;case 35:i=n;break;case 38:i=l?0===a?n-1:a-1:!1;break;case 40:i=l?a===n-1?0:a+1:!1;break;default:i=!1}i!==!1&&(e.preventDefault(),t.elements.btn.eq(i).focus(),t.toggle(i,!0))},select:function(e){var t=this,n=t.settings,a=t.elements;a.btn.eq(e).addClass(n.btnSelectedClass).attr(s.tbI,"0").attr(s.aSe,s.t),a.panel.eq(e).addClass(n.panelSelectedClass).attr(s.aHi,s.f),t.selectedTab=e},deselect:function(e){var t=this,n=t.settings,a=t.elements;a.btn.eq(e).removeClass(n.btnSelectedClass).attr(s.tbI,"-1").attr(s.aSe,s.f),a.panel.eq(e).removeClass(n.panelSelectedClass).attr(s.aHi,s.t)},show:function(e,t){var n=this,s=t?n.settings.fadeSpeed:0;n.settings.cssTransitions||n.elements.panel.eq(e).fadeIn(s),n.select(e),l.trigger(a+".select",[n.element,e])},hide:function(e){var t=this;t.settings.cssTransitions||t.elements.panel.eq(e).hide(),t.deselect(e),l.trigger(a+".deselect",[t.element,e])},methodCaller:function(t,n){var a=this;"number"!=typeof n&&("string"==typeof n&&(n=e(n)),"object"==typeof n&&1===n.length&&n.hasClass(a.settings.btnClass)&&1===n.closest(a.element).length&&(n=a.nav.index(n))),"select"===t&&a.toggle(n,!0)}}),e.fn[a]=function(t,n){return this.each(function(){var s=this;e.data(s,"plugin_"+a)||"object"!=typeof t&&"undefined"!=typeof t?"string"==typeof t&&"undefined"!=typeof n&&e.data(s,"plugin_"+a).methodCaller(t,n):e.data(s,"plugin_"+a,new c(s,t))})},e.fn[a].defaultSettings={tabGroupIdPrefix:"tab-group--",navClass:"tab-group__tab-nav",listClass:"tab-group__tab-ul",listItemClass:"tab-group__tab-li",btnClass:"tab-group__tab-btn",panelsContainerClass:"tab-group__tabs-cont",panelClass:"tab-group__tabpanel",contentClass:"tab-group__tab-content",contentRole:"document",btnSelectedClass:"tab-group__tab-btn_selected",panelSelectedClass:"tab-group__tabpanel_selected",verticalMode:!1,fadeSpeed:300,cssTransitions:!1}}(jQuery,window,document); \ No newline at end of file