-
Notifications
You must be signed in to change notification settings - Fork 4
/
pinch.min.js
1 lines (1 loc) · 1.89 KB
/
pinch.min.js
1
new function(){var a,b={target:null,distance:0,angle:0,x:0,y:0}.constructor,c=[],d=[],e={target:null,scale:0,angle:0,x:0,y:0}.constructor,f=[],g={transform:"",WebkitTransform:"-webkit-",MozTransform:"-moz-",OTransform:"-o-",msTransform:"-ms-"},h=function(){for(var b in g)if(document.body.style[b]!==a)return g[b]}()||"",i=function(a,b,c,d,e,f,g){var i=$.Event(c,{prefix:h,scale:d,angle:e,offsetLeft:f,offsetTop:g});$(a).trigger(i),i.isDefaultPrevented()&&b.preventDefault()},j=function(a,e,f){var g=Array.prototype.slice.call(f.originalEvent.touches),h,j,k=function(a){return a.target==h.target};for(var l=0;g.length>0;l++){h=g.shift(),j=g.filter(k).shift();if(j)g.splice(g.indexOf(j),1);else continue;var m=h.clientX,n=h.clientY,o=j.clientX,p=j.clientY;for(var q=0;q<e.length;q++){var r=e[q],s=r.filter(k).shift();s||r.push(s=new b),s.target=h.target,s.distance=Math.sqrt((m-o)*(m-o)+(n-p)*(n-p)),s.angle=Math.atan((n-p)/(m-o))*360/Math.PI||0,s.x=(m+o)/2,s.y=(n+p)/2}var t=d.filter(k).shift(),u=c.filter(k).shift();t&&i(t.target,f,a,t.distance/u.distance||1,t.angle-u.angle,t.x-u.x,t.y-u.y)}};$(document).off(".pinch").on({"touchstart.pinch":function(a){j("pinchstart",[c,d],a)},"touchmove.pinch":function(a){j("pinchmove",[d],a)},"touchend.pinch":function(a){j("pinchend",[d],a),a.originalEvent.touches.length==0&&(c.length=d.length=f.length=0)},"pinchstart.pinch":function(a){var b=getComputedStyle(a.target,null).getPropertyValue(h+"transform"),c=b.match(/[0-9.\-]+/g),d=c?c.map(function(a){return parseFloat(a)}):[0,0,0,0,0,0],g=f.filter(function(b){return b.target==a.target}).shift();g||f.push(g=new e),g.target=a.target,g.scale=b=="none"?0:Math.sqrt(d[0]*d[0]+d[1]*d[1])-1,g.angle=Math.atan2(d[1],d[0])*(180/Math.PI),g.x=d[4],g.y=d[5]},"pinchmove.pinch":function(a){var b=f.filter(function(b){return b.target==a.target}).shift();b&&i(b.target,a,"pinchchange",b.scale+a.scale,b.angle+a.angle,b.x+a.offsetLeft,b.y+a.offsetTop)}})}