joomla_test/modules/mod_roktabs/tmpl/roktabs.js
2020-01-02 22:20:31 +07:00

42 lines
8.2 KiB
JavaScript

var RokTabsOptions={mouseevent:[],duration:[],transition:[],auto:[],delay:[],type:[],arrows:[],tabsScroll:[],linksMargins:[],navscroll:[],marginCompensation:[]};
var RokTabsOptions={mouseevent:[],duration:[],transition:[],auto:[],delay:[],type:[],arrows:[],tabsScroll:[],linksMargins:[],navscroll:[],marginCompensation:[]};
var RokTabs=new Class({version:"1.8 (mt1.2)",Implements:[Options,Events],options:{scroll:RokTabsOptions},initialize:function(a){this.setOptions({scroll:RokTabsOptions});
if(!this.options.scroll.navscroll||!this.options.scroll.navscroll.length){this.options.scroll.navscroll=[];(RokTabsOptions.duration.length).times(function(){this.options.scroll.navscroll.push(true);
}.bind(this));}this.containers=$$(".roktabs-container-inner");this.tabsWrapper=$$(".roktabs-links");this.tabs=$$(".roktabs-links ul");this.panels=$$(".roktabs-container-wrapper");
this.outer=$$(this.tabsWrapper.getParent());this.wrapper=$$(this.outer.getParent());this.fx=[];this.current=[];this.timer=[];this.tabsSize=[];this.tabScroll=[];
this.panels.each(function(b,c){this.current[c]=0;if(!this.options.scroll.mouseevent[c]){this.options.scroll.mouseevent[c]="click";}b.setStyle("width",(Browser.opera)?30000:50000);
if(Browser.ie){b.setStyles({filter:"inherit",position:"relative"}).getChildren().setStyles({filter:"inherit",position:"relative"});}},this);this.attachEvents();
},attachEvents:function(){var b,a=this;this.tabs.each(function(l,g){if(!this.options.scroll.navscroll[g]){this.tabsWrapper.addClass("roktabs-links-noscroll");
}this.outer[g].addEvents({mouseenter:function(){if(a.options.scroll.auto[g]){a.stop(g);}},mouseleave:function(){if(a.options.scroll.auto[g]){a.start(g);
}}});this.fx[g]=new Fx.Scroll(this.panels[g].getParent(),{link:"cancel",wheelStops:false,duration:this.options.scroll.duration[g],transition:this.options.scroll.transition[g]});
this.fx[g].set(0,false);b=0;this.containers[g].setStyle("width",this.wrapper[g].getStyle("width").toInt()-this.tabsWrapper[g].getParent().getStyle("border-left-width").toInt()-this.tabsWrapper[g].getParent().getStyle("border-right-width").toInt());
l.getElements("li").each(function(d,e){var c=this.panels[g].getChildren()[e];c.setStyle("width",((Browser.ie4)?this.wrapper[g]:this.outer[g]).getStyle("width").toInt()-c.getStyle("padding-left").toInt()-c.getStyle("padding-left").toInt()-c.getStyle("margin-left").toInt()-c.getStyle("margin-left").toInt());
b+=d.getSize().x;if(this.options.scroll.marginCompensation[g]){b+=d.getStyle("margin-left").toInt()+d.getStyle("margin-right").toInt();}d.setStyle("cursor","pointer").addEvents({mouseenter:this.mouseenter.bind(this,[d,c,g,e]),mouseleave:this.mouseleave.bind(this,[d,c,g,e]),mousedown:this.mousedown.bind(this,[d,c,g,e]),mouseup:this.mouseup.bind(this,[d,c,g,e])});
},this);this.tabsSize[g]=[l.getSize().x,b];var k=this.outer[g].getElement(".roktabs-arrows");if(this.options.scroll.arrows[g]){var j=k.getElement(".previous");
var h=k.getElement(".next");}if(this.options.scroll.auto[g]){this.start(g);}if(this.tabsSize[g][1]>this.tabsSize[g][0]&&this.options.scroll.navscroll[g]){this.tabScroller(g);
}},this);return this;},mouseenter:function(f,e,h,g){if(f[0]){g=f[3];h=f[2];e=f[1];f=f[0];}f.addClass("hover").addClass("over");this.fireEvent("mouseenter",[f,e,h,g]);
if(RokTabsOptions.mouseevent[h]=="mouseenter"){this.mousedown(f,e,h,g,true);this.mouseup(f,e,h,g,true);}},mouseleave:function(f,e,h,g){if(f[0]){g=f[3];
h=f[2];e=f[1];f=f[0];}f.removeClass("hover").removeClass("over").removeClass("down").removeClass("up");this.fireEvent("mouseleave",[f,e,h,g]);if(RokTabsOptions.mouseevent[h]=="mouseenter"){this.mouseup(f,e,h,g,true);
}},mousedown:function(i,h,n,m,l){if(i[0]){l=i[4];m=i[3];n=i[2];h=i[1];i=i[0];}i.removeClass("up").addClass("down");if(this.options.scroll.type[n]=="scrolling"){this.fx[n].options.duration=RokTabsOptions.duration[n];
this.fx[n].options.link="cancel";this.fx[n].toElement(h);}else{var k=this;var j=new Fx.Tween(this.fx[n].element,{duration:RokTabsOptions.duration[n]/2,link:"cancel",onComplete:function(){if(!this.to[0].value){k.fx[n].options.duration=0;
k.fx[n].toElement(h);j.start("opacity",1);}}});j.cancel().start("opacity",0);}this.fireEvent("mousedown",[i,h,n,m]);},mouseup:function(g,f,j,i,h){if(g[0]){h=g[4];
i=g[3];j=g[2];f=g[1];g=g[0];}if(RokTabsOptions.mouseevent[j]!="click"&&!h){return;}this.tabs[j].getElements("li").removeClass("active");g.removeClass("down").addClass("up").addClass("active");
this.current[j]=i;this.fireEvent("mouseup",[g,f,j,i]);},click:function(g,f,j,i,h){if(g[0]){h=g[4];i=g[3];j=g[2];f=g[1];g=g[0];}return g.fireEvent("mousedown",[g,f,j,i],h).fireEvent("mouseup",[g,f,j,i]).fireEvent("mouseleave",[g,f,j,i]);
},start:function(d){clearTimeout(this.timer[d]);var c=this.next.bind(this,d);this.timer[d]=c.periodical(this.options.scroll.delay[d]);},stop:function(b){clearTimeout(this.timer[b]);
},next:function(e){var d=this.tabs.getElements("li");var h=this.current[e]+1,g=d[e][h],f;if(g){f=g;}else{f=d[e][0];h=0;}return this.click(f,this.panels[e],e,h);
},previous:function(e){var d=this.tabs.getElements("li");var h=this.current[e]-1,g=d[e][h],f;if(g){f=g;}else{f=d[e][d.length];h=d.length;}return this.click(f,this.panels[e],e,h);
},goTo:function(g,f){var k=this.tabs.getElements("li");var j=k[g][f],h;if(j){h=j;}else{h=k[g][0];current=0;}var i=this.panels[g].getChildren()[f];if(this.options.scroll.mouseevent[g]=="mouseenter"){this.mouseenter(h,i,g,j,true);
}return this.click(h,i,g,j,true);},tabView:function(d,c){if(c=="hide"){this.tabs[d].setStyle("display","none");}else{this.tabs[d].setStyle("display","");
}},tabPosition:function(e,d){var f=this.tabsWrapper[e];switch(d){case"top":f.inject(f.getParent(),"top");f.getFirst().removeProperty("class").addClass("roktabs-top");
break;case"bottom":default:f.inject(f.getParent());f.getFirst().removeProperty("class").addClass("roktabs-bottom");}},tabScroller:function(r){var q=this.tabs[r],s=this;
var p=q.getParent();(2).times(function(){s.tabsSize[r][1]=0;q.getChildren().each(function(b){if(window.ie){b.getFirst().inject(b);}s.tabsSize[r][1]+=b.getSize().x+b.getStyle("margin-left").toInt()+b.getStyle("margin-right").toInt()+b.getStyle("padding-left").toInt()+b.getStyle("padding-right").toInt()+b.getStyle("border-left-width").toInt()+b.getStyle("border-right-width").toInt();
},this);q.setStyle("width",s.tabsSize[r][1]+((Browser.firefox)?5:(Browser.ie6)?0.5:0));}.bind(this));p.setStyles({overflow:"hidden",width:this.tabsSize[r][0],position:"relative"});
if(q.getSize().x>p.getSize().x){var o=new Element("div",{"class":"active-arrows"}).setStyle("position","relative").inject(p,"before").adopt(p);var n=new Element("div",{"class":"arrow-prev png"}).set("html","<span><</span>").inject(o,"top");
var m=new Element("div",{"class":"arrow-next png"}).set("html","<span>></span>").inject(o);var l={prev:n.getStyle("width").toInt()+n.getStyle("margin-left").toInt()+n.getStyle("margin-right").toInt()+n.getStyle("border-left").toInt()+n.getStyle("border-right").toInt()+n.getStyle("padding-left").toInt()+n.getStyle("padding-right").toInt(),next:m.getStyle("width").toInt()+m.getStyle("margin-left").toInt()+m.getStyle("margin-right").toInt()+m.getStyle("border-left").toInt()+m.getStyle("border-right").toInt()+m.getStyle("padding-left").toInt()+m.getStyle("padding-right").toInt()};
var k=0;if(this.options.scroll.linksMargins[r]){k=p.getStyle("margin-right").toInt();}if(k<0){k=Math.abs(k)/2;}p.setStyle("width",this.tabsSize[r][0]-k-l.prev-l.next);
new Element("div",{"class":"clear"}).inject(o);this.tabScroll[r]={speed:70,amount:30,current:0};var a;m.addEvents({mouseenter:function(){clearTimeout(a);
this.addClass("arrow-next-hover");a=s.tabScrollerAnim.periodical(s.tabScroll[r]["speed"],s,[r,p,true]);},mouseleave:function(){this.removeClass("arrow-next-hover");
clearTimeout(a);}});n.addEvents({mouseenter:function(){clearTimeout(a);this.addClass("arrow-prev-hover");a=s.tabScrollerAnim.periodical(s.tabScroll[r]["speed"],s,[r,p,false]);
},mouseleave:function(){this.removeClass("arrow-prev-hover");clearTimeout(a);}});}},tabScrollerAnim:function(g,f,k){var j=f.getScrollSize().x,i=f.getScroll().x;
var h;if(k){h=i+this.tabScroll[g]["amount"];}else{h=i-this.tabScroll[g]["amount"];}h=(h<0)?0:(h>=j)?j:h;f.scrollTo(h,0);}});var roktabs;window.addEvent("load",function(){roktabs=new RokTabs();
});