-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery-tabs.min.js
15 lines (15 loc) · 4.75 KB
/
jquery-tabs.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
* jQuery Chaos Tabs
* By Matthew Sigley
* Version 1.5.0
*/
(function(e){function q(a){var b=window.location.hash.substring(1);if("tab-"!==b.substring(0,4))return!1;var c=a.find('.tab-menu li > a[href="#'+b+'"]').first();if(c.length)a.find(".tab-menu").children(".active").removeClass("active"),c.parent().addClass("active"),a.find(".tab-content").hide().css("content-visibility","hidden"),e(c.attr("rel")).show().css("content-visibility","visible");else return!1;a=a.find('[id="'+b+'"], a[name="'+b+'"]').first();a.length&&a.get(0).scrollIntoView(!0);return window.location.hash}
e.resizeChaosTabsEvent=function(a){cancelAnimationFrame(a.data.tabContainer.get(0).chaosTabsResizeFrame);a.data.tabContainer.get(0).chaosTabsResizeFrame=requestAnimationFrame(a.data.tabContainer.get(0).resizeChaosTabs)};e.clickArrowChaosTabsEvent=function(a){var b=a.data.tabMenuWrap;a=a.data.arrowDirection;b.stop();"left"==a?b.animate({scrollLeft:b.scrollLeft()-100},100):"right"==a&&b.animate({scrollLeft:b.scrollLeft()+100},100)};e.fn.chaosTabsCacheTabProperties=function(){var a=this.get(0),b=this.find(".tab-menu-wrap:first"),
c=this.find(".tab-menu:first"),d=c.width(),g="border-box"===b.css("box-sizing"),f="border-box"===c.css("box-sizing"),l=this.find(".arrow");g&&b.css({"padding-left":"","padding-right":""});var h=parseFloat(b.css("padding-left")),k=parseFloat(b.css("padding-right"));!isNaN(h)&&isFinite(h)&&(h=0);!isNaN(k)&&isFinite(k)&&(k=0);g&&b.css({"padding-left":h,"padding-right":k});a.tabMenuWrap=b;a.tabMenu=c;a.tabMenuWidth=d;a.isTabMenuWrapBorderBox=g;a.isTabMenuBorderBox=f;a.tabArrows=l;a.tabMenuWrapPaddingLeft=
h;a.tabMenuWrapPaddingRight=k};e.fn.chaosTabsAttachArrowEvents=function(){var a=this.get(0),b=a.chaosTabsArgs,c=a.tabArrows,d=a.tabMenuWrap;a=a.tabMenu;c.eq(0).on("click",{tabMenuWrap:d,arrowDirection:"left"},e.clickArrowChaosTabsEvent);c.eq(1).on("click",{tabMenuWrap:d,arrowDirection:"right"},e.clickArrowChaosTabsEvent);a.find("li").on("click",function(){thisPosition=e(this).position();d.stop().animate({scrollLeft:thisPosition.left-b.arrowLeftPadding},100)})};e.fn.chaosTabsHandleOverflowArrows=function(){var a=
this.get(0),b=a.chaosTabsArgs,c=a.chaosTabsArrowsShown||!1,d=e(window).width();if("undefined"==typeof a.chaosTabsLastWindowWidth||!(a.chaosTabsLastWindowWidth==d||a.chaosTabsLastWindowWidth<d&&!c||a.chaosTabsLastWindowWidth>d&&c)){var g=a.tabMenu,f=a.tabMenuWrap.width(),l=a.tabMenuWidth,h=a.isTabMenuBorderBox,k=a.tabMenuWrapPaddingLeft,m=a.tabMenuWrapPaddingRight,n=a.tabArrows;a.isTabMenuWrapBorderBox&&c&&(f-=k+m);h&&c&&(l-=b.arrowRightPadding+b.arrowLeftPadding);l>f&&!c?(g.data({"padding-right":g.css("padding-right"),
"padding-left":g.css("padding-left")}),g.css({"padding-right":"+="+b.arrowRightPadding,"padding-left":"+="+b.arrowLeftPadding}),n.show().css("content-visibility","visible"),c=!0):l<=f&&c&&(n.hide().css("content-visibility","hidden"),g.css({"padding-right":g.data("padding-right"),"padding-left":g.data("padding-left")}),c=!1)}a.chaosTabsArrowsShown=c;a.chaosTabsLastWindowWidth=d};e.fn.chaosTabs=function(a){a=e.extend({},{arrows:!1,arrowRightPadding:20,arrowLeftPadding:20,callback:!1},a);var b=a.callback,
c=e(window),d=this.parent();this.css("contain","layout paint style");this.css("position","relative");var g="",f="";this.children(".tab").each(function(h,k){var m=e(k),n=m.find(".tab-title"),r=n.text(),p=encodeURIComponent(r.replace("?",""));m=m.find(".tab-content");n.hide().css("content-visibility","hidden");m.hide().css("content-visibility","hidden");p&&(0==e('[id="tab-'+p+'"], a[name="tab-'+p+'"]').length&&(g+='<div id="tab-'+p+'" style="position: absolute; top: -100px;"></div>'),f+="<li "+(0===
h?'class="first"':"")+'><a href="#tab-'+p+'" rel="#tab-'+h+'">'+r+"</a></li>",m.attr("id","tab-"+h))});f='<ul class="tab-menu clearfix">'+f+"</ul>";a.arrows?(f='<div class="tab-menu-wrap" style="box-sizing: border-box; overflow-x: auto; overflow-y:hidden; -webkit-overflow-scrolling:touch;">'+f+"</div>",f='<div class="tab-arrow-wrap"><a class="arrow-left arrow" style="display: none;">◄</a>'+f+'<a class="arrow-right arrow" style="display: none;">►</a></div>'):f='<div class="tab-menu-wrap">'+
f+"</div>";this.prepend(g+f);d.get(0).chaosTabsArgs=a;if(a.arrows)for(d.chaosTabsCacheTabProperties(),d.chaosTabsAttachArrowEvents(),d.chaosTabsHandleOverflowArrows(),d.get(0).resizeChaosTabs=d.chaosTabsHandleOverflowArrows.bind(d),a=["resize","load","transitionend","animationend"],i=0;i<a.length;i++)c.on(a[i],{tabContainer:d},e.resizeChaosTabsEvent);q(this)||(c=this.find(".tab-menu li").first(),c.addClass("active"),this.find(".tab-content").first().show().css("content-visibility","visible"),b&&"function"===
typeof b&&b(c.find("a").html()));var l=this;window.addEventListener("hashchange",function(h){(h=q(l))&&b&&"function"===typeof b&&b(h)});return this}})(jQuery);