perfect-scrollbar/min/perfect-scrollbar-0.4.7.min.js
Hyunje Alex Jun e159cbbda5 Release 0.4.7.
1. Don't prevent the default scrolling for the inactive axis.
2. Enhance the scrolling logic.
3. Implement Home, End, Page Up, Page Down and Spacebar for the key
   scrolling.
4. Bug fixes.
2014-01-21 12:30:13 +09:00

4 lines
6.5 KiB
JavaScript

/*! perfect-scrollbar - v0.4.7
* http://noraesae.github.com/perfect-scrollbar/
* Copyright (c) 2014 Hyeonje Jun; Licensed MIT */
"use strict";(function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)})(function(e){var o={wheelSpeed:10,wheelPropagation:!1,minScrollbarLength:null,useBothWheelAxes:!1,useKeyboard:!0,suppressScrollX:!1,suppressScrollY:!1,scrollXMarginOffset:0,scrollYMarginOffset:0},n=function(){var e=0;return function(){var o=e;return e+=1,".perfect-scrollbar-"+o}}();e.fn.perfectScrollbar=function(t,r){return this.each(function(){var l=e.extend(!0,{},o),s=e(this);if("object"==typeof t?e.extend(!0,l,t):r=t,"update"===r)return s.data("perfect-scrollbar-update")&&s.data("perfect-scrollbar-update")(),s;if("destroy"===r)return s.data("perfect-scrollbar-destroy")&&s.data("perfect-scrollbar-destroy")(),s;if(s.data("perfect-scrollbar"))return s.data("perfect-scrollbar");s.addClass("ps-container");var a,c,i,u,p,d,f,h,b,v,g=e("<div class='ps-scrollbar-x-rail'></div>").appendTo(s),m=e("<div class='ps-scrollbar-y-rail'></div>").appendTo(s),w=e("<div class='ps-scrollbar-x'></div>").appendTo(g),T=e("<div class='ps-scrollbar-y'></div>").appendTo(m),L=parseInt(g.css("bottom"),10),y=parseInt(m.css("right"),10),S=n(),I=function(e,o){var n=e+o,t=u-b;v=0>n?0:n>t?t:n;var r=parseInt(v*(d-u)/(u-b),10);s.scrollTop(r),g.css({bottom:L-r})},C=function(e,o){var n=e+o,t=i-f;h=0>n?0:n>t?t:n;var r=parseInt(h*(p-i)/(i-f),10);s.scrollLeft(r),m.css({right:y-r})},X=function(e){return l.minScrollbarLength&&(e=Math.max(e,l.minScrollbarLength)),e},Y=function(){g.css({left:s.scrollLeft(),bottom:L-s.scrollTop(),width:i,display:l.suppressScrollX?"none":"inherit"}),m.css({top:s.scrollTop(),right:y-s.scrollLeft(),height:u,display:l.suppressScrollY?"none":"inherit"}),w.css({left:h,width:f}),T.css({top:v,height:b})},k=function(){i=s.width(),u=s.height(),p=s.prop("scrollWidth"),d=s.prop("scrollHeight"),!l.suppressScrollX&&p>i+l.scrollXMarginOffset?(a=!0,f=X(parseInt(i*i/p,10)),h=parseInt(s.scrollLeft()*(i-f)/(p-i),10)):(a=!1,f=0,h=0,s.scrollLeft(0)),!l.suppressScrollY&&d>u+l.scrollYMarginOffset?(c=!0,b=X(parseInt(u*u/d,10)),v=parseInt(s.scrollTop()*(u-b)/(d-u),10)):(c=!1,b=0,v=0,s.scrollTop(0)),v>=u-b&&(v=u-b),h>=i-f&&(h=i-f),Y()},x=function(){var o,n;w.bind("mousedown"+S,function(e){n=e.pageX,o=w.position().left,g.addClass("in-scrolling"),e.stopPropagation(),e.preventDefault()}),e(document).bind("mousemove"+S,function(e){g.hasClass("in-scrolling")&&(C(o,e.pageX-n),e.stopPropagation(),e.preventDefault())}),e(document).bind("mouseup"+S,function(){g.hasClass("in-scrolling")&&g.removeClass("in-scrolling")}),o=n=null},D=function(){var o,n;T.bind("mousedown"+S,function(e){n=e.pageY,o=T.position().top,m.addClass("in-scrolling"),e.stopPropagation(),e.preventDefault()}),e(document).bind("mousemove"+S,function(e){m.hasClass("in-scrolling")&&(I(o,e.pageY-n),e.stopPropagation(),e.preventDefault())}),e(document).bind("mouseup"+S,function(){m.hasClass("in-scrolling")&&m.removeClass("in-scrolling")}),o=n=null},P=function(e,o){var n=s.scrollTop();if(0===e){if(!c)return!1;if(0===n&&o>0||n>=d-u&&0>o)return!l.wheelPropagation}var t=s.scrollLeft();if(0===o){if(!a)return!1;if(0===t&&0>e||t>=p-i&&e>0)return!l.wheelPropagation}return!0},M=function(){var e=!1;s.bind("mousewheel"+S,function(o,n,t,r){l.useBothWheelAxes?c&&!a?r?s.scrollTop(s.scrollTop()-r*l.wheelSpeed):s.scrollTop(s.scrollTop()+t*l.wheelSpeed):a&&!c&&(t?s.scrollLeft(s.scrollLeft()+t*l.wheelSpeed):s.scrollLeft(s.scrollLeft()-r*l.wheelSpeed)):(s.scrollTop(s.scrollTop()-r*l.wheelSpeed),s.scrollLeft(s.scrollLeft()+t*l.wheelSpeed)),k(),e=P(t,r),e&&o.preventDefault()}),s.bind("MozMousePixelScroll"+S,function(o){e&&o.preventDefault()})},O=function(){var o=!1;s.bind("mouseenter"+S,function(){o=!0}),s.bind("mouseleave"+S,function(){o=!1});var n=!1;e(document).bind("keydown"+S,function(e){if(o){var t=0,r=0;switch(e.which){case 37:t=-3;break;case 38:r=3;break;case 39:t=3;break;case 40:r=-3;break;case 33:r=9;break;case 32:case 34:r=-9;break;case 35:r=-u;break;case 36:r=u;break;default:return}s.scrollTop(s.scrollTop()-r*l.wheelSpeed),s.scrollLeft(s.scrollLeft()+t*l.wheelSpeed),n=P(t,r),n&&e.preventDefault()}})},j=function(){var e=function(e){e.stopPropagation()};T.bind("click"+S,e),m.bind("click"+S,function(e){var o=parseInt(b/2,10),n=e.pageY-m.offset().top-o,t=u-b,r=n/t;0>r?r=0:r>1&&(r=1),s.scrollTop((d-u)*r)}),w.bind("click"+S,e),g.bind("click"+S,function(e){var o=parseInt(f/2,10),n=e.pageX-g.offset().left-o,t=i-f,r=n/t;0>r?r=0:r>1&&(r=1),s.scrollLeft((p-i)*r)})},A=function(){var o=function(e,o){s.scrollTop(s.scrollTop()-o),s.scrollLeft(s.scrollLeft()-e),k()},n={},t=0,r={},l=null,a=!1;e(window).bind("touchstart"+S,function(){a=!0}),e(window).bind("touchend"+S,function(){a=!1}),s.bind("touchstart"+S,function(e){var o=e.originalEvent.targetTouches[0];n.pageX=o.pageX,n.pageY=o.pageY,t=(new Date).getTime(),null!==l&&clearInterval(l),e.stopPropagation()}),s.bind("touchmove"+S,function(e){if(!a&&1===e.originalEvent.targetTouches.length){var l=e.originalEvent.targetTouches[0],s={};s.pageX=l.pageX,s.pageY=l.pageY;var c=s.pageX-n.pageX,i=s.pageY-n.pageY;o(c,i),n=s;var u=(new Date).getTime();r.x=c/(u-t),r.y=i/(u-t),t=u,e.preventDefault()}}),s.bind("touchend"+S,function(){clearInterval(l),l=setInterval(function(){return.01>Math.abs(r.x)&&.01>Math.abs(r.y)?(clearInterval(l),void 0):(o(30*r.x,30*r.y),r.x*=.8,r.y*=.8,void 0)},10)})},E=function(){s.bind("scroll"+S,function(){k()})},W=function(){s.unbind(S),e(window).unbind(S),e(document).unbind(S),s.data("perfect-scrollbar",null),s.data("perfect-scrollbar-update",null),s.data("perfect-scrollbar-destroy",null),w.remove(),T.remove(),g.remove(),m.remove(),w=T=i=u=p=d=f=h=L=b=v=y=null},B=function(o){s.addClass("ie").addClass("ie"+o);var n=function(){var o=function(){e(this).addClass("hover")},n=function(){e(this).removeClass("hover")};s.bind("mouseenter"+S,o).bind("mouseleave"+S,n),g.bind("mouseenter"+S,o).bind("mouseleave"+S,n),m.bind("mouseenter"+S,o).bind("mouseleave"+S,n),w.bind("mouseenter"+S,o).bind("mouseleave"+S,n),T.bind("mouseenter"+S,o).bind("mouseleave"+S,n)},t=function(){Y=function(){w.css({left:h+s.scrollLeft(),bottom:L,width:f}),T.css({top:v+s.scrollTop(),right:y,height:b}),w.hide().show(),T.hide().show()}};6===o&&(n(),t())},K="ontouchstart"in window||window.DocumentTouch&&document instanceof window.DocumentTouch,q=function(){var e=navigator.userAgent.toLowerCase().match(/(msie) ([\w.]+)/);e&&"msie"===e[1]&&B(parseInt(e[2],10)),k(),E(),x(),D(),j(),K&&A(),s.mousewheel&&M(),l.useKeyboard&&O(),s.data("perfect-scrollbar",s),s.data("perfect-scrollbar-update",k),s.data("perfect-scrollbar-destroy",W)};return q(),s})}});