Created
April 6, 2013 08:13
-
-
Save myndzi/5325369 to your computer and use it in GitHub Desktop.
LearnBoost Antiscroll run through Closure Compiler's advanced optimizations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var f=null,k=!1; | |
(function(b){function l(a,e){this.b=b(a);this.e=e||{};this.g=k!==this.e.x||this.e.forceHorizontal;this.h=k!==this.e.y||this.e.forceVertical;this.i=k!==this.e.autoHide;this.f=void 0==this.e.padding?2:this.e.padding;this.a=this.b.find(".antiscroll-inner");this.a.css({width:"+="+(this.h?g():0),height:"+="+(this.g?g():0)});var d={};this.g&&(d.width="+="+g());this.h&&(d.height="+="+g());this.a.css(d);this.k()}function c(a){this.a=a;this.a.b.append(this.b);this.c=this.a.a.get(0);this.d=this.f=this.e=k; | |
this.a.b.mouseenter(b.proxy(this,"z"));this.a.b.mouseleave(b.proxy(this,"y"));this.b.mousedown(b.proxy(this,"x"));this.l=b.proxy(this,"u");this.a.a.scroll(this.l);this.k=b.proxy(this,"w");this.a.a.bind("mousewheel",this.k);a=this.a.e.initialDisplay;a!==k&&(this.h(),this.a.i&&(this.g=setTimeout(b.proxy(this,"hide"),parseInt(a,10)||3E3)))}function n(a,e){function d(){}d.prototype=e.prototype;a.prototype=new d}function g(){if(void 0===m){var a=b('<div class="antiscroll-inner" style="width:50px;height:50px;overflow-y:scroll;position:absolute;top:-200px;left:-200px;"><div style="height:100px;width:100%"></div>'); | |
b("body").append(a);var e=b(a).innerWidth(),d=b("div",a).innerWidth();b(a).remove();m=e-d}return m}b.fn.antiscroll=function(a){return this.each(function(){b(this).data("$.A")&&b(this).data("$.A").j();b(this).data("$.A",new b.b(this,a))})};b.b=l;l.prototype.k=function(){var a=this.a.get(0).scrollWidth>this.b.width()+(this.h?g():0),e=this.a.get(0).scrollHeight>this.b.height()+(this.g?g():0);this.g&&(!this.c&&a?this.c=new c.b(this):this.c&&!a?(this.c.j(),this.c=f):this.c&&this.c.update());this.h&&(!this.d&& | |
e?this.d=new c.a(this):this.d&&!e?(this.d.j(),this.d=f):this.d&&this.d.update())};l.prototype.j=function(){this.c&&(this.c.j(),this.c=f);this.d&&(this.d.j(),this.d=f);return this};c.prototype.j=function(){this.b.remove();this.a.a.unbind("scroll",this.l);this.a.a.unbind("mousewheel",this.k);return this};c.prototype.z=function(){this.f=!0;this.h()};c.prototype.y=function(){this.f=k;this.e||this.a.i&&this.i()};c.prototype.u=function(){this.d||(this.h(),!this.f&&!this.e&&this.a.i&&(this.g=setTimeout(b.proxy(this, | |
"hide"),1500)));this.update()};c.prototype.x=function(a){a.preventDefault();this.e=!0;this.n=a.pageY-parseInt(this.b.css("top"),10);this.m=a.pageX-parseInt(this.b.css("left"),10);this.b[0].ownerDocument.onselectstart=function(){return k};var e=b.proxy(this,"v"),d=this;b(this.b[0].ownerDocument).mousemove(e).mouseup(function(){d.e=k;this.onselectstart=f;b(this).unbind("mousemove",e);d.f||d.i()})};c.prototype.h=function(){!this.d&&this.update()&&(this.b.addClass("antiscroll-scrollbar-shown"),this.g&& | |
(clearTimeout(this.g),this.g=f),this.d=!0)};c.prototype.i=function(){this.a.i!==k&&this.d&&(this.b.removeClass("antiscroll-scrollbar-shown"),this.d=k)};c.b=function(a){this.b=b('<div class="antiscroll-scrollbar antiscroll-scrollbar-horizontal">');c.call(this,a)};n(c.b,c);c.b.prototype.update=function(){var a=this.a.b.width(),e=a-2*this.a.f,d=this.a.a.get(0);this.b.css("width",e*a/d.scrollWidth).css("left",e*d.scrollLeft/d.scrollWidth);return a<d.scrollWidth};c.b.prototype.v=function(a){var e=this.a.b.width()- | |
2*this.a.f,d=a.pageX-this.m;a=this.b.width();var b=this.a.a.get(0),d=Math.min(Math.max(d,0),e-a);b.scrollLeft=(b.scrollWidth-this.a.b.width())*d/(e-a)};c.b.prototype.w=function(a,b,d){if(0>d&&0==this.a.a.get(0).scrollLeft||0<d&&this.c.scrollLeft+Math.ceil(this.a.b.width())==this.c.scrollWidth)return a.preventDefault(),k};c.a=function(a){this.b=b('<div class="antiscroll-scrollbar antiscroll-scrollbar-vertical">');c.call(this,a)};n(c.a,c);c.a.prototype.update=function(){var a=this.a.b.height(),b=a- | |
2*this.a.f,d=this.c,c=b*a/d.scrollHeight,c=20>c?20:c,h=b*d.scrollTop/d.scrollHeight;h+c>b&&(h=h-(h+c-b)-3);this.b.css("height",c).css("top",h);return a<d.scrollHeight};c.a.prototype.v=function(a){var b=this.a.b.height(),d=b-2*this.a.f,c=a.pageY-this.n;a=this.b.height();var h=this.c,c=Math.min(Math.max(c,0),d-a);h.scrollTop=(h.scrollHeight-b)*c/(d-a)};c.a.prototype.w=function(a,b,c,g){if(0<g&&0==this.c.scrollTop||0>g&&this.c.scrollTop+Math.ceil(this.a.b.height())==this.c.scrollHeight)return a.preventDefault(), | |
k};var m})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment