4 lines
7.3 KiB
JavaScript
4 lines
7.3 KiB
JavaScript
|
/*! perfect-scrollbar - v0.4.6
|
||
|
* http://noraesae.github.com/perfect-scrollbar/
|
||
|
* Copyright (c) 2013 HyeonJe Jun; Licensed MIT */
|
||
|
"use strict";(function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)})(function(e){var r={wheelSpeed:10,wheelPropagation:!1,minScrollbarLength:null,useBothWheelAxes:!1,useKeyboard:!0,suppressScrollX:!1,suppressScrollY:!1,scrollXMarginOffset:0,scrollYMarginOffset:0};e.fn.perfectScrollbar=function(o,l){return this.each(function(){var t=e.extend(!0,{},r),s=e(this);if("object"==typeof o?e.extend(!0,t,o):l=o,"update"===l)return s.data("perfect-scrollbar-update")&&s.data("perfect-scrollbar-update")(),s;if("destroy"===l)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 n,c,a,i,p,f,u,d,b,h,v=e("<div class='ps-scrollbar-x-rail'></div>").appendTo(s),g=e("<div class='ps-scrollbar-y-rail'></div>").appendTo(s),m=e("<div class='ps-scrollbar-x'></div>").appendTo(v),w=e("<div class='ps-scrollbar-y'></div>").appendTo(g),T=parseInt(v.css("bottom"),10),L=parseInt(g.css("right"),10),y=function(){var e=parseInt(h*(f-i)/(i-b),10);s.scrollTop(e),v.css({bottom:T-e})},S=function(){var e=parseInt(d*(p-a)/(a-u),10);s.scrollLeft(e),g.css({right:L-e})},I=function(e){return t.minScrollbarLength&&(e=Math.max(e,t.minScrollbarLength)),e},C=function(){v.css({left:s.scrollLeft(),bottom:T-s.scrollTop(),width:a,display:t.suppressScrollX?"none":"inherit"}),g.css({top:s.scrollTop(),right:L-s.scrollLeft(),height:i,display:t.suppressScrollY?"none":"inherit"}),m.css({left:d,width:u}),w.css({top:h,height:b})},X=function(){a=s.width(),i=s.height(),p=s.prop("scrollWidth"),f=s.prop("scrollHeight"),!t.suppressScrollX&&p>a+t.scrollXMarginOffset?(n=!0,u=I(parseInt(a*a/p,10)),d=parseInt(s.scrollLeft()*(a-u)/(p-a),10)):(n=!1,u=0,d=0,s.scrollLeft(0)),!t.suppressScrollY&&f>i+t.scrollYMarginOffset?(c=!0,b=I(parseInt(i*i/f,10)),h=parseInt(s.scrollTop()*(i-b)/(f-i),10)):(c=!1,b=0,h=0,s.scrollTop(0)),h>=i-b&&(h=i-b),d>=a-u&&(d=a-u),C()},Y=function(e,r){var o=e+r,l=a-u;d=0>o?0:o>l?l:o,v.css({left:s.scrollLeft()}),m.css({left:d})},x=function(e,r){var o=e+r,l=i-b;h=0>o?0:o>l?l:o,g.css({top:s.scrollTop()}),w.css({top:h})},D=function(){var r,o;m.bind("mousedown.perfect-scrollbar",function(e){o=e.pageX,r=m.position().left,v.addClass("in-scrolling"),e.stopPropagation(),e.preventDefault()}),e(document).bind("mousemove.perfect-scrollbar",function(e){v.hasClass("in-scrolling")&&(S(),Y(r,e.pageX-o),e.stopPropagation(),e.preventDefault())}),e(document).bind("mouseup.perfect-scrollbar",function(){v.hasClass("in-scrolling")&&v.removeClass("in-scrolling")}),r=o=null},P=function(){var r,o;w.bind("mousedown.perfect-scrollbar",function(e){o=e.pageY,r=w.position().top,g.addClass("in-scrolling"),e.stopPropagation(),e.preventDefault()}),e(document).bind("mousemove.perfect-scrollbar",function(e){g.hasClass("in-scrolling")&&(y(),x(r,e.pageY-o),e.stopPropagation(),e.preventDefault())}),e(document).bind("mouseup.perfect-scrollbar",function(){g.hasClass("in-scrolling")&&g.removeClass("in-scrolling")}),r=o=null},k=function(){var e=function(e,r){var o=s.scrollTop();if(0===o&&r>0&&0===e)return!t.wheelPropagation;if(o>=f-i&&0>r&&0===e)return!t.wheelPropagation;var l=s.scrollLeft();return 0===l&&0>e&&0===r?!t.wheelPropagation:l>=p-a&&e>0&&0===r?!t.wheelPropagation:!0},r=!1;s.bind("mousewheel.perfect-scrollbar",function(o,l,a,i){t.useBothWheelAxes?c&&!n?i?s.scrollTop(s.scrollTop()-i*t.wheelSpeed):s.scrollTop(s.scrollTop()+a*t.wheelSpeed):n&&!c&&(a?s.scrollLeft(s.scrollLeft()+a*t.wheelSpeed):s.scrollLeft(s.scrollLeft()-i*t.wheelSpeed)):(s.scrollTop(s.scrollTop()-i*t.wheelSpeed),s.scrollLeft(s.scrollLeft()+a*t.wheelSpeed)),X(),r=e(a,i),r&&o.preventDefault()}),s.bind("MozMousePixelScroll.perfect-scrollbar",function(e){r&&e.preventDefault()})},M=function(){var r=function(e,r){var o=s.scrollTop();if(0===o&&r>0&&0===e)return!1;if(o>=f-i&&0>r&&0===e)return!1;var l=s.scrollLeft();return 0===l&&0>e&&0===r?!1:l>=p-a&&e>0&&0===r?!1:!0},o=!1;s.bind("mouseenter.perfect-scrollbar",function(){o=!0}),s.bind("mouseleave.perfect-scrollbar",function(){o=!1});var l=!1;e(do
|