-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairplane.min.js
1 lines (1 loc) · 7.23 KB
/
airplane.min.js
1
var airPlane=function(){function v(o){if(!b.isCalibrated()){b.calibrate(o);return}var a=n-i;if(o.fingers!==null&&o.fingers!==undefined&&o.fingers.length>0){var c=0,h=0,v=0;while(c<o.fingers.length){if(c<o.fingers.length){if(o.fingers[c].tipPosition[2]<v&&o.fingers[c].direction.z<0){if(o.fingers[c].tipPosition[2]>e){h=c;v=o.fingers[c].tipPosition[2]}}}c+=1}var m=0,g=[];while(m<o.fingers.length){if(o.fingers[m].tipPosition[2]<e+s*l.leniance){var w=o.fingers[m].tipPosition[0],E=o.fingers[m].tipPosition[1];var S=(w+=0-i)/(n-i)*100;var x=(E+=0-r)/(t-r)*100;var T=Math.floor(0+window.innerWidth/100*S)+window.pageXOffset;var N=Math.floor(window.innerHeight-window.innerHeight/100*x)+window.pageYOffset;var C=o.fingers[m].tipPosition[2];if(C-y.lastCoords.z>y.threshold.get()&&!f&&T-y.threshold.lastCoords.x>threshold.get()||C-y.lastCoords.z>y.threshold.get()&&!f&&N-y.lastCoords.y>moveThreshold){T=y.lastCoords.x;N=y.lastCoords.y;C=y.lastCoords.z;f=false}else{lastX=T;lastY=N;lastZ=C}if(y.get()[m]===undefined){y.createPointer()}if(y.display()){y.get()[m].style.opacity=1;y.get()[m].style.left=T+50+"px";y.get()[m].style.top=N+"px"}else{y.get()[m].style.opacity=0}if(m===h&&o.fingers[m].tipPosition[2]<e+s){var k=document.elementFromPoint(T,N);y.get()[m].style.opacity=1;if(k!==null&&!u){k.dispatchEvent(d);(function(){u=true;setTimeout(function(){u=false},p)})()}}g.push({x:T,y:N,z:o.fingers[m].tipPosition[2]})}else{if(y.get()[m]!==undefined){y.get()[m].style.left="-100px";y.get()[m].style.top="-100px"}}m+=1}var L=m;while(L<y.get().length){y.get()[L].style.top="-100px";y.get()[L].style.left="-100px";L+=1}if(l.returnCoordinates===true){return g}}else if(o.hands.length<1){f=true;if(y.get().length>0){y.get()[0].style.top="-100px";y.get()[0].style.left="-100px"}}if(l.returnCoordinates===true){return[]}}function m(e){if(e.customEvent!==undefined){d=new Event(e.customEvent)}if(e.delay!==undefined){g(e.delay)}if(e.threshold!==undefined&&typeof e.threshold==="number"){threshold=e.threshold}if(e.percentToDrop!==undefined&&typeof e.percentToDrop==="number"){percentToDrop=e.percentToDrop()}if(e.alwaysReset!==undefined&&e.alwaysReset===true||e.alwaysReset===1){w()}if(e.displayPointers!==undefined&&typeof e.displayPointers==="boolean"){y.display(e.displayPointers)}if(e.returnCoordinates!==undefined&&typeof e.returnCoordinates==="boolean"){l.returnCoordinates=e.returnCoordinates}}function g(e){if(e!==null&&e!==undefined&&typeof e==="number"&&e>-1){p=e}else{console.error("Invalid input")}}function w(){localStorage.clear();S.empty();e=t=n=r=i=undefined;o=isTopSet=isRightSet=isBottomSet=isLeftSet=false;if(c===undefined){b.createCalibrationElement()}c.style.display="block";c.style.left=window.innerWidth/2-c.offsetWidth/2}function E(){return{zDepth:e,top:t,right:n,bottom:r,left:i}}var e,t,n,r,i,s=20;var o=isTopSet=isRightSet=isBottomSet=isLeftSet=false;var u=false,a=2e3,f=true;var l={threshold:200,percentToDrop:20,returnCoordinates:false,leniance:2};var c,h;var p=500;var d=new Event("click");var y=function(){function i(){return e}function s(e){if(e!==undefined&&typeof e==="boolean"){t=e}return t}function o(){var t=document.createElement("div");t.setAttribute("class","cursor");document.body.appendChild(t);e.push(t)}var e=[],t=true,n={x:undefined,y:undefined,z:undefined};var r=function(){function t(t){if(typeof e==="number"){e=t}else{console.error("Not a valid value")}}function n(){return e}var e=10;return{set:t,get:n}}();return{get:i,display:s,createPointer:o,threshold:r,lastCoords:n}}();var b=function(){function s(){if(!o||!isTopSet||!isRightSet||!isBottomSet||!isLeftSet){if(localStorage.getItem("leapCoords")===null){return false}else{var s=JSON.parse(localStorage.getItem("leapCoords"));e=s.z;t=s.topCoords;n=s.rightCoords;r=s.bottomCoords;i=s.leftCoords;o=isTopSet=isRightSet=isBottomSet=isLeftSet=true;return true}}else if(o&&isTopSet&&isRightSet&&isBottomSet&&isLeftSet&&localStorage.getItem("leapCoords")===null){var u={z:e,topCoords:t,rightCoords:n,bottomCoords:r,leftCoords:i};localStorage.setItem("leapCoords",JSON.stringify(u));return true}else{return true}}function f(){c=document.createElement("div");c.setAttribute("id","calEl");h=document.createElement("div");h.setAttribute("id","progress");c.appendChild(h);document.body.appendChild(c);c.style.top=window.innerHeight/2-c.offsetWidth/2+"px";c.style.left=window.innerWidth/2-c.offsetHeight/2+"px";c.style.display="none"}function p(e){console.log("Point set. Remove Finger.");h.style.height="0px";c.style.display="none";if(e.top!==undefined){c.style.top=e.top+"px"}if(e.left!==undefined){c.style.left=e.left+"px"}if(e.display!==undefined){c.style.display=e.display}u=true;if(e.final!==true){setTimeout(function(){u=false;c.style.display="block"},a)}}function d(e){h.style.height=c.offsetHeight/100*e+"px"}function v(s){if(u){return}var a=s.fingers;if(s.fingers.length>1){return false}if(c===undefined){f();c.style.display="block"}if(a!==null&&a!==undefined&&a.length>0){var h=0;while(h<1){if(!o){S.addPoint({which:"zMeasure",value:a[h].tipPosition[2]});if(S.checkPointProgress({which:"zMeasure"})>l.threshold){o=true;e=S.getPoint({which:"zMeasure"});p({top:0})}else{d(S.checkPointProgress({which:"zMeasure"})/l.threshold*100)}}else if(!isTopSet){S.addPoint({which:"topMeasure",value:a[h].tipPosition[1]});if(S.checkPointProgress({which:"topMeasure"})>l.threshold){isTopSet=true;t=S.getPoint({which:"topMeasure"});p({top:window.innerHeight/2-c.offsetWidth/2,left:window.innerWidth-c.offsetWidth/1})}else{d(S.checkPointProgress({which:"topMeasure"})/l.threshold*100)}}else if(!isRightSet){S.addPoint({which:"rightMeasure",value:a[h].tipPosition[0]});if(S.checkPointProgress({which:"rightMeasure"})>l.threshold){isRightSet=true;n=S.getPoint({which:"rightMeasure"});p({top:window.innerHeight-c.offsetHeight,left:window.innerWidth/2-c.offsetWidth/2})}else{d(S.checkPointProgress({which:"rightMeasure"})/l.threshold*100)}}else if(!isBottomSet){S.addPoint({which:"bottomMeasure",value:a[h].tipPosition[1]});if(S.checkPointProgress({which:"bottomMeasure"})>l.threshold){isBottomSet=true;r=S.getPoint({which:"bottomMeasure"});p({top:window.innerHeight/2-c.offsetWidth/2,left:0})}else{d(S.checkPointProgress({which:"bottomMeasure"})/l.threshold*100)}}else if(!isLeftSet){S.addPoint({which:"leftMeasure",value:a[h].tipPosition[0]});if(S.checkPointProgress({which:"leftMeasure"})>l.threshold){isLeftSet=true;i=S.getPoint({which:"leftMeasure"});p({top:window.innerHeight/2-c.offsetWidth/2,left:window.innerWidth/2-c.offsetWidth/2,display:"none","final":true})}else{var v=S.checkPointProgress({which:"leftMeasure"})/l.threshold*100;d(S.checkPointProgress({which:"leftMeasure"})/l.threshold*100)}}h+=1}}}return{isCalibrated:s,calibrate:v,createCalibrationElement:f}}();var S=function(){function t(t){if(t!==undefined&&t!==null){if(e[t.which]!==undefined&&t.value!==undefined&&typeof t.value==="number"){e[t.which].push(t.value)}}}function n(t){var n=0;for(var r=0+Math.floor(l.threshold/100*l.percentToDrop);r<e[t.which].length;r+=1){n+=e[t.which][r]}return n/(e[t.which].length-Math.floor(l.threshold/100*l.percentToDrop))}function r(t){return e[t.which].length}function i(){for(var t in e){e[t]=[]}}var e={zMeasure:[],topMeasure:[],rightMeasure:[],bottomMeasure:[],leftMeasure:[]};return{addPoint:t,getPoint:n,checkPointProgress:r,empty:i}}();return{checkCoords:v,calibration:b,reset:w,currentCoords:E,set:m,screenPointers:y}}()