-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrader.min.js
11 lines (11 loc) · 5.37 KB
/
rader.min.js
1
2
3
4
5
6
7
8
9
10
11
'use strict';(function(A,M){function N(g){function F(a,c){var b=a[m.clientX]||(((a.originalEvent||a).touches||[])[0]||{})[m.pageX];if(c)var d=c.getBoundingClientRect(),b=b-d[m.start];return b}function A(a){if(a)n(document).on("selectstart.rader",function(){return!1});else n(document).off("selectstart.rader")}function B(a){return Math.min.apply(Math,a)}function G(a){100<a&&(a=100);0>a&&(a=0);return a}function p(a){null==H[a]&&(H[a]=G(100*((a-x)/O)));return H[a]}function y(a){null==I[a]&&(I[a]=a/100*
O+x);return I[a]}function C(a){var c=h[0],b=h[h.length-1];if(!h)return a;for(var d=0;k[d+1]&&!(a>=k[d]&&a<=k[d+1]);)d++;var e=k[d],f=k[d+1]||e,q=h[d],d=h[d+1]||q;0>=f-e&&(f=J,e=x);a="log"==g.scale?Math.exp((a-e)/(f-e)*(Math.log(d)-Math.log(q))+Math.log(q)):(a-e)/(f-e)*(d-q)+q;return a<c?c:a>b?b:a}function W(a){if(!k)return a;for(var c=k[0],b=k[k.length-1],d=0;h[d+1]&&!(a>=h[d]&&a<=h[d+1]);)d++;d==h.length-1&&d--;var e=h[d],f=h[d+1],q=k[d],d=k[d+1];a="log"==g.scale?(Math.log(a)-Math.log(e))/(Math.log(f)-
Math.log(e))*(d-q)+q:(a-e)/(f-e)*(d-q)+q;return a<c?c:a>b?b:a}function P(a,c,b){var d=a,e,f,h=-1,m=1/0;c=c||k;for(var l=0;l<c.length;l++)f="pc"==b?c[l]:p(c[l]),e=Math.abs(f-a),!(e<m)||g.runnersFreeze&&g.runnersFreeze[l]||(d=f,m=e,h=l);return{index:h,b:d}}function X(a,c){var b,d,e,f=1/0,h=a;b=P(a).b;var l=100*g.stickingRadius/s;e=Math.abs(b-a);if(e>l)return a;for(var m=0;m<k.length;m++)b=p(k[m]),d=Math.abs(b-a),b*c>a*c&&d<f&&(f=d,h=b);if(f<l)return h;if(f>=l)return a=G(a-e*c+l*c),Math.abs(h-a)<l?h:
a}function D(a,c,b){var d;if(g.runnersFreeze&&g.runnersFreeze[c])return e[c];if("init"==Q)d=1;else{d=e[a]||0;if(b>d)d=1;else if(b<d)d=-1;else return!1;b=G(b);a!=c&&(b=X(b,d))}var f=P(b).b,h=100*g.stickingRadius/s;f!==M&&f!==b&&Math.abs(f-b)<h&&(!R&&g.transCls&&(r(t).addClass(g.transCls),R=setTimeout(function(){r(t).removeClass(g.transCls);R=M},500)),b=f);f=100*g.bumpRadius/s;e[c+1*d]!==M&&(e[c+1*d]-b<f&&0<d||b-e[c+1*d]<f&&0>d)&&(a=D(a,c+1*d,b+d*f),b*d>(a-f*d)*d&&(b=X(a-f*d,-d)));e[c]=b;a={};a[m.start]=
e[c]+"%";r(E[c]).css(a);return b}function K(a){if(g.pointInRangeCls){var c=z.slice(),b;for(b=0;b<L.length;b++)p(k[b])>=e[0]&&p(k[b])<=e[e.length-1]?z[b]=1:z[b]=0;for(b=0;b<z.length;b++)if(z[b]!=c[b]||a)z[b]?r(L[b]).addClass(g.pointInRangeCls):r(L[b]).removeClass(g.pointInRangeCls)}a={};a[m.start]=B(e)+"%";a[m.size]=Math.max.apply(Math,e)-B(e)+"%";r(Y).css(a);if(g.onUpdate)g.onUpdate({minPos:B(e),maxPos:Math.max.apply(Math,e),minVal:C(y(B(e))),maxVal:C(y(Math.max.apply(Math,e)))})}function S(a,c){if(null!=
a){var b=(a-Z)*(100/s);a=p(l[u])+b;for(b=0;b<e.length;b++)T[b]=e[b];D(u,u,G(a))}a:if(e.length!=T.length)b=!1;else{for(b=0;b<e.length;b++)if(e[b]!==T[b]){b=!1;break a}b=!0}b&&!c||K(c)}function $(){var a=B(e),c=Math.max.apply(Math,e),b=C(y(a)),d=C(y(c));g.collapseVals&&c-a<100*g.bumpRadius/s+1E-5&&(100==c?b=d:0==a?d=b:e[u]===a?d=b:b=d);return{minPos:a,maxPos:c,minVal:b,maxVal:d}}function U(){g.move&&g.move($())}function aa(){s=t[m.a];H=[];I=[];var a,c;for(c=0;c<k.length;c++)a={},a[m.start]=p(k[c])+
"%",r(L[c]).css(a);for(c=0;c<l.length;c++)a={},e[c]=p(l[c]),a[m.start]=e[c]+"%",r(E[c]).css(a);c=p(l[0]);var b=p(l[l.length-1]);a={};a[m.start]=c+"%";a[m.size]=Math.abs(b-c)+"%";r(Y).css(a)}function V(){for(var a=0,c=l.length;a<c;a++)l[a]=y(e[a])}var N=this,O,s,ba=g.direction||"-",m=da[ba],f,r,Z,u=-1,l=[],e=[],T=[],z=[];Q="init";this.elements={};r=g.dom||n;var t=g.root[0],E=n(g.runners);f={stickingRadius:0,bumpRadius:E[0][m.offset],points:[],pointsPos:[0,10],runnersPos:[]};for(var w in f)null==g[w]&&
(g[w]=f[w]);var ca=g.track,Y=g.trackActive,L=g.points,k=g.pointsPos,v=g.runnersPos;w=g.runnersVal;var x,J,h=g.values;x=k[0];J=k[k.length-1];h||(h=k);for(f=0;f<h.length;f++)h[f]=+h[f];if(2==h.length&&2<k.length){var ea=(h[1]-h[0])/(k[k.length-1]-k[0]);for(f=1;f<k.length;f++)h[f]=h[0]+(k[f]-k[0])*ea}if(w&&!v.length)for(f=0;f<w.length;f++)v[f]=W(w[f]);v.length||(v=[x,J]);O=Math.abs(J-x);var H=[],I=[],R;n(document).on("mouseup.rader blur.rader touchend.rader",function(){-1!=u&&(V(),g.change&&g.change($()),
A(1));u=-1});n(document).on("mousedown.rader touchstart.rader",function(a){s=t[m.a];Z=F(a)});n(document).on("mousemove.rader touchmove.rader",function(a){-1!=u&&(a=F(a),S(a,0),U())});if(g.click)n(ca||t).on("click.rader",function(a){for(var c,b=0;b<g.runners.length;b++)c=c||a.target==g.runners[b];c||(c=100*(F(a,this)/this[m.a]),b=P(c,e,"pc"),D(b.index,b.index,c),a=F(a),S(a,1),V(),U())});this.pos=function(a,c){if(null!=c){var b=p(c);D(a,a,b);V();K(1);return this}return l[a]};this.val=function(a,c){if(null!=
c){var b=W(c),b=p(b);D(a,a,b);for(b=0;b<e.length;b++)l[b]=y(e[b]);K(1);return this}return C(l[a])};this.invalidate=function(){aa();K(1);U()};this.dispose=function(){n(document).off("rader");n(E).off("rader");n(ca).off("rader");n(t).off("rader")};for(f=0;f<v.length;f++)n(E[f]).on("mousedown.rader touchstart.rader",function(a){return function(c){2!=c.button&&(c.preventDefault(),A(),u=a)}}(f));(function(){s=t[m.a];l=v.slice();for(var a=0;a<v.length;a++)e[a]=p(l[a]);for(a=0;a<v.length;a++)N.pos(a,l[a]),
e[a]=p(l[a])})();aa();S(null,1);Q="ready";n(t)[0].setAttribute("data-rader-inited",ba);return this}var n=A.$,Q,da={"-":{start:"left",c:"offsetLeft",a:"clientWidth",offset:"offsetWidth",size:"width",clientX:"clientX",pageX:"pageX"},"|":{start:"top",c:"offsetTop",a:"clientHeight",offset:"offsetHeight",size:"height",clientX:"clientY",pageX:"pageY"}};A.$.fn.rader=function(g){g=g||{};g.root=g.root||this;return new N(g)}})(window);