Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

/*
 * jScrollPane - v2.0.0beta2 - 2010-08-21
 * 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(aj,ag){var aq,h=this,af,S,ax,Y,ao,ae,F,q,au,m,Z,A,p,at,E,Q,ah,W,o,T,D,ac,G,I,P,n,K,y,ar,z,L,C,an,X=wasAtLeft=true,aw=wasAtRight=false;L=aj.css("paddingTop")+" "+aj.css("paddingRight")+" "+aj.css("paddingBottom")+" "+aj.css("paddingLeft");C=(parseInt(aj.css("paddingLeft"))||0)+(parseInt(aj.css("paddingRight"))||0);J(ag);function J(aA){var aE,aD,aC,az,ay,aB;aq=aA;if(af==c){aj.css({overflow:"hidden",padding:0});S=aj.innerWidth()+C;ax=aj.innerHeight();aj.width(S);af=b('<div class="jspPane" />').wrap(b('<div class="jspContainer" />').css({width:S+"px",height:ax+"px"}));aj.wrapInner(af.parent());Y=aj.find(">.jspContainer");af=Y.find(">.jspPane");af.css("padding",L)}else{aj.css("width",null);aB=aj.outerWidth()+C!=S||aj.outerHeight()!=ax;if(aB){S=aj.innerWidth()+C;ax=aj.innerHeight();Y.css({width:S+"px",height:ax+"px"})}an=af.innerWidth();if(!aB&&af.outerWidth()==ao&&af.outerHeight()==ae){if(m||au){af.css("width",an+"px");aj.css("width",(an+C)+"px")}return}af.css("width",null);aj.css("width",(S+C)+"px");Y.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end()}aE=af.clone().css("position","absolute");aD=b('<div style="width:1px; position: relative;" />').append(aE);b("body").append(aD);ao=Math.max(af.outerWidth(),aE.outerWidth());aD.remove();ae=af.outerHeight();F=ao/S;q=ae/ax;au=q>1;m=F>1;if(!(m||au)){aj.removeClass("jspScrollable");af.css({top:0,width:Y.width()+"px"});R();r();u()}else{aj.addClass("jspScrollable");aC=aq.maintainPosition&&(p||Q);if(aC){az=j();ay=g()}x();al();k();if(aC){w(az);v(ay)}t();l();av();if(aq.hijackInternalLinks){i()}}if(aq.autoReinitialise&&!z){z=setInterval(function(){J(aq)},aq.autoReinitialiseDelay)}else{if(!aq.autoReinitialise&&z){clearInterval(z)}}aj.trigger("jsp-initialised",[m||au])}function x(){if(au){Y.append(b('<div class="jspVerticalBar" />').append(b('<div class="jspCap jspCapTop" />'),b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragTop" />'),b('<div class="jspDragBottom" />'))),b('<div class="jspCap jspCapBottom" />')));ah=Y.find(">.jspVerticalBar");W=ah.find(">.jspTrack");Z=W.find(">.jspDrag");if(aq.showArrows){ac=b('<a class="jspArrow jspArrowUp" />').bind("mousedown.jsp",H(0,-1)).bind("click.jsp",ak);G=b('<a class="jspArrow jspArrowDown" />').bind("mousedown.jsp",H(0,1)).bind("click.jsp",ak);if(aq.arrowScrollOnHover){ac.bind("mouseover.jsp",H(0,-1,ac));G.bind("mouseover.jsp",H(0,1,G))}V(W,aq.verticalArrowPositions,ac,G)}T=ax;Y.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function(){T-=b(this).outerHeight()});Z.hover(function(){Z.addClass("jspHover")},function(){Z.removeClass("jspHover")}).bind("mousedown.jsp",function(ay){b("html").bind("dragstart.jsp selectstart.jsp",function(){return false});Z.addClass("jspActive");var s=ay.pageY-Z.position().top;b("html").bind("mousemove.jsp",function(az){M(az.pageY-s,false)}).bind("mouseup.jsp mouseleave.jsp",B);return false});O();ai()}}function O(){W.height(T+"px");p=0;o=aq.verticalGutter+W.outerWidth();af.width(S-o-C);if(ah.position().left==0){af.css("margin-left",o+"px")}}function al(){if(m){Y.append(b('<div class="jspHorizontalBar" />').append(b('<div class="jspCap jspCapLeft" />'),b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragLeft" />'),b('<div class="jspDragRight" />'))),b('<div class="jspCap jspCapRight" />')));I=Y.find(">.jspHorizontalBar");P=I.find(">.jspTrack");at=P.find(">.jspDrag");if(aq.showArrows){y=b('<a class="jspArrow jspArrowLeft" />').bind("mousedown.jsp",H(-1,0)).bind("click.jsp",ak);ar=b('<a class="jspArrow jspArrowRight" />').bind("mousedown.jsp",H(1,0)).bind("click.jsp",ak);if(aq.arrowScrollOnHover){y.bind("mouseover.jsp",H(-1,0,y));ar.bind("mouseover.jsp",H(1,0,ar))}V(P,aq.horizontalArrowPositions,y,ar)
}at.hover(function(){at.addClass("jspHover")},function(){at.removeClass("jspHover")}).bind("mousedown.jsp",function(ay){b("html").bind("dragstart.jsp selectstart.jsp",function(){return false});at.addClass("jspActive");var s=ay.pageX-at.position().left;b("html").bind("mousemove.jsp",function(az){N(az.pageX-s,false)}).bind("mouseup.jsp mouseleave.jsp",B);return false});n=Y.innerWidth();ad();ap()}else{}}function ad(){Y.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){n-=b(this).outerWidth()});P.width(n+"px");Q=0}function k(){if(m&&au){var ay=P.outerHeight(),s=W.outerWidth();T-=ay;b(I).find(">.jspCap:visible,>.jspArrow").each(function(){n+=b(this).outerWidth()});n-=s;ax-=s;S-=ay;P.parent().append(b('<div class="jspCorner" />').css("width",ay+"px"));O();ad()}if(m){af.width((Y.outerWidth()-C)+"px")}ae=af.outerHeight();q=ae/ax;if(m){K=1/F*n;if(K>aq.horizontalDragMaxWidth){K=aq.horizontalDragMaxWidth}else{if(K<aq.horizontalDragMinWidth){K=aq.horizontalDragMinWidth}}at.width(K+"px");E=n-K}if(au){D=1/q*T;if(D>aq.verticalDragMaxHeight){D=aq.verticalDragMaxHeight}else{if(D<aq.verticalDragMinHeight){D=aq.verticalDragMinHeight}}Z.height(D+"px");A=T-D}}function V(az,aB,ay,s){var aD="before",aA="after",aC;if(aB=="os"){aB=/Mac/.test(navigator.platform)?"after":"split"}if(aB==aD){aA=aB}else{if(aB==aA){aD=aB;aC=ay;ay=s;s=aC}}az[aD](ay)[aA](s)}function H(ay,s,az){return function(){am(ay,s,this,az);this.blur();return false}}function am(aA,ay,aD,aC){aD=b(aD).addClass("jspActive");var aB,s=function(){if(aA!=0){N(Q+aA*aq.arrowButtonSpeed,false)}if(ay!=0){M(p+ay*aq.arrowButtonSpeed,false)}},az=setInterval(s,aq.arrowRepeatFreq);s();aB=aC==c?"mouseup.jsp":"mouseout.jsp";aC=aC||b("html");aC.bind(aB,function(){aD.removeClass("jspActive");clearInterval(az);aC.unbind(aB)})}function B(){b("html").unbind("dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp");Z&&Z.removeClass("jspActive");at&&at.removeClass("jspActive")}function M(s,ay){if(!au){return}if(s<0){s=0}else{if(s>A){s=A}}if(ay==c){ay=aq.animateScroll}if(ay){h.animate(Z,"top",s,aa)}else{Z.css("top",s);aa(s)}}function aa(ay){if(ay==c){ay=Z.position().top}Y.scrollTop(0);p=ay;var aB=p==0,az=p==A,aA=ay/A,s=-aA*(ae-ax);if(X!=aB||aw!=az){X=aB;aw=az;aj.trigger("jsp-arrow-change",[X,aw,wasAtLeft,wasAtRight])}ai(aB,az);af.css("top",s);aj.trigger("jsp-scroll-y",[-s,aB,az])}function N(ay,s){if(!m){return}if(ay<0){ay=0}else{if(ay>E){ay=E}}if(s==c){s=aq.animateScroll}if(s){h.animate(at,"left",ay,ab)}else{at.css("left",ay);ab(ay)}}function ab(ay){if(ay==c){ay=at.position().left}Y.scrollTop(0);Q=ay;var aB=Q==0,aA=Q==A,az=ay/E,s=-az*(ao-S);if(wasAtLeft!=aB||wasAtRight!=aA){wasAtLeft=aB;wasAtRight=aA;aj.trigger("jsp-arrow-change",[X,aw,wasAtLeft,wasAtRight])}ap(aB,aA);af.css("left",s);aj.trigger("jsp-scroll-x",[-s,aB,aA])}function ai(ay,s){if(aq.showArrows){ac[ay?"addClass":"removeClass"]("jspDisabled");G[s?"addClass":"removeClass"]("jspDisabled")}}function ap(ay,s){if(aq.showArrows){y[ay?"addClass":"removeClass"]("jspDisabled");ar[s?"addClass":"removeClass"]("jspDisabled")}}function v(s,ay){var az=s/(ae-ax);M(az*A,ay)}function w(ay,s){var az=ay/(ao-S);N(az*E,s)}function U(aG,aE,ay){var aC,aA,s=0,az,aD,aF;try{aC=b(aG)}catch(aB){return}aA=aC.outerHeight();Y.scrollTop(0);while(!aC.is(".jspPane")){s+=aC.position().top;aC=aC.offsetParent();if(/^body|html$/i.test(aC[0].nodeName)){return}}az=g();aD=az+ax;if(s<az||aE){aF=s-aq.verticalGutter}else{if(s+aA>aD){aF=s-ax+aA+aq.verticalGutter}}if(aF){v(aF,ay)}}function j(){return -af.position().left}function g(){return -af.position().top}function l(){Y.unbind("mousewheel.jsp").bind("mousewheel.jsp",function(aB,aC,aA,ay){var az=Q,s=p;N(Q+aA*aq.mouseWheelSpeed,false);M(p-ay*aq.mouseWheelSpeed,false);return az==Q&&s==p})}function R(){Y.unbind("mousewheel.jsp")}function ak(){return false}function t(){af.unbind("focusin.jsp").bind("focusin.jsp",function(s){U(s.target,false)})}function r(){af.unbind("focusin.jsp")}function av(){if(location.hash&&location.hash.length>1){var az,ay;
try{az=b(location.hash)}catch(s){return}if(az.length&&af.find(az)){if(Y.scrollTop()==0){ay=setInterval(function(){if(Y.scrollTop()>0){U(location.hash,true);b(document).scrollTop(Y.position().top);clearInterval(ay)}},50)}else{U(location.hash,true);b(document).scrollTop(Y.position().top)}}}}function u(){b("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function i(){u();b("a[href^=#]").addClass("jspHijack").bind("click.jsp-hijack",function(){var s=this.href.split("#"),ay;if(s.length>1){ay=s[1];if(ay.length>0&&af.find("#"+ay).length>0){U("#"+ay,true);return false}}})}b.extend(h,{reinitialise:function(ay){ay=b.extend({},ay,aq);J(ay)},scrollToElement:function(az,ay,s){U(az,ay,s)},scrollTo:function(az,s,ay){w(az,ay);v(s,ay)},scrollToX:function(ay,s){w(ay,s)},scrollToY:function(s,ay){v(s,ay)},scrollBy:function(ay,s,az){h.scrollByX(ay,az);h.scrollByY(s,az)},scrollByX:function(s,az){var ay=j()+s,aA=ay/(ao-S);N(aA*E,az)},scrollByY:function(s,az){var ay=g()+s,aA=ay/(ae-ax);M(aA*A,az)},animate:function(ay,aB,s,aA){var az={};az[aB]=s;ay.animate(az,{duration:aq.animateDuration,ease:aq.animateEase,queue:false,step:aA})},getContentPositionX:function(){return j()},getContentPositionY:function(){return g()},getIsScrollableH:function(){return m},getIsScrollableV:function(){return au},getContentPane:function(){return af},scrollToBottom:function(s){M(A,s)},hijackInternalLinks:function(){i()}})}f=b.extend({},b.fn.jScrollPane.defaults,f);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,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:10,arrowButtonSpeed:10,arrowRepeatFreq:100,arrowScrollOnHover:false,verticalArrowPositions:"split",horizontalArrowPositions:"split"}})(jQuery,this);