-
Notifications
You must be signed in to change notification settings - Fork 1
/
yyshake.min.js
1 lines (1 loc) · 1.66 KB
/
yyshake.min.js
1
(function(c){if(!("ondevicemotion" in c)){c.yyshake=false;return}function a(d){if(d){return Math.abs(d)}else{return 0}}var b=(function(){var m=15,u=false,v=false,j=null,i=null,h=null,e,l=0,p=null,r=[];function q(x){r.some(function(z,y){if(z.callback===x){r.splice(y,1);return true}})}function n(z,x){var y=r.some(function(B,A){if(B.callback===z){return true}});(!y)&&r.push({callback:z,one:x})}function w(y){var x=Array.prototype.slice.call(arguments,1);switch(y){case"end":r=r.filter(function(z){if(typeof z.callback==="object"){z.callback.end&&z.callback.end.apply(c,x)}else{z.callback.apply(c,x)}if(z.one){return false}else{return true}});break;default:r.forEach(function(A,z){if(typeof A.callback==="object"){A.callback[y]&&A.callback[y].apply(c,x)}});break}}function s(x){if(typeof x==="object"){if(x.threshold){m=x.threshold}}}function o(y,x){x=x?true:false;n(y,x)}function k(x){if(x){q(x)}else{r=[]}}function g(){f(true)}function t(){f(false)}function f(x){if(x){if(!u){c.addEventListener("devicemotion",d,false);u=true}}else{if(u){c.removeEventListener("devicemotion",d,false);u=false}}}function d(D){var C=D.accelerationIncludingGravity;if((j===null)&&(i===null)&&(h===null)){j=C.x;i=C.y;h=C.z;e=new Date().getTime();l=0;p=null;return}var x=new Date().getTime(),E=x-e,z=a(j-C.x),A=a(i-C.y),B=a(h-C.z),y=Math.floor(Math.max(z,A));e=x;j=C.x;i=C.y;h=C.z;if(y>=m){if(l===0){w("begin");v=true}else{w("lasting",true,{deleta:y,interval:E,threshold:m})}l++;if(p){clearTimeout(p)}p=setTimeout(function(){w("end");j=null;i=null;h=null;v=false},200)}else{v&&w("lasting",false,{delta:y,interval:E,threshold:m})}}return{config:s,addListener:o,removeListener:k,start:g,stop:t}})();c.yyshake=b})(window);