forked from stazna01/jQuery-at-Accordion-or-Tabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.atAccordionOrTabs.min.js
executable file
·1 lines (1 loc) · 5.82 KB
/
jquery.atAccordionOrTabs.min.js
1
!function(i){i.fn.accordionortabs=function(t){var e=i.extend({defaultOpened:0,containerBreakPoint:0,tabsIfPossible:!0,hashbangPrefix:"tabset_",centerTabs:!1,minCenterTabs:0},t);function s(t,a,s){s=void 0!==s&&s,t.addClass("at-tabs"),tabs_width=0,i("> li > a",t).each(function(t){tabs_width=tabs_width+i(this).outerWidth(!0)+5,0==t&&!0===e.centerTabs&&(tabs_width-=i(this).css("margin-left").replace(/[^-\d\.]/g,"")),t==i(this).closest(".at-accordion-or-tabs").find("> li > a").length-1&&(largest_tab_widths[a]=tabs_width+15,!1===s&&fix_accordion_or_tabs())})}function a(t,a){skip_fix_accordion_or_tabs_function="undefined"!=typeof skip_fix_accordion_or_tabs_function&&skip_fix_accordion_or_tabs_function,$first_tab_width=i("> li > a",t).eq(0).outerWidth(!0),void 0===first_tab_widths[a]?first_tab_widths[a]=$first_tab_width:$first_tab_width!=first_tab_widths[a]&&(first_tab_widths[a]=$first_tab_width,s(t,a,!0))}return startingOuterWidth=i(window).width(),is_iOS=/(iPad|iPhone|iPod)/g.test(navigator.userAgent),window.fix_accordion_or_tabs=function(){i(".bbq.at-accordion-or-tabs.at-tabs-when-possible").each(function(t){($tabset=i(this),$tabs=$tabset.find(">li>a"),tabs_when_possible_index=t,rt_user_defined_container_breakpoint=$tabset.attr("data-rtContainerBreakPoint")?$tabset.attr("data-rtContainerBreakPoint"):e.containerBreakPoint,a($tabset,tabs_when_possible_index),largest_tab_widths[t]>$tabset.width()||rt_user_defined_container_breakpoint>=$tabset.width())?(!0===e.centerTabs&&$tabs.eq(0).css("margin-left",""),$tabset.removeClass("at-tabs"),0==(i.bbq.getState($tabset.attr("data-tabset-id"),!0)||0)&&($tabset.addClass("at-accordion-closed"),$tabs.eq(0).removeClass("active").attr("aria-expanded","false").next("section").removeClass("is-open").hide())):(!0===e.centerTabs&&$tabs.length>=e.minCenterTabs&&$tabs.eq(0).css("margin-left",($tabset.outerWidth(!0)-largest_tab_widths[t])/2+10),$tabset.hasClass("at-accordion-closed")&&($tabset.removeClass("at-accordion-closed"),$tabs.eq(0).addClass("active").attr("aria-expanded","true").next("section").addClass("is-open").show().focus(),s($tabset,tabs_when_possible_index)))})},1==e.tabsIfPossible&&this.addClass("at-tabs-when-possible"),0!=e.defaultOpened&&this.each(function(t){e.defaultOpened<=i(this).find(">li").length&&i(this).attr("data-default-opened",e.defaultOpened)}),this.addClass("bbq clearfix at-accordion-or-tabs").find(">li>a").prepend('<span class="at-tab-one-pixel-fix-left"></span><span class="at-tab-one-pixel-fix-right"></span>'),this.each(function(t){i(this).keydown(function(t){if(-1!=[37,38,39,40].indexOf(t.keyCode))switch($temp_tab=i(this).find(">li>a:focus"),t.keyCode){case 38:case 37:t.preventDefault(),t.stopPropagation(),$temp_tab.closest("ul").find("li").first().is($temp_tab.parent())?$temp_tab.parent().nextAll("li").last().find(">a").focus():$temp_tab.parent().prevAll().first().find(">a").focus();break;case 40:case 39:t.preventDefault(),t.stopPropagation(),$temp_tab.closest("ul").find("li").last().is($temp_tab.parent())?$temp_tab.parent().prevAll("li").last().find("a").first().focus():$temp_tab.parent().nextAll("li").first().find("a").first().focus()}})}),this.each(function(a){i(this).attr("data-tabset-id",e.hashbangPrefix+a),i(this).find(">li>a").each(function(t){i(this).attr("href","!#"+e.hashbangPrefix+a+"="+t).attr("aria-controls","sect_"+e.hashbangPrefix+a+"_"+t).attr("id","accordion_"+e.hashbangPrefix+a+"_"+t).attr("aria-expanded","false"),i(this).next("section").attr("id","sect_"+e.hashbangPrefix+a+"_"+t).attr("aria-labelledby","accordion_"+e.hashbangPrefix+a+"_"+t)})}),i(document).ready(function(){i.param.fragment.ajaxCrawlable(!0),largest_tab_widths=new Array,first_tab_widths=new Array,i(".bbq.at-accordion-or-tabs.at-tabs-when-possible").each(function(t){a(i(this),t),s(i(this),t)}),i(".bbq.at-accordion-or-tabs").each(function(t){var a=i.bbq.getState(i(this).attr("data-tabset-id"),!0)||0,s=i(this).attr("data-default-opened");if(0==a&&void 0!==s&&""!=s){var e={};e[i(this).attr("data-tabset-id")]=s,i.bbq.pushState(e)}}),i(".at-accordion-or-tabs").on("click","> li > a",function(t){if(i(this).hasClass("active")){if(!i(this).closest(".at-accordion-or-tabs").hasClass("at-tabs")){s=i(this).closest(".bbq").attr("data-tabset-id");i.bbq.removeState(s)}}else{var a={},s=i(this).closest(".bbq").attr("data-tabset-id"),e=i(this).parent().prevAll().length+1;a[s]=e,i.bbq.pushState(a)}i(this).blur(),t.preventDefault()}),i(window).trigger("hashchange")}),i(window).resize(function(){(!is_iOS||is_iOS&&startingOuterWidth!==i(window).width())&&(startingOuterWidth=i(window).width(),fix_accordion_or_tabs())}),i(window).on("hashchange",function(t){i(".bbq").each(function(){var t=i.bbq.getState(i(this).attr("data-tabset-id"),!0)||0;0<t?(i(this).find(">li>a").eq(t-1).hasClass("active")||(i(this).hasClass("at-tabs")?(i(this).find(".is-open").removeClass("is-open").hide(),i(this).find(">li>section").eq(t-1).toggleClass("is-open").toggle()):(i(this).find(".is-open").removeClass("is-open").slideToggle(),i(this).find(">li>section").eq(t-1).toggleClass("is-open").slideToggle()),i(this).find(".active").removeClass("active").attr("aria-expanded","false"),i(this).find(">li>a").eq(t-1).addClass("active").attr("aria-expanded","true").blur()),i(this).removeClass("at-accordion-closed")):i(this).hasClass("at-accordion-or-tabs")&&!i(this).hasClass("at-tabs")?i(this).addClass("at-accordion-closed").find(">li>a.active").removeClass("active").attr("aria-expanded","false").next("section").removeClass("is-open").slideUp():i(this).hasClass("at-accordion-or-tabs")&&i(this).hasClass("at-tabs")&&!i(this).hasClass("at-accordion-closed")&&(i(this).addClass("at-accordion-closed").find(">li>a.active").removeClass("active").attr("aria-expanded","false").next("section").removeClass("is-open").hide(),i(this).children("li").first().children("a").addClass("active").attr("aria-expanded","true").next("section").addClass("is-open").show())})}),this}}(jQuery);