perfect-scrollbar/min/perfect-scrollbar.min.js

4 lines
8.7 KiB
JavaScript
Raw Normal View History

/*! perfect-scrollbar - v0.5.6
* http://noraesae.github.com/perfect-scrollbar/
2014-09-25 02:35:43 +08:00
* Copyright (c) 2014 Hyunje 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";function t(e){return"string"==typeof e?parseInt(e,10):~~e}var o={wheelSpeed:1,wheelPropagation:!1,minScrollbarLength:null,maxScrollbarLength:null,useBothWheelAxes:!1,useKeyboard:!0,suppressScrollX:!1,suppressScrollY:!1,scrollXMarginOffset:0,scrollYMarginOffset:0,includePadding:!1},n=0,r=function(){var e=n++;return function(t){var o=".perfect-scrollbar-"+e;return t===void 0?o:t+o}};e.fn.perfectScrollbar=function(n,l){return this.each(function(){function i(e,o){var n=e+o,r=x-k;W=0>n?0:n>r?r:n;var l=t(W*(C-x)/(x-k));S.scrollTop(l)}function a(e,o){var n=e+o,r=P-E;X=0>n?0:n>r?r:n;var l=t(X*(D-P)/(P-E));S.scrollLeft(l)}function c(e){return L.minScrollbarLength&&(e=Math.max(e,L.minScrollbarLength)),L.maxScrollbarLength&&(e=Math.min(e,L.maxScrollbarLength)),e}function s(){var e={width:P,display:M?"inherit":"none"};e.left=I?S.scrollLeft()+P-D:S.scrollLeft(),q?e.bottom=R-S.scrollTop():e.top=B+S.scrollTop(),K.css(e);var t={top:S.scrollTop(),height:x,display:Y?"inherit":"none"};F?t.right=I?D-S.scrollLeft()-z-Q.outerWidth():z-S.scrollLeft():t.left=I?S.scrollLeft()+2*P-D-G-Q.outerWidth():G+S.scrollLeft(),U.css(t),O.css({left:X,width:E-H}),Q.css({top:W,height:k-J})}function d(){S.removeClass("ps-active-x"),S.removeClass("ps-active-y"),P=L.includePadding?S.innerWidth():S.width(),x=L.includePadding?S.innerHeight():S.height(),D=S.prop("scrollWidth"),C=S.prop("scrollHeight"),!L.suppressScrollX&&D>P+L.scrollXMarginOffset?(M=!0,E=c(t(P*P/D)),X=t(S.scrollLeft()*(P-E)/(D-P))):(M=!1,E=0,X=0,S.scrollLeft(0)),!L.suppressScrollY&&C>x+L.scrollYMarginOffset?(Y=!0,k=c(t(x*x/C)),W=t(S.scrollTop()*(x-k)/(C-x))):(Y=!1,k=0,W=0,S.scrollTop(0)),X>=P-E&&(X=P-E),W>=x-k&&(W=x-k),s(),M&&S.addClass("ps-active-x"),Y&&S.addClass("ps-active-y")}function u(){var t,o,n=!1;O.bind(j("mousedown"),function(e){o=e.pageX,t=O.position().left,K.addClass("in-scrolling"),n=!0,e.stopPropagation(),e.preventDefault()}),e(A).bind(j("mousemove"),function(e){n&&(a(t,e.pageX-o),d(),e.stopPropagation(),e.preventDefault())}),e(A).bind(j("mouseup"),function(){n&&(n=!1,K.removeClass("in-scrolling"))}),t=o=null}function p(){var t,o,n=!1;Q.bind(j("mousedown"),function(e){o=e.pageY,t=Q.position().top,n=!0,U.addClass("in-scrolling"),e.stopPropagation(),e.preventDefault()}),e(A).bind(j("mousemove"),function(e){n&&(i(t,e.pageY-o),d(),e.stopPropagation(),e.preventDefault())}),e(A).bind(j("mouseup"),function(){n&&(n=!1,U.removeClass("in-scrolling"))}),t=o=null}function f(e,t){var o=S.scrollTop();if(0===e){if(!Y)return!1;if(0===o&&t>0||o>=C-x&&0>t)return!L.wheelPropagation}var n=S.scrollLeft();if(0===t){if(!M)return!1;if(0===n&&0>e||n>=D-P&&e>0)return!L.wheelPropagation}return!0}function v(){function e(e){var t=e.originalEvent.deltaX,o=-1*e.originalEvent.deltaY;return(t===void 0||o===void 0)&&(t=-1*e.originalEvent.wheelDeltaX/6,o=e.originalEvent.wheelDeltaY/6),e.originalEvent.deltaMode&&1===e.originalEvent.deltaMode&&(t*=10,o*=10),t!==t&&o!==o&&(t=0,o=e.originalEvent.wheelDelta),[t,o]}function t(t){var n=e(t),r=n[0],l=n[1];o=!1,L.useBothWheelAxes?Y&&!M?(l?S.scrollTop(S.scrollTop()-l*L.wheelSpeed):S.scrollTop(S.scrollTop()+r*L.wheelSpeed),o=!0):M&&!Y&&(r?S.scrollLeft(S.scrollLeft()+r*L.wheelSpeed):S.scrollLeft(S.scrollLeft()-l*L.wheelSpeed),o=!0):(S.scrollTop(S.scrollTop()-l*L.wheelSpeed),S.scrollLeft(S.scrollLeft()+r*L.wheelSpeed)),d(),o=o||f(r,l),o&&(t.stopPropagation(),t.preventDefault())}var o=!1;window.onwheel!==void 0?S.bind(j("wheel"),t):window.onmousewheel!==void 0&&S.bind(j("mousewheel"),t)}function g(){var t=!1;S.bind(j("mouseenter"),function(){t=!0}),S.bind(j("mouseleave"),function(){t=!1});var o=!1;e(A).bind(j("keydown"),function(n){if((!n.isDefaultPrevented||!n.isDefaultPrevented())&&t){for(var r=document.activeElement?document.activeElement:A.activeElement;r.shadowRoot;)r=r.shadowRoot.activeElement;if(!e(r).is(":input,[contenteditable]")){var l=0,i=0;switch(n.which){case 37:l=-30;break;case 38:i=30;break;case 39:l=30