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

4 lines
7.5 KiB
JavaScript
Raw Permalink Normal View History

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