/* * jScrollPane - v2.0.0beta8 - 2011-01-24 * http://jscrollpane.kelvinluck.com/ * * Copyright (c) 2010 Kelvin Luck * Dual licensed under the MIT and GPL licenses. */ (function(b,a,c){b.fn.jScrollPane=function(f){function d(C,M){var av,O=this,W,ai,v,ak,R,X,y,q,aw,aB,aq,i,H,h,j,Y,S,am,V,t,A,an,ad,al,F,l,ap,au,x,ar,aE,g,J,ah=true,N=true,aD=false,k=false,aa=b.fn.mwheelIntent?"mwheelIntent.jsp":"mousewheel.jsp";aE=C.css("paddingTop")+" "+C.css("paddingRight")+" "+C.css("paddingBottom")+" "+C.css("paddingLeft");g=(parseInt(C.css("paddingLeft"))||0)+(parseInt(C.css("paddingRight"))||0);ao(M);function ao(aH){var aL,aK,aJ,aG,aF,aI;av=aH;if(W===c){C.css({overflow:"hidden",padding:0});ai=C.innerWidth()+g;v=C.innerHeight();C.width(ai);W=b('
').wrap(b('
').css({width:ai+"px",height:v+"px"}));C.wrapInner(W.parent());ak=C.find(">.jspContainer");W=ak.find(">.jspPane");W.css("padding",aE)}else{C.css("width","");aI=C.outerWidth()+g!=ai||C.outerHeight()!=v;if(aI){ai=C.innerWidth()+g;v=C.innerHeight();ak.css({width:ai+"px",height:v+"px"})}if(!aI&&J==R&&W.outerHeight()==X){if(aB||aw){C.css("width",(ai+g)+"px")}return}J=R;W.css("width","");C.css("width",ai+"px");ak.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end()}aL=W.clone().css("position","absolute");aK=b('
').append(aL);b("body").append(aK);R=Math.max(W.outerWidth(),aL.outerWidth());aK.remove();X=W.outerHeight();y=R/ai;q=X/v;aw=q>1;aB=y>1;if(!(aB||aw)){C.removeClass("jspScrollable");W.css({top:0,width:ak.width()-g});n();D();P();w();ag()}else{C.addClass("jspScrollable");aJ=av.maintainPosition&&(H||Y);if(aJ){aG=az();aF=ax()}aC();z();E();if(aJ){L(aG);K(aF)}I();ae();if(av.enableKeyboardNavigation){Q()}if(av.clickOnTrack){p()}B();if(av.hijackInternalLinks){m()}}if(av.autoReinitialise&&!ar){ar=setInterval(function(){ao(av)},av.autoReinitialiseDelay)}else{if(!av.autoReinitialise&&ar){clearInterval(ar)}}C.trigger("jsp-initialised",[aB||aw])}function aC(){if(aw){ak.append(b('
').append(b('
'),b('
').append(b('
').append(b('
'),b('
'))),b('
')));S=ak.find(">.jspVerticalBar");am=S.find(">.jspTrack");aq=am.find(">.jspDrag");if(av.showArrows){an=b('').bind("mousedown.jsp",aA(0,-1)).bind("click.jsp",ay);ad=b('').bind("mousedown.jsp",aA(0,1)).bind("click.jsp",ay);if(av.arrowScrollOnHover){an.bind("mouseover.jsp",aA(0,-1,an));ad.bind("mouseover.jsp",aA(0,1,ad))}aj(am,av.verticalArrowPositions,an,ad)}t=v;ak.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function(){t-=b(this).outerHeight()});aq.hover(function(){aq.addClass("jspHover")},function(){aq.removeClass("jspHover")}).bind("mousedown.jsp",function(aF){b("html").bind("dragstart.jsp selectstart.jsp",function(){return false});aq.addClass("jspActive");var s=aF.pageY-aq.position().top;b("html").bind("mousemove.jsp",function(aG){T(aG.pageY-s,false)}).bind("mouseup.jsp mouseleave.jsp",at);return false});o()}}function o(){am.height(t+"px");H=0;V=av.verticalGutter+am.outerWidth();W.width(ai-V-g);if(S.position().left===0){W.css("margin-left",V+"px")}}function z(){if(aB){ak.append(b('
').append(b('
'),b('
').append(b('
').append(b('
'),b('
'))),b('
')));al=ak.find(">.jspHorizontalBar");F=al.find(">.jspTrack");h=F.find(">.jspDrag");if(av.showArrows){au=b('').bind("mousedown.jsp",aA(-1,0)).bind("click.jsp",ay);x=b('').bind("mousedown.jsp",aA(1,0)).bind("click.jsp",ay);if(av.arrowScrollOnHover){au.bind("mouseover.jsp",aA(-1,0,au)); x.bind("mouseover.jsp",aA(1,0,x))}aj(F,av.horizontalArrowPositions,au,x)}h.hover(function(){h.addClass("jspHover")},function(){h.removeClass("jspHover")}).bind("mousedown.jsp",function(aF){b("html").bind("dragstart.jsp selectstart.jsp",function(){return false});h.addClass("jspActive");var s=aF.pageX-h.position().left;b("html").bind("mousemove.jsp",function(aG){U(aG.pageX-s,false)}).bind("mouseup.jsp mouseleave.jsp",at);return false});l=ak.innerWidth();af()}else{}}function af(){ak.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){l-=b(this).outerWidth()});F.width(l+"px");Y=0}function E(){if(aB&&aw){var aF=F.outerHeight(),s=am.outerWidth();t-=aF;b(al).find(">.jspCap:visible,>.jspArrow").each(function(){l+=b(this).outerWidth()});l-=s;v-=s;ai-=aF;F.parent().append(b('
').css("width",aF+"px"));o();af()}if(aB){W.width((ak.outerWidth()-g)+"px")}X=W.outerHeight();q=X/v;if(aB){ap=1/y*l;if(ap>av.horizontalDragMaxWidth){ap=av.horizontalDragMaxWidth}else{if(apav.verticalDragMaxHeight){A=av.verticalDragMaxHeight}else{if(AaP){O.scrollByY(-aM)}else{T(aP)}}else{if(aJ>0){if(H+aNaP){O.scrollByX(-aM)}else{U(aP)}}else{if(aJ>0){if(Y+aNi){s=i}}if(aF===c){aF=av.animateScroll}if(aF){O.animate(aq,"top",s,ab)}else{aq.css("top",s);ab(s)}}function ab(aF){if(aF===c){aF=aq.position().top}ak.scrollTop(0);H=aF;var aI=H===0,aG=H==i,aH=aF/i,s=-aH*(X-v);if(ah!=aI||aD!=aG){ah=aI;aD=aG;C.trigger("jsp-arrow-change",[ah,aD,N,k])}u(aI,aG);W.css("top",s);C.trigger("jsp-scroll-y",[-s,aI,aG])}function U(aF,s){if(!aB){return}if(aF<0){aF=0}else{if(aF>j){aF=j}}if(s===c){s=av.animateScroll}if(s){O.animate(h,"left",aF,ac)}else{h.css("left",aF);ac(aF)}}function ac(aF){if(aF===c){aF=h.position().left}ak.scrollTop(0); Y=aF;var aI=Y===0,aH=Y==j,aG=aF/j,s=-aG*(R-ai);if(N!=aI||k!=aH){N=aI;k=aH;C.trigger("jsp-arrow-change",[ah,aD,N,k])}r(aI,aH);W.css("left",s);C.trigger("jsp-scroll-x",[-s,aI,aH])}function u(aF,s){if(av.showArrows){an[aF?"addClass":"removeClass"]("jspDisabled");ad[s?"addClass":"removeClass"]("jspDisabled")}}function r(aF,s){if(av.showArrows){au[aF?"addClass":"removeClass"]("jspDisabled");x[s?"addClass":"removeClass"]("jspDisabled")}}function K(s,aF){var aG=s/(X-v);T(aG*i,aF)}function L(aF,s){var aG=aF/(R-ai);U(aG*j,s)}function Z(aR,aM,aG){var aK,aH,aI,s=0,aQ=0,aF,aL,aO,aN,aP;try{aK=b(aR)}catch(aJ){return}aH=aK.outerHeight();aI=aK.outerWidth();ak.scrollTop(0);ak.scrollLeft(0);while(!aK.is(".jspPane")){s+=aK.position().top;aQ+=aK.position().left;aK=aK.offsetParent();if(/^body|html$/i.test(aK[0].nodeName)){return}}aF=ax();aL=aF+v;if(saL){aN=s-v+aH+av.verticalGutter}}if(aN){K(aN,aG)}viewportLeft=az();aO=viewportLeft+ai;if(aQaO){aP=aQ-ai+aI+av.horizontalGutter}}if(aP){L(aP,aG)}}function az(){return -W.position().left}function ax(){return -W.position().top}function ae(){ak.unbind(aa).bind(aa,function(aI,aJ,aH,aF){var aG=Y,s=H;O.scrollBy(-aH*av.mouseWheelSpeed,-aF*av.mouseWheelSpeed);return aG==Y&&s==H})}function n(){ak.unbind(aa)}function ay(){return false}function I(){W.find(":input,a").unbind("focus.jsp").bind("focus.jsp",function(s){if(s.target===W[0]){return}Z(s.target,false)})}function D(){W.find(":input,a").unbind("focus.jsp")}function Q(){C.attr("tabindex",0).unbind("keydown.jsp keyup.jsp").bind("keydown.jsp",function(aG){if(aG.target!==C[0]){return}var aF=Y,s=H;switch(aG.keyCode){case 40:O.scrollByY(av.keyboardSpeed);break;case 38:O.scrollByY(-av.keyboardSpeed);break;case 34:case 32:O.scrollByY(v*av.scrollPagePercent);break;case 33:O.scrollByY(-v*av.scrollPagePercent);break;case 35:K(X-v);break;case 36:K(0);break;case 39:O.scrollByX(av.keyboardSpeed);break;case 37:O.scrollByX(-av.keyboardSpeed);break}if(aF!=Y||s!=H){return false}});if(av.hideFocus){C.css("outline","none");if("hideFocus" in ak[0]){C.attr("hideFocus",true)}}else{C.css("outline","");if("hideFocus" in ak[0]){C.attr("hideFocus",false)}}}function P(){C.attr("tabindex","-1").removeAttr("tabindex").unbind("keydown.jsp").unbind("keyup.jsp")}function B(){if(location.hash&&location.hash.length>1){var aG,aF;try{aG=b(location.hash)}catch(s){return}if(aG.length&&W.find(location.hash)){if(ak.scrollTop()===0){aF=setInterval(function(){if(ak.scrollTop()>0){Z(location.hash,true);b(document).scrollTop(ak.position().top);clearInterval(aF)}},50)}else{Z(location.hash,true);b(document).scrollTop(ak.position().top)}}}}function ag(){b("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function m(){ag();b("a[href^=#]").addClass("jspHijack").bind("click.jsp-hijack",function(){var s=this.href.split("#"),aF;if(s.length>1){aF=s[1];if(aF.length>0&&W.find("#"+aF).length>0){Z("#"+aF,true);return false}}})}b.extend(O,{reinitialise:function(aF){aF=b.extend({},av,aF);ao(aF)},scrollToElement:function(aG,aF,s){Z(aG,aF,s)},scrollTo:function(aG,s,aF){L(aG,aF);K(s,aF)},scrollToX:function(aF,s){L(aF,s)},scrollToY:function(s,aF){K(s,aF)},scrollBy:function(aF,s,aG){O.scrollByX(aF,aG);O.scrollByY(s,aG)},scrollByX:function(s,aG){var aF=az()+s,aH=aF/(R-ai);U(aH*j,aG)},scrollByY:function(s,aG){var aF=ax()+s,aH=aF/(X-v);T(aH*i,aG)},animate:function(aF,aI,s,aH){var aG={};aG[aI]=s;aF.animate(aG,{duration:av.animateDuration,ease:av.animateEase,queue:false,step:aH})},getContentPositionX:function(){return az()},getContentPositionY:function(){return ax()},getIsScrollableH:function(){return aB},getIsScrollableV:function(){return aw},getContentPane:function(){return W},scrollToBottom:function(s){T(i,s)},hijackInternalLinks:function(){m()}})}f=b.extend({},b.fn.jScrollPane.defaults,f);b.each(["mouseWheelSpeed","arrowButtonSpeed","trackClickSpeed","keyboardSpeed"],function(){f[this]=f[this]||f.speed}); var e;this.each(function(){var g=b(this),h=g.data("jsp");if(h){h.reinitialise(f)}else{h=new d(g,f);g.data("jsp",h)}e=e?e.add(g):g});return e};b.fn.jScrollPane.defaults={showArrows:false,maintainPosition:true,clickOnTrack:true,autoReinitialise:false,autoReinitialiseDelay:500,verticalDragMinHeight:0,verticalDragMaxHeight:99999,horizontalDragMinWidth:0,horizontalDragMaxWidth:99999,animateScroll:false,animateDuration:300,animateEase:"linear",hijackInternalLinks:false,verticalGutter:4,horizontalGutter:4,mouseWheelSpeed:0,arrowButtonSpeed:0,arrowRepeatFreq:50,arrowScrollOnHover:false,trackClickSpeed:0,trackClickRepeatFreq:70,verticalArrowPositions:"split",horizontalArrowPositions:"split",enableKeyboardNavigation:true,hideFocus:false,keyboardSpeed:0,initialDelay:300,speed:30,scrollPagePercent:0.8}})(jQuery,this);