!function(t,e){"function"==typeof define&&define.amd?define(function(){return e(t,t.document)}):"undefined"!=typeof module&&module.exports?module.exports=e(t,t.document):t.Shake=e(t,t.document)}("undefined"!=typeof window?window:this,function(t,e){"use strict";function i(i){if(this.hasDeviceMotion="ondevicemotion"in t,this.options={threshold:15,timeout:1e3},"object"==typeof i)for(var s in i)i.hasOwnProperty(s)&&(this.options[s]=i[s]);if(this.lastTime=new Date,this.lastX=null,this.lastY=null,this.lastZ=null,"function"==typeof e.CustomEvent)this.event=new e.CustomEvent("shake",{bubbles:!0,cancelable:!0});else{if("function"!=typeof e.createEvent)return!1;this.event=e.createEvent("Event"),this.event.initEvent("shake",!0,!0)}}return i.prototype.reset=function(){this.lastTime=new Date,this.lastX=null,this.lastY=null,this.lastZ=null},i.prototype.start=function(){this.reset(),this.hasDeviceMotion&&t.addEventListener("devicemotion",this,!1)},i.prototype.stop=function(){this.hasDeviceMotion&&t.removeEventListener("devicemotion",this,!1),this.reset()},i.prototype.devicemotion=function(e){var i,s=e.accelerationIncludingGravity,n=0,o=0,h=0;if(null===this.lastX&&null===this.lastY&&null===this.lastZ)return this.lastX=s.x,this.lastY=s.y,void(this.lastZ=s.z);n=Math.abs(this.lastX-s.x),o=Math.abs(this.lastY-s.y),h=Math.abs(this.lastZ-s.z),(n>this.options.threshold&&o>this.options.threshold||n>this.options.threshold&&h>this.options.threshold||o>this.options.threshold&&h>this.options.threshold)&&(i=new Date,i.getTime()-this.lastTime.getTime()>this.options.timeout&&(t.dispatchEvent(this.event),this.lastTime=new Date)),this.lastX=s.x,this.lastY=s.y,this.lastZ=s.z},i.prototype.handleEvent=function(t){if("function"==typeof this[t.type])return this[t.type](t)},i});