1 line
4.6 KiB
JavaScript
1 line
4.6 KiB
JavaScript
!function(t,s,i,a){function e(s,i){this.element=t(s),this.$elem=t(this.element),this.settings=t.extend({},l,i),this._defaults=l,this._name=n,this.init()}var n="pwstabs",l={effect:"scale",defaultTab:1,containerWidth:"100%",tabsPosition:"horizontal",horizontalPosition:"top",verticalPosition:"left",responsive:!1,theme:"",rtl:!1};e.prototype={init:function(){var i=["scale","slideleft","slideright","slidetop","slidedown","none"],a=this.$elem,e=a.children("[data-pws-tab]");a.addClass("pws_tabs_list"),a.wrap('<div class="pws_tabs_container"></div>');var n=a.closest(".pws_tabs_container");if("100%"!==this.settings.containerWidth&&n.css("width",this.settings.containerWidth),"vertical"==this.settings.tabsPosition){if(n.closest(".pws_tab_single").length){var l=n.closest(".pws_tab_single").innerWidth();n.css("width",l)}"left"==this.settings.verticalPosition?n.addClass("pws_tabs_vertical pws_tabs_vertical_left"):n.addClass("pws_tabs_vertical pws_tabs_vertical_right")}else"top"==this.settings.horizontalPosition?n.addClass("pws_tabs_horizontal pws_tabs_horizontal_top"):n.addClass("pws_tabs_horizontal pws_tabs_horizontal_bottom");this.settings.rtl&&n.addClass("pws_tabs_rtl"),"none"==this.settings.effect&&n.addClass("pws_tabs_noeffect"),this.settings.theme&&n.addClass(this.settings.theme),t.inArray(this.settings.effect,i)>=0?n.addClass("pws_"+this.settings.effect):n.addClass("pws_scale"),e.addClass("pws_hide").hide(),"vertical"==this.settings.tabsPosition?"left"==this.settings.verticalPosition?n.prepend('<ul class="pws_tabs_controll"></ul>'):n.append('<ul class="pws_tabs_controll"></ul>'):"top"==this.settings.horizontalPosition?n.prepend('<ul class="pws_tabs_controll"></ul>'):n.append('<ul class="pws_tabs_controll"></ul>');var d=n.children(".pws_tabs_controll"),o=1;e.each(function(){t(this).attr("data-pws-tab-id",o);var s=t(this).data("pws-tab"),i=t(this).data("pws-tab-name");d.append('<li><a data-tab-id="'+s+'">'+i+"</a></li>"),t(this).addClass("pws_tab_single"),o++});var h=d.find("a"),p=d.find("li"),r=a.children('[data-pws-tab-id="'+this.settings.defaultTab+'"]');if(a.children("[data-pws-tab-icon]").each(function(){var s=t(this).attr("data-pws-tab"),i=t(this).attr("data-pws-tab-name"),a=t(this).attr("data-pws-tab-icon");""==i&&d.find('[data-tab-id="'+s+'"]').addClass("pws_tab_noname"),d.find('[data-tab-id="'+s+'"]').prepend('<i class="fa '+a+'"></i>')}),"vertical"==this.settings.tabsPosition){var _=n.innerWidth()/450,c=parseInt(h.css("font-size"))/_,w=parseInt(h.css("padding-left"))+parseInt(h.css("padding-right")),u=h.html().length*c+w,b=d.outerHeight(),f=n.outerWidth()-u,v=a.outerHeight();d.width(u),a.outerWidth(f),b>v&&a.css("min-height",b)}if(r.addClass("pws_show").show(),d.find('[data-tab-id="'+r.data("pws-tab")+'"]').addClass("pws_tab_active"),h.on("click",function(s){s.preventDefault(),h.removeClass("pws_tab_active"),t(this).addClass("pws_tab_active");var i=t(this).data("tab-id"),n=a.children('[data-pws-tab="'+i+'"]');e.removeClass("pws_show"),setTimeout(function(){e.hide(),n.show()},400),setTimeout(function(){n.addClass("pws_show")},450)}),this.settings.responsive){n.addClass("pws_tabs_responsive");var g=parseInt(d.children("li").length),m=100/g,C=Math.max.apply(null,p.map(function(){return t(this).height()}).get());t(s).on("resize load",{pluginSettings:this.settings},function(i){var e=i.data.pluginSettings,l=e.tabsPosition,o=e.containerWidth;t(s).width()<=960&&(n.width(""),p.css("width",m+"%"),h.each(function(){t(this).height(C)}),"vertical"==l&&(d.width(""),a.width(""),a.css("min-height",""),a.height(r.height()))),t(s).width()<=600?(n.find(".pws_responsive_small_menu").length<1&&t('<div class="pws_responsive_small_menu"><a data-visible="0"><i class="fa fa-bars"></i></a></div>').insertBefore(d),d.addClass("pws_tabs_menu_popup"),h.height(""),p.width(""),n.find("ul.pws_tabs_menu_popup").hide(),n.find(".pws_responsive_small_menu a").click(function(s){s.preventDefault(),"0"==t(this).attr("data-visible")?(n.find("ul.pws_tabs_menu_popup").show(),t(this).attr("data-visible","1")):(n.find("ul.pws_tabs_menu_popup").hide(),t(this).attr("data-visible","0"))}),n.find("ul.pws_tabs_menu_popup li a").on("click",function(s){s.preventDefault(),t(this).closest(".pws_tabs_menu_popup").hide(),n.find(".pws_responsive_small_menu a").attr("data-visible","0")})):t(s).width()>960?(n.css("width",o),p.width(""),h.height(""),n.find(".pws_responsive_small_menu").remove(),d.removeClass("pws_tabs_menu_popup"),d.show()):t(s).width()>600&&(n.find(".pws_responsive_small_menu").remove(),d.removeClass("pws_tabs_menu_popup"),d.show(),h.on("click",function(s){s.preventDefault(),t(this).parent().parent().show()}))})}}},t.fn[n]=function(t){return this.each(function(){new e(this,t)})}}(jQuery,window,document); |