blob: 16b5d6776c5a64d6cf7d7e8b449e0b29c3f01575 [file] [log] [blame]
/**
* @module Easy Responsive Tabs Plugin
* @author Samson.Onna (samson3d@gmail.com)
* @license MIT License
*/
!function(t){t.fn.extend({easyResponsiveTabs:function(a){var e={type:"default",width:"auto",fit:!0,closed:!1,activate:function(){}},a=t.extend(e,a),s=a,i=s.type,n=s.fit,r=s.width,c="vertical",o="accordion",d=window.location.hash,l=!(!window.history||!history.replaceState);t(this).bind("tabactivate",function(t,e){"function"==typeof a.activate&&a.activate.call(e,t)}),this.each(function(){function e(){i==c&&s.addClass("resp-vtabs"),1==n&&s.css({width:"100%"}),i==o&&(s.addClass("resp-easy-accordion"),s.find(".resp-tabs-list").css("display","none"))}var s=t(this),p=s.find("ul.resp-tabs-list"),b=s.attr("id");s.find("ul.resp-tabs-list li").addClass("resp-tab-item"),s.css({display:"block",width:r}),s.find(".resp-tabs-container > div").addClass("resp-tab-content"),e();var v;s.find(".resp-tab-content").before("<div class='resp-accordion' role='tab'><span class='resp-arrow'></span></div>");var f=0;s.find(".resp-accordion").each(function(){v=t(this);var a=s.find(".resp-tab-item:eq("+f+")"),e=s.find(".resp-accordion:eq("+f+")");e.append(a.html()),e.data(a.data()),v.attr("aria-controls","tab_item-"+f),f++});var h,u=0;s.find(".resp-tab-item").each(function(){$tabItem=t(this),$tabItem.attr("aria-controls","tab_item-"+u),$tabItem.attr("role","tab");var a=0;s.find(".resp-tab-content").each(function(){h=t(this),h.attr("aria-labelledby","tab_item-"+a),a++}),u++});var C=0;if(""!=d){var m=d.match(new RegExp(b+"([0-9]+)"));null!==m&&2===m.length&&(C=parseInt(m[1],10)-1,C>u&&(C=0))}t(s.find(".resp-tab-item")[C]).addClass("resp-tab-active"),a.closed===!0||"accordion"===a.closed&&!p.is(":visible")||"tabs"===a.closed&&p.is(":visible")?t(s.find(".resp-tab-content")[C]).addClass("resp-tab-content-active resp-accordion-closed"):(t(s.find(".resp-accordion")[C]).addClass("resp-tab-active"),t(s.find(".resp-tab-content")[C]).addClass("resp-tab-content-active").attr("style","display:block")),s.find("[role=tab]").each(function(){var a=t(this);a.click(function(){var a=t(this),e=a.attr("aria-controls");if(a.hasClass("resp-accordion")&&a.hasClass("resp-tab-active"))return s.find(".resp-tab-content-active").slideUp("",function(){t(this).addClass("resp-accordion-closed")}),a.removeClass("resp-tab-active"),!1;if(!a.hasClass("resp-tab-active")&&a.hasClass("resp-accordion")?(s.find(".resp-tab-active").removeClass("resp-tab-active"),s.find(".resp-tab-content-active").slideUp().removeClass("resp-tab-content-active resp-accordion-closed"),s.find("[aria-controls="+e+"]").addClass("resp-tab-active"),s.find(".resp-tab-content[aria-labelledby = "+e+"]").slideDown().addClass("resp-tab-content-active")):(s.find(".resp-tab-active").removeClass("resp-tab-active"),s.find(".resp-tab-content-active").removeAttr("style").removeClass("resp-tab-content-active").removeClass("resp-accordion-closed"),s.find("[aria-controls="+e+"]").addClass("resp-tab-active"),s.find(".resp-tab-content[aria-labelledby = "+e+"]").addClass("resp-tab-content-active").attr("style","display:block")),a.trigger("tabactivate",a),t(window).trigger("lookup.unveil"),l){var i=window.location.hash,n=b+(parseInt(e.substring(9),10)+1).toString();if(""!=i){var r=new RegExp(b+"[0-9]+");n=null!=i.match(r)?i.replace(r,n):i+"|"+n}else n="#"+n;history.replaceState(null,null,n)}})}),t(window).resize(function(){s.find(".resp-accordion-closed").removeAttr("style")})})}})}(jQuery);