-
Notifications
You must be signed in to change notification settings - Fork 4
/
baron.min.js
2 lines (2 loc) · 4.19 KB
/
baron.min.js
1
2
/*! baron 22-04-2013 */
(function(e,t){"use strict";function o(){}function s(r){function f(o){s.init=function(s){function n(){s.barOnCls&&(B[A.client]<B[A.scrollSize]?d(B).addClass(s.barOnCls):d(B).removeClass(s.barOnCls))}function i(e){var t=s.barMinSize||20;e>0&&t>e&&(e=t),W&&d(W).css(A.size,parseInt(e)+"px")}function r(e){W&&d(W).css(A.pos,parseInt(e)+"px")}function l(){return E[A.client]-k-W[A.offset]}function c(e){return e*l()+k}function f(e){return(e-k)/l()}function a(e){return e["client"+A.x]||(((e.originalEvent||e).touches||{})[0]||{})["page"+A.x]}function p(){return!1}function v(e){u(document,"selectpos selectstart",p,e?"off":"on")}function C(e){try{D=document.createEvent("WheelEvent"),D.initWebKitWheelEvent(e.originalEvent.wheelDeltaX,e.originalEvent.wheelDeltaY),B.dispatchEvent(D),e.preventDefault()}catch(e){}}function m(e,o){(s.viewMinSize||0)>w&&(o=t),o!==t?(o+="px",d(z[e]).css(A.pos,o).addClass(y)):d(z[e]).css(A.pos,"").removeClass(y)}function b(e){if(d(B).css(A.crossSize,B.parentNode[A.crossClient]+B[A.crossOffset]-B[A.crossClient]+"px"),w=B[A.client],e&&(S=[]),L=[],F=[],z=h(s.header,B)){for(D=0;z.length>D;D++)F[D]=F[D-1]||0,z[D-1]&&(F[D]+=z[D-1][A.offset]),H={},H[A.size]=z[D][A.offset],d(z[D].parentNode).css(H),H={},H[A.crossSize]=z[D].parentNode[A.crossClient],d(z[D]).css(H),w-=z[D][A.offset],S[D]=z[D].parentNode[A.offsetPos],0==D&&0==S[D]||!e||(u(z[D],"mousewheel",C,"off"),u(z[D],"mousewheel",C));s.trackSmartLim&&(E!=B?(H={},H[A.pos]=z[0].parentNode[A.offset],d(E).css(H)):k=z[0].parentNode[A.offset])}}function g(){var e,o,n,l,f;if(n=(E[A.client]-k)*B[A.client]/B[A.scrollSize],o!=n&&(i(n),o=n),e=-(B["page"+A.x+"Offset"]||B[A.scroll]),N=c(-e/(B[A.scrollSize]-B[A.client])),r(N),z){var a;for(D=0;z.length>D;D++)f=0,S[D]+e<F[D]+P?(f=1,l=F[D]):S[D]+e>F[D]+w-P?(f=2,l=F[D]+w):(f=3,l=t),f!=L[D]&&(m(D,l),L[D]=f,a=!0);if(a)for(D=0;z.length>D;D++)L[D]!=L[D+1]&&1==L[D]&&s.hBeforeFixCls?d(z[D]).addClass(s.hBeforeFixCls).removeClass(s.hAfterFixCls+""):L[D]!=L[D-1]&&2==L[D]&&s.hAfterFixCls?d(z[D]).addClass(s.hAfterFixCls).removeClass(s.hBeforeFixCls+""):d(z[D]).removeClass(s.hBeforeFixCls+"").removeClass(s.hAfterFixCls+"")}}function x(){clearTimeout(O),O=setTimeout(function(){b(),g(),n()},200)}var z,w,S,F,O,W,E,N,y,A,B,T,_,H,P,D,L=[],k=0;return B=s.scroller,this._barOn=n,this._uView=b,this._uBar=g,s.bar&&s.bar[0].nodeType&&(W=s.bar[0]),W||(s.bar?W=h(s.bar,B)[0]:(W=h("*",B),W=W[W.length-1])),W?(E=h(s.track,B)[0],E=E||W.parentNode):E=B,B.setAttribute("data-baron","inited"),A=o.dir,P=s.fixRadius||0,y=s.hFixCls,u(B,"scroll",g),u(W,"touchstart mousedown",function(e){e.preventDefault(),v(),T=1}),u(document,"mouseup blur touchend",function(){v(1),T=0}),u(document,"touchstart mousedown",function(e){2!=e.button&&(_=a(e)-N)}),u(document,"mousemove touchmove",function(e){T&&(B[A.scroll]=f(a(e)-_)*(B[A.scrollSize]-B[A.client]))}),u(e,"resize",x),u(B,"sizeChange",x),u(W,"mousewheel",C),this},s.init.prototype.update=function(){this._uView(1),this._uBar(),this._barOn()};for(var n=0,i=0;p.length>i;i++)p[i].getAttribute("data-baron")?u(p[i],"sizeChange",t,"trigger"):(o.scroller=p[i],o.v!==!1&&(o.dir=c.v,o.bar=o.vbar||o.bar,this[n++]=new s.init(o)),o.h&&(o.dir=c.h,o.bar=o.hbar,this[n++]=new s.init(o)));return this}var a,u,h,d,p;return n=function(e){o(e,r)},r=r||{},h=r.selector||l,h||n(1),u=r.event||function(e,t,o,s){l(e)[s||"on"](t,o)},r.event||l||n(2),d=r.dom||l,d||n(3),p=h(r.scroller||this),p[0]||(p=[p]),p[0].nodeType||n(10),f.prototype.u=function(){for(var e=-1;this[++e];)this[e].update()},a=new f(r),a.u(),i.push(a),a}var n,i=[],r=e.baron,l=e.jQuery,c={v:{x:"Y",pos:"top",crossPos:"left",size:"height",crossSize:"width",client:"clientHeight",crossClient:"clientWidth",offset:"offsetHeight",crossOffset:"offsetWidth",offsetPos:"offsetTop",scroll:"scrollTop",scrollSize:"scrollHeight"},h:{x:"X",pos:"left",crossPos:"top",size:"width",crossSize:"height",client:"clientWidth",crossClient:"clientHeight",offset:"offsetWidth",crossOffset:"offsetHeight",offsetPos:"offsetLeft",scroll:"scrollLeft",scrollSize:"scrollWidth"}};e&&(s.u=function(){for(var e=0;i.length>e;e++)i[e].u()},s.noConflict=function(){return e.baron=r,s},s.version="0.5.1",l&&l.fn&&(l.fn.baron=s),e.baron=s,e.module&&module.exports&&(module.exports=s.noConflict()))})(window);