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