/*! * jScrollPane - v2.0.0beta11 - 2011-07-04 * http://jscrollpane.kelvinluck.com/ * * Copyright (c) 2010 Kelvin Luck * Dual licensed under the MIT and GPL licenses. */ // Script: jScrollPane - cross browser customisable scrollbars // // *Version: 2.0.0beta11, Last updated: 2011-07-04* // // Project Home - http://jscrollpane.kelvinluck.com/ // GitHub - http://github.com/vitch/jScrollPane // Source - http://github.com/vitch/jScrollPane/raw/master/script/jquery.jscrollpane.js // (Minified) - http://github.com/vitch/jScrollPane/raw/master/script/jquery.jscrollpane.min.js // // About: License // // Copyright (c) 2011 Kelvin Luck // Dual licensed under the MIT or GPL Version 2 licenses. // http://jscrollpane.kelvinluck.com/MIT-LICENSE.txt // http://jscrollpane.kelvinluck.com/GPL-LICENSE.txt // // About: Examples // // All examples and demos are available through the jScrollPane example site at: // http://jscrollpane.kelvinluck.com/ // // About: Support and Testing // // This plugin is tested on the browsers below and has been found to work reliably on them. If you run // into a problem on one of the supported browsers then please visit the support section on the jScrollPane // website (http://jscrollpane.kelvinluck.com/) for more information on getting support. You are also // welcome to fork the project on GitHub if you can contribute a fix for a given issue. // // jQuery Versions - tested in 1.4.2+ - reported to work in 1.3.x // Browsers Tested - Firefox 3.6.8, Safari 5, Opera 10.6, Chrome 5.0, IE 6, 7, 8 // // About: Release History // // 2.0.0beta11 - (in progress) // 2.0.0beta10 - (2011-04-17) cleaner required size calculation, improved keyboard support, stickToBottom/Left, other small fixes // 2.0.0beta9 - (2011-01-31) new API methods, bug fixes and correct keyboard support for FF/OSX // 2.0.0beta8 - (2011-01-29) touchscreen support, improved keyboard support // 2.0.0beta7 - (2011-01-23) scroll speed consistent (thanks Aivo Paas) // 2.0.0beta6 - (2010-12-07) scrollToElement horizontal support // 2.0.0beta5 - (2010-10-18) jQuery 1.4.3 support, various bug fixes // 2.0.0beta4 - (2010-09-17) clickOnTrack support, bug fixes // 2.0.0beta3 - (2010-08-27) Horizontal mousewheel, mwheelIntent, keyboard support, bug fixes // 2.0.0beta2 - (2010-08-21) Bug fixes // 2.0.0beta1 - (2010-08-17) Rewrite to follow modern best practices and enable horizontal scrolling, initially hidden // elements and dynamically sized elements. // 1.x - (2006-12-31 - 2010-07-31) Initial version, hosted at googlecode, deprecated (function(a,b,c){a.fn.jScrollPane=function(b){function d(b,d){function T(d){var f,q,r,t,u,w,x=!1,y=!1;e=d;if(g===c)u=b.scrollTop(),w=b.scrollLeft(),b.css({overflow:"hidden",padding:0}),h=b.innerWidth()+L,i=b.innerHeight(),b.width(h),g=a('
').css("padding",K).append(b.children()),j=a('
').css({width:h+"px",height:i+"px"}).append(g).appendTo(b);else{b.css("width",""),x=e.stickToBottom&&bp(),y=e.stickToRight&&bq(),t=b.innerWidth()+L!=h||b.outerHeight()!=i,t&&(h=b.innerWidth()+L,i=b.innerHeight(),j.css({width:h+"px",height:i+"px"}));if(!t&&M==k&&g.outerHeight()==l){b.width(h);return}M=k,g.css("width",""),b.width(h),j.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end()}g.css("overflow","auto"),d.contentWidth?k=d.contentWidth:k=g[0].scrollWidth,l=g[0].scrollHeight,g.css("overflow",""),m=k/h,n=l/i,o=n>1,p=m>1,!p&&!o?(b.removeClass("jspScrollable"),g.css({top:0,width:j.width()-L}),bs(),bv(),bx(),bc(),bz()):(b.addClass("jspScrollable"),f=e.maintainPosition&&(s||v),f&&(q=bn(),r=bo()),U(),W(),Y(),f&&(bl(y?k-h:q,!1),bk(x?l-i:r,!1)),bu(),br(),bB(),e.enableKeyboardNavigation&&bw(),e.clickOnTrack&&bb(),by(),e.hijackInternalLinks&&bA()),e.autoReinitialise&&!J?J=setInterval(function(){T(e)},e.autoReinitialiseDelay):!e.autoReinitialise&&J&&clearInterval(J),u&&b.scrollTop(0)&&bk(u,!1),w&&b.scrollLeft(0)&&bl(w,!1),b.trigger("jsp-initialised",[p||o])}function U(){o&&(j.append(a('
').append(a('
'),a('
').append(a('
').append(a('
'),a('
'))),a('
'))),w=j.find(">.jspVerticalBar"),x=w.find(">.jspTrack"),q=x.find(">.jspDrag"),e.showArrows&&(B=a('').bind("mousedown.jsp",_(0,-1)).bind("click.jsp",bt),C=a('').bind("mousedown.jsp",_(0,1)).bind("click.jsp",bt),e.arrowScrollOnHover&&(B.bind("mouseover.jsp",_(0,-1,B)),C.bind("mouseover.jsp",_(0,1,C))),Z(x,e.verticalArrowPositions,B,C)),z=i,j.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function(){z-=a(this).outerHeight()}),q.hover(function(){q.addClass("jspHover")},function(){q.removeClass("jspHover")}).bind("mousedown.jsp",function(b){a("html").bind("dragstart.jsp selectstart.jsp",bt),q.addClass("jspActive");var c=b.pageY-q.position().top;return a("html").bind("mousemove.jsp",function(a){be(a.pageY-c,!1)}).bind("mouseup.jsp mouseleave.jsp",bd),!1}),V())}function V(){x.height(z+"px"),s=0,y=e.verticalGutter+x.outerWidth(),g.width(h-y-L);try{w.position().left===0&&g.css("margin-left",y+"px")}catch(a){}}function W(){p&&(j.append(a('
').append(a('
'),a('
').append(a('
').append(a('
'),a('
'))),a('
'))),D=j.find(">.jspHorizontalBar"),E=D.find(">.jspTrack"),t=E.find(">.jspDrag"),e.showArrows&&(H=a('').bind("mousedown.jsp",_(-1,0)).bind("click.jsp",bt),I=a('').bind("mousedown.jsp",_(1,0)).bind("click.jsp",bt),e.arrowScrollOnHover&&(H.bind("mouseover.jsp",_(-1,0,H)),I.bind("mouseover.jsp",_(1,0,I))),Z(E,e.horizontalArrowPositions,H,I)),t.hover(function(){t.addClass("jspHover")},function(){t.removeClass("jspHover")}).bind("mousedown.jsp",function(b){a("html").bind("dragstart.jsp selectstart.jsp",bt),t.addClass("jspActive");var c=b.pageX-t.position().left;return a("html").bind("mousemove.jsp",function(a){bg(a.pageX-c,!1)}).bind("mouseup.jsp mouseleave.jsp",bd),!1}),F=j.innerWidth(),X())}function X(){j.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){F-=a(this).outerWidth()}),E.width(F+"px"),v=0}function Y(){if(p&&o){var b=E.outerHeight(),c=x.outerWidth();z-=b,a(D).find(">.jspCap:visible,>.jspArrow").each(function(){F+=a(this).outerWidth()}),F-=c,i-=c,h-=b,E.parent().append(a('
').css("width",b+"px")),V(),X()}p&&g.width(j.outerWidth()-L+"px"),l=g.outerHeight(),n=l/i,p&&(G=Math.ceil(1/m*F),G>e.horizontalDragMaxWidth?G=e.horizontalDragMaxWidth:Ge.verticalDragMaxHeight?A=e.verticalDragMaxHeight:Ac?f.scrollByY(-g):be(c);else if(h>0)s+oc?f.scrollByX(-g):bg(c);else if(i>0)v+or&&(a=r),b===c&&(b=e.animateScroll),b?f.animate(q,"top",a,bf):(q.css("top",a),bf(a))}function bf(a){a===c&&(a=q.position().top),j.scrollTop(0),s=a;var d=s===0,e=s==r,f=a/r,h=-f*(l-i);if(N!=d||P!=e)N=d,P=e,b.trigger("jsp-arrow-change",[N,P,O,Q]);bi(d,e),g.css("top",h),b.trigger("jsp-scroll-y",[-h,d,e]).trigger("scroll")}function bg(a,b){if(!p)return;a<0?a=0:a>u&&(a=u),b===c&&(b=e.animateScroll),b?f.animate(t,"left",a,bh):(t.css("left",a),bh(a))}function bh(a){a===c&&(a=t.position().left),j.scrollTop(0),v=a;var d=v===0,e=v==u,f=a/u,i=-f*(k-h);if(O!=d||Q!=e)O=d,Q=e,b.trigger("jsp-arrow-change",[N,P,O,Q]);bj(d,e),g.css("left",i),b.trigger("jsp-scroll-x",[-i,d,e]).trigger("scroll")}function bi(a,b){e.showArrows&&(B[a?"addClass":"removeClass"]("jspDisabled"),C[b?"addClass":"removeClass"]("jspDisabled"))}function bj(a,b){e.showArrows&&(H[a?"addClass":"removeClass"]("jspDisabled"),I[b?"addClass":"removeClass"]("jspDisabled"))}function bk(a,b){var c=a/(l-i);be(c*r,b)}function bl(a,b){var c=a/(k-h);bg(c*u,b)}function bm(b,c,d){var f,g,k,l=0,m=0,n,o,p,q,r,s;try{f=a(b)}catch(t){return}g=f.outerHeight(),k=f.outerWidth(),j.scrollTop(0),j.scrollLeft(0);while(!f.is(".jspPane")){l+=f.position().top,m+=f.position().left,f=f.offsetParent();if(/^body|html$/i.test(f[0].nodeName))return}n=bo(),p=n+i,lp&&(r=l-i+g+e.verticalGutter),r&&bk(r,d),o=bn(),q=o+h,mq&&(s=m-h+k+e.horizontalGutter),s&&bl(s,d)}function bn(){return-g.position().left}function bo(){return-g.position().top}function bp(){var a=l-i;return a>20&&a-bo()<10}function bq(){var a=k-h;return a>20&&a-bn()<10}function br(){j.unbind(S).bind(S,function(a,b,c,d){var g=v,h=s;return f.scrollBy(c*e.mouseWheelSpeed,-d*e.mouseWheelSpeed,!1),g==v&&h==s})}function bs(){j.unbind(S)}function bt(){return!1}function bu(){g.find(":input,a").unbind("focus.jsp").bind("focus.jsp",function(a){bm(a.target,!1)})}function bv(){g.find(":input,a").unbind("focus.jsp")}function bw(){function k(){var a=v,b=s;switch(c){case 40:f.scrollByY(e.keyboardSpeed,!1);break;case 38:f.scrollByY(-e.keyboardSpeed,!1);break;case 34:case 32:f.scrollByY(i*e.scrollPagePercent,!1);break;case 33:f.scrollByY(-i*e.scrollPagePercent,!1);break;case 39:f.scrollByX(e.keyboardSpeed,!1);break;case 37:f.scrollByX(-e.keyboardSpeed,!1)}return d=a!=v||b!=s,d}var c,d,h=[];p&&h.push(D[0]),o&&h.push(w[0]),g.focus(function(){b.focus()}),b.attr("tabindex",0).unbind("keydown.jsp keypress.jsp").bind("keydown.jsp",function(b){if(b.target!==this&&(!h.length||!a(b.target).closest(h).length))return;var e=v,f=s;switch(b.keyCode){case 40:case 38:case 34:case 32:case 33:case 39:case 37:c=b.keyCode,k();break;case 35:bk(l-i),c=null;break;case 36:bk(0),c=null}return d=b.keyCode==c&&e!=v||f!=s,!d}).bind("keypress.jsp",function(a){return a.keyCode==c&&k(),!d}),e.hideFocus?(b.css("outline","none"),"hideFocus"in j[0]&&b.attr("hideFocus",!0)):(b.css("outline",""),"hideFocus"in j[0]&&b.attr("hideFocus",!1))}function bx(){b.attr("tabindex","-1").removeAttr("tabindex").unbind("keydown.jsp keypress.jsp")}function by(){if(location.hash&&location.hash.length>1){var b,c,d=escape(location.hash);try{b=a(d)}catch(e){return}b.length&&g.find(d)&&(j.scrollTop()===0?c=setInterval(function(){j.scrollTop()>0&&(bm(d,!0),a(document).scrollTop(j.position().top),clearInterval(c))},50):(bm(d,!0),a(document).scrollTop(j.position().top)))}}function bz(){a("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function bA(){bz(),a("a[href^=#]").addClass("jspHijack").bind("click.jsp-hijack",function(){var a=this.href.split("#"),b;if(a.length>1){b=a[1];if(b.length>0&&g.find("#"+b).length>0)return bm("#"+b,!0),!1}})}function bB(){var a,b,c,d,e,g=!1;j.unbind("touchstart.jsp touchmove.jsp touchend.jsp click.jsp-touchclick").bind("touchstart.jsp",function(f){var h=f.originalEvent.touches[0];a=bn(),b=bo(),c=h.pageX,d=h.pageY,e=!1,g=!0}).bind("touchmove.jsp",function(h){if(!g)return;var i=h.originalEvent.touches[0],j=v,k=s;return f.scrollTo(a+c-i.pageX,b+d-i.pageY),e=e||Math.abs(c-i.pageX)>5||Math.abs(d-i.pageY)>5,j==v&&k==s}).bind("touchend.jsp",function(a){g=!1}).bind("click.jsp-touchclick",function(a){if(e)return e=!1,!1})}function bC(){var a=bo(),c=bn();b.removeClass("jspScrollable").unbind(".jsp"),b.replaceWith(R.append(g.children())),R.scrollTop(a),R.scrollLeft(c),J&&clearInterval(J)}var e,f=this,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N=!0,O=!0,P=!1,Q=!1,R=b.clone(!1,!1).empty(),S=a.fn.mwheelIntent?"mwheelIntent.jsp":"mousewheel.jsp";K=b.css("paddingTop")+" "+b.css("paddingRight")+" "+b.css("paddingBottom")+" "+b.css("paddingLeft"),L=(parseInt(b.css("paddingLeft"),10)||0)+(parseInt(b.css("paddingRight"),10)||0),a.extend(f,{reinitialise:function(b){b=a.extend({},e,b),T(b)},scrollToElement:function(a,b,c){bm(a,b,c)},scrollTo:function(a,b,c){bl(a,c),bk(b,c)},scrollToX:function(a,b){bl(a,b)},scrollToY:function(a,b){bk(a,b)},scrollToPercentX:function(a,b){bl(a*(k-h),b)},scrollToPercentY:function(a,b){bk(a*(l-i),b)},scrollBy:function(a,b,c){f.scrollByX(a,c),f.scrollByY(b,c)},scrollByX:function(a,b){var c=bn()+Math[a<0?"floor":"ceil"](a),d=c/(k-h);bg(d*u,b)},scrollByY:function(a,b){var c=bo()+Math[a<0?"floor":"ceil"](a),d=c/(l-i);be(d*r,b)},positionDragX:function(a,b){bg(a,b)},positionDragY:function(a,b){be(a,b)},animate:function(a,b,c,d){var f={};f[b]=c,a.animate(f,{duration:e.animateDuration,easing:e.animateEase,queue:!1,step:d})},getContentPositionX:function(){return bn()},getContentPositionY:function(){return bo()},getContentWidth:function(){return k},getContentHeight:function(){return l},getPercentScrolledX:function(){return bn()/(k-h)},getPercentScrolledY:function(){return bo()/(l-i)},getIsScrollableH:function(){return p},getIsScrollableV:function(){return o},getContentPane:function(){return g},scrollToBottom:function(a){be(r,a)},hijackInternalLinks:function(){bA()},destroy:function(){bC()}}),T(d)}return b=a.extend({},a.fn.jScrollPane.defaults,b),a.each(["mouseWheelSpeed","arrowButtonSpeed","trackClickSpeed","keyboardSpeed"],function(){b[this]=b[this]||b.speed}),this.each(function(){var c=a(this),e=c.data("jsp");e?e.reinitialise(b):(e=new d(c,b),c.data("jsp",e))})},a.fn.jScrollPane.defaults={showArrows:!1,maintainPosition:!0,stickToBottom:!1,stickToRight:!1,clickOnTrack:!0,autoReinitialise:!1,autoReinitialiseDelay:500,verticalDragMinHeight:0,verticalDragMaxHeight:99999,horizontalDragMinWidth:0,horizontalDragMaxWidth:99999,contentWidth:c,animateScroll:!1,animateDuration:300,animateEase:"linear",hijackInternalLinks:!1,verticalGutter:4,horizontalGutter:4,mouseWheelSpeed:0,arrowButtonSpeed:0,arrowRepeatFreq:50,arrowScrollOnHover:!1,trackClickSpeed:0,trackClickRepeatFreq:70,verticalArrowPositions:"split",horizontalArrowPositions:"split",enableKeyboardNavigation:!0,hideFocus:!1,keyboardSpeed:0,initialDelay:300,speed:30,scrollPagePercent:.8}})(jQuery,this)