perfect-scrollbar/min/perfect-scrollbar-0.4.4.min.js
Hyunje Alex Jun 58261f2ace Release 0.4.4.
Patch notes
1. Bug fixes.
2013-09-09 10:44:48 +09:00

4 lines
5.3 KiB
JavaScript

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