-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvlv.min.js
More file actions
1 lines (1 loc) · 3.63 KB
/
Copy pathvlv.min.js
File metadata and controls
1 lines (1 loc) · 3.63 KB
1
function jsvlv(e,n,t,o){function i(e,n){O||o.onSelectRow(e,n)}function l(e,n){n.addEventListener("click",function(){i(e,n)},!1)}function r(){var e;Math.abs(Y)<2?(T+=Y,Y=0):(e=Math.round(.6*Y),T+=e,Y-=e)}function u(){var e,t,o;if(r(),0>T)for(M.style.top=T+"px",e=J+1;n-T-N>0;){if(!(K>e)){N>n?(T=n-N,M.style.top=T+"px"):(M.style.top="0px",T=0);break}t=P[e-1].index+1,x(t),e++}else T>0&&(T=0,Y=0,M.style.top="0px");o=-T/(V-n),W&&W.set(0>o?0:o>1?1:o),0!=Y&&requestAnimationFrame(u)}function c(e){Y+=(V-n)*-e-T,requestAnimationFrame(u)}function a(e){var n=e.wheelDeltaY||e.wheelDelta||-e.detail;e.preventDefault(),O||(e.stopPropagation(),w(),Y+=n,requestAnimationFrame(u))}function s(){"object"==typeof document.onmousewheel&&document.body.addEventListener("mousewheel",a,!0)}function d(){"object"==typeof document.onmousewheel&&document.body.removeEventListener("mousewheel",a,!0)}function f(e){O||(W&&W.enable(),e.preventDefault())}function m(e){W&&W.disable(),e.preventDefault()}function v(e){var n=!1;if(!O){switch(e.keyCode){case D:p(F),n=!0;break;case E:p(C),n=!0;break;case k:case A:-1!=Q&&(o.onSelectRow(P[Q].index,P[Q].element),n=!0)}n&&(e.preventDefault(),e.stopPropagation())}}function p(e){var n,t;0!=K&&(1==K?(Q=0,o.onFocusRow(P[Q].index,P[Q].element)):-1==Q?(Q=g(),o.onFocusRow(P[Q].index,P[Q].element)):(n=Q+e,n>=0&&K>n&&(e==C&&n>J&&(t=P[J].index+1,x(n)),o.onBlurRow(P[Q].index,P[Q].element),b(n),o.onFocusRow(P[n].index,P[n].element),Q=n)))}function w(){-1!=Q&&(o.onBlurRow(P[Q].index,P[Q].element),Q=-1)}function g(){for(var e=-T,n=0,t=0;t<P.length&&!(n>=e);t++)n+=P[t].height;return t}function b(e){for(var t=0,o=0,i=0;i<P.length&&(o=P[i].height,i!=e);i++)t+=o;-T>t?(Y+=-(T+t),requestAnimationFrame(u)):o+t>n-T&&(Y-=t+o-n+T,requestAnimationFrame(u))}function x(e){var n,o=t.contentForRowAtIndex(e);M.appendChild(o),n=$(o).outerHeight(!0),N+=n,P.push({index:e,element:o,height:n}),l(e,o),J=e,U=(U*e+n)/(e+1),V=U*K}function R(){for(var e=0;n>N&&K>e;)x(e),e++;V>n&&(W=new jsvlvscrollbar(c),L.appendChild(W.getElement()),W.show())}function y(){for(w();M.firstChild;)M.removeChild(M.firstChild);W&&W.hide(),M.style.top="0px",P=[],z=0,J=-1,N=0,T=0,K=t?t.numberOfRows():0}var F=-1,C=1,D=38,E=40,k=13,A=32,H=this,I="vlv"+Math.round(1e6*Math.random()),j='<div id="<%= id %>" class="vlv-container" style="width:<%=width %>px;height:<%=height %>px;"></div>',q=$(_.template(j,{id:I,width:e,height:n})),L=q[0],S=null,B=$('<div class="vlv-content"></div>'),M=B[0],O=!1,P=[],z=0,J=-1,N=0,T=0,Y=0,G=!1,K=t?t.numberOfRows():0,Q=-1,U=0,V=0,W=null;return o=o||{},o.onSelectRow=o.onSelectRow||function(){},o.onFocusRow=o.onFocusRow||function(){},o.onBlurRow=o.onBlurRow||function(){},scrollInfoDelegate={},scrollInfoDelegate.scrollHeight=function(){return 5e3},scrollInfoDelegate.clientHeight=function(){return 300},H.getElement=function(){return L},H.show=function(e){L.appendChild(M),q.bind("mouseenter",f),q.bind("mouseleave",m),s(),document.addEventListener("keydown",v,!0),e.appendChild(L),G=!0,S=e,y(),R()},H.hide=function(){q.unbind("mouseenter",f),q.unbind("mouseleave",m),d(),document.removeEventListener("keydown",v,!0),G&&(S&&S.removeChild(L),G=!1)},H.reload=function(){y(),R()},H.freeze=function(){O=!0,W&&W.disable()},H.unfreeze=function(){O=!1,W&&W.enable()},H.recalculateContentHeight=function(){N=0,U=0,V=0,P.forEach(function(e,n){h=$(e.element).outerHeight(!0),e.height=h,N+=h,U=(U*n+h)/(n+1),V=U*K}),V>n?W?(W.show(),W.set(-T/(V-n))):(W=new jsvlvscrollbar(c),L.appendChild(W.getElement()),W.show()):(T=0,W&&W.hide())},H.dbgdmp=function(){var e={scrollDistance:T,scrollDistancePending:Y,contentHeight:N,firstIndex:z,lastIndex:J,indexOfFocused:Q,contentTop:M.style.top};console.log(JSON.stringify(e))},H}