2014-07-11 21:33:40 +08:00
|
|
|
!function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?a(require("jquery")):a(jQuery)}(function(a){"use strict";var b={wheelSpeed:10,wheelPropagation:!1,minScrollbarLength:null,useBothWheelAxes:!1,useKeyboard:!0,suppressScrollX:!1,suppressScrollY:!1,scrollXMarginOffset:0,scrollYMarginOffset:0,includePadding:!1},c=function(){var a=0;return function(){var b=a;return a+=1,".perfect-scrollbar-"+b}}();a.fn.perfectScrollbar=function(d,e){return this.each(function(){var f=a.extend(!0,{},b),g=a(this);if("object"==typeof d?a.extend(!0,f,d):e=d,"update"===e)return g.data("perfect-scrollbar-update")&&g.data("perfect-scrollbar-update")(),g;if("destroy"===e)return g.data("perfect-scrollbar-destroy")&&g.data("perfect-scrollbar-destroy")(),g;if(g.data("perfect-scrollbar"))return g.data("perfect-scrollbar");g.addClass("ps-container");var l,m,n,o,p,q,r,s,w,x,h=a("<div class='ps-scrollbar-x-rail'></div>").appendTo(g),i=a("<div class='ps-scrollbar-y-rail'></div>").appendTo(g),j=a("<div class='ps-scrollbar-x'></div>").appendTo(h),k=a("<div class='ps-scrollbar-y'></div>").appendTo(i),t=parseInt(h.css("bottom"),10),u=t===t,v=u?null:parseInt(h.css("top"),10),y=parseInt(i.css("right"),10),z=y===y,A=z?null:parseInt(i.css("left"),10),B="rtl"===g.css("direction"),C=c(),D=parseInt(h.css("borderLeftWidth"),10)+parseInt(h.css("borderRightWidth"),10),E=parseInt(h.css("borderTopWidth"),10)+parseInt(h.css("borderBottomWidth"),10),F=function(a,b){var c=a+b,d=o-w;x=0>c?0:c>d?d:c;var e=parseInt(x*(q-o)/(o-w),10);g.scrollTop(e),u?h.css({bottom:t-e}):h.css({top:v+e})},G=function(a,b){var c=a+b,d=n-r;s=0>c?0:c>d?d:c;var e=parseInt(s*(p-n)/(n-r),10);g.scrollLeft(e),z?i.css({right:y-e}):i.css({left:A+e})},H=function(a){return f.minScrollbarLength&&(a=Math.max(a,f.minScrollbarLength)),a},I=function(){var a={width:n,display:l?"inherit":"none"};a.left=B?g.scrollLeft()+n-p:g.scrollLeft(),u?a.bottom=t-g.scrollTop():a.top=v+g.scrollTop(),h.css(a);var b={top:g.scrollTop(),height:o,display:m?"inherit":"none"};z?b.right=B?p-g.scrollLeft()-y-k.outerWidth():y-g.scrollLeft():b.left=B?g.scrollLeft()+2*n-p-A-k.outerWidth():A+g.scrollLeft(),i.css(b),j.css({left:s,width:r-D}),k.css({top:x,height:w-E})},J=function(){n=f.includePadding?g.innerWidth():g.width(),o=f.includePadding?g.innerHeight():g.height(),p=g.prop("scrollWidth"),q=g.prop("scrollHeight"),!f.suppressScrollX&&n+f.scrollXMarginOffset<p?(l=!0,r=H(parseInt(n*n/p,10)),s=parseInt(g.scrollLeft()*(n-r)/(p-n),10)):(l=!1,r=0,s=0,g.scrollLeft(0)),!f.suppressScrollY&&o+f.scrollYMarginOffset<q?(m=!0,w=H(parseInt(o*o/q,10)),x=parseInt(g.scrollTop()*(o-w)/(q-o),10)):(m=!1,w=0,x=0,g.scrollTop(0)),x>=o-w&&(x=o-w),s>=n-r&&(s=n-r),I()},K=function(){var b,c;j.bind("mousedown"+C,function(a){c=a.pageX,b=j.position().left,h.addClass("in-scrolling"),a.stopPropagation(),a.preventDefault()}),a(document).bind("mousemove"+C,function(a){h.hasClass("in-scrolling")&&(G(b,a.pageX-c),a.stopPropagation(),a.preventDefault())}),a(document).bind("mouseup"+C,function(){h.hasClass("in-scrolling")&&h.removeClass("in-scrolling")}),b=c=null},L=function(){var b,c;k.bind("mousedown"+C,function(a){c=a.pageY,b=k.position().top,i.addClass("in-scrolling"),a.stopPropagation(),a.preventDefault()}),a(document).bind("mousemove"+C,function(a){i.hasClass("in-scrolling")&&(F(b,a.pageY-c),a.stopPropagation(),a.preventDefault())}),a(document).bind("mouseup"+C,function(){i.hasClass("in-scrolling")&&i.removeClass("in-scrolling")}),b=c=null},M=function(a,b){var c=g.scrollTop();if(0===a){if(!m)return!1;if(0===c&&b>0||c>=q-o&&0>b)return!f.wheelPropagation}var d=g.scrollLeft();if(0===b){if(!l)return!1;if(0===d&&0>a||d>=p-n&&a>0)return!f.wheelPropagation}return!0},N=function(){f.wheelSpeed/=10;var a=!1;g.bind("mousewheel"+C,function(b,c,d,e){var h=b.deltaX*b.deltaFactor||d,i=b.deltaY*b.deltaFactor||e;a=!1,f.useBothWheelAxes?m&&!l?(i?g.scrollTop(g.scrollTop()-i*f.wheelSpeed):g.scrollTop(g.scrollTop()+h*f.wheelSpeed),a=!0):l&&!m&&(h?g.scrollLeft(g.scrollLeft()+h*f.wheelSpeed):g.scrollLeft(g.scrollLeft()-i*f.wheelSpeed),a=!0
|