perfect-scrollbar/min/perfect-scrollbar.min.js
Hyunje Alex Jun 9be4a1a85f Minify source files with the new build system.
From now, the build can be done with 'grunt build'.
2013-06-16 00:30:43 +09:00

4 lines
4.1 KiB
JavaScript

/*! perfect-scrollbar - v0.3.4
* http://noraesae.github.com/perfect-scrollbar/
* Copyright (c) 2013 HyeonJe Jun; Licensed MIT */
(function(e){var t={wheelSpeed:10,wheelPropagation:!1};e.fn.perfectScrollbar=function(r,o){return this.each(function(){var l=e.extend(!0,{},t);if("object"==typeof r?e.extend(!0,l,r):o=r,"update"===o)return e(this).data("perfect-scrollbar-update")&&e(this).data("perfect-scrollbar-update")(),e(this);if("destroy"===o)return e(this).data("perfect-scrollbar-destroy")&&e(this).data("perfect-scrollbar-destroy")(),e(this);if(e(this).data("perfect-scrollbar"))return e(this).data("perfect-scrollbar");var n,a,s,c,i,p,f,u,d=e(this).addClass("ps-container"),g=e("<div class='ps-scrollbar-x'></div>").appendTo(d),h=e("<div class='ps-scrollbar-y'></div>").appendTo(d),v=parseInt(g.css("bottom"),10),b=parseInt(h.css("right"),10),m=function(){var e=parseInt(u*c/a,10);d.scrollTop(e),g.css({bottom:v-e})},w=function(){var e=parseInt(p*s/n,10);d.scrollLeft(e),h.css({right:b-e})},T=function(){n=d.width(),a=d.height(),s=d.prop("scrollWidth"),c=d.prop("scrollHeight"),s>n?(i=parseInt(n*n/s,10),p=parseInt(d.scrollLeft()*n/s,10)):(i=0,p=0,d.scrollLeft(0)),c>a?(f=parseInt(a*a/c,10),u=parseInt(d.scrollTop()*a/c,10)):(f=0,u=0,d.scrollTop(0)),u>=a-f&&(u=a-f),p>=n-i&&(p=n-i),g.css({left:p+d.scrollLeft(),bottom:v-d.scrollTop(),width:i}),h.css({top:u+d.scrollTop(),right:b-d.scrollLeft(),height:f})},y=function(e,t){var r=e+t,o=n-i;p=0>r?0:r>o?o:r,g.css({left:p+d.scrollLeft()})},P=function(e,t){var r=e+t,o=a-f;u=0>r?0:r>o?o:r,h.css({top:u+d.scrollTop()})},I=function(){var t,r;g.bind("mousedown.perfect-scroll",function(e){r=e.pageX,t=g.position().left,g.addClass("in-scrolling"),e.stopPropagation(),e.preventDefault()}),e(document).bind("mousemove.perfect-scroll",function(e){g.hasClass("in-scrolling")&&(w(),y(t,e.pageX-r),e.stopPropagation(),e.preventDefault())}),e(document).bind("mouseup.perfect-scroll",function(){g.hasClass("in-scrolling")&&g.removeClass("in-scrolling")})},L=function(){var t,r;h.bind("mousedown.perfect-scroll",function(e){r=e.pageY,t=h.position().top,h.addClass("in-scrolling"),e.stopPropagation(),e.preventDefault()}),e(document).bind("mousemove.perfect-scroll",function(e){h.hasClass("in-scrolling")&&(m(),P(t,e.pageY-r),e.stopPropagation(),e.preventDefault())}),e(document).bind("mouseup.perfect-scroll",function(){h.hasClass("in-scrolling")&&h.removeClass("in-scrolling")})},C=function(){var e=function(e,t){var r=d.scrollTop();if(0===r&&t>0&&0===e)return!l.wheelPropagation;if(r>=c-a&&0>t&&0===e)return!l.wheelPropagation;var o=d.scrollLeft();return 0===o&&0>e&&0===t?!l.wheelPropagation:o>=s-n&&e>0&&0===t?!l.wheelPropagation:!0};d.bind("mousewheel.perfect-scroll",function(t,r,o,n){d.scrollTop(d.scrollTop()-n*l.wheelSpeed),d.scrollLeft(d.scrollLeft()+o*l.wheelSpeed),T(),e(o,n)&&t.preventDefault()})},D=function(){var t=function(e,t){d.scrollTop(d.scrollTop()-t),d.scrollLeft(d.scrollLeft()-e),T()},r={},o=0,l={},n=null,a=!1;e(window).bind("touchstart.perfect-scroll",function(){a=!0}),e(window).bind("touchend.perfect-scroll",function(){a=!1}),d.bind("touchstart.perfect-scroll",function(e){var t=e.originalEvent.targetTouches[0];r.pageX=t.pageX,r.pageY=t.pageY,o=(new Date).getTime(),null!==n&&clearInterval(n),e.stopPropagation()}),d.bind("touchmove.perfect-scroll",function(e){if(!a&&1===e.originalEvent.targetTouches.length){var n=e.originalEvent.targetTouches[0],s={};s.pageX=n.pageX,s.pageY=n.pageY;var c=s.pageX-r.pageX,i=s.pageY-r.pageY;t(c,i),r=s;var p=(new Date).getTime();l.x=c/(p-o),l.y=i/(p-o),o=p,e.preventDefault()}}),d.bind("touchend.perfect-scroll",function(){n=setInterval(function(){return.01>Math.abs(l.x)&&.01>Math.abs(l.y)?(clearInterval(n),void 0):(t(30*l.x,30*l.y),l.x*=.8,l.y*=.8,void 0)},10)})},X=function(){g.remove(),h.remove(),d.unbind(".perfect-scroll"),e(window).unbind(".perfect-scroll"),d.data("perfect-scrollbar",null),d.data("perfect-scrollbar-update",null),d.data("perfect-scrollbar-destroy",null)},Y=/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent),x=function(){T(),I(),L(),Y&&D(),d.mousewheel&&C(),d.data("perfect-scrollbar",d),d.data("perfect-scrollbar-update",T),d.data("perfect-scrollbar-destroy",X)};return x(),d})}})(jQuery);