text: !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.nipplejs=e()}}(function(){function e(){}function t(e,i){return this.identifier=i.identifier,this.position=i.position,this.frontPosition=dataoptions.frontPosition,this.collection=e,this.defaults={size:100,threshold:.1,color:"white",fadeTime:250,restJoystick:!0,restOpacity:.5,mode:"dynamic",zone:document.body,lockX:!1,lockY:!1},this.config(i),"dynamic"===this.options.mode&&(this.options.restOpacity=0),this.id=t.id,t.id+=1,this.buildEl().stylize(),this.instance={el:this.ui.el,on:this.on.bind(this),off:this.off.bind(this),show:this.show.bind(this),hide:this.hide.bind(this),add:this.addToDom.bind(this),remove:this.removeFromDom.bind(this),destroy:this.destroy.bind(this),resetDirection:this.resetDirection.bind(this),computeDirection:this.computeDirection.bind(this),trigger:this.trigger.bind(this),position:this.position,frontPosition:this.frontPosition,ui:this.ui,identifier:this.identifier,id:this.id,options:this.options},this.instance}function i(e,t){var n=this;return n.nipples=[],n.idles=[],n.actives=[],n.ids=[],n.pressureIntervals={},n.manager=e,n.id=i.id,i.id+=1,n.defaults={zzz:!1,maxNumberOfNipples:10,mode:"dynamic",position:{top:0,left:0},catchDistance:200,size:100,threshold:.1,color:"white",fadeTime:250,restJoystick:!0,restOpacity:.5,lockX:!1,lockY:!1},n.config(t),"static"!==n.options.mode&&"semi"!==n.options.mode||(n.options.multitouch=!1),n.options.multitouch||(n.options.maxNumberOfNipples=1),n.updateBox(),n.prepareNipples(),n.bindings(),n.begin(),n.nipples}function n(e){var t=this;t.ids={},t.index=0,t.collections=[],t.config(e),t.prepareCollections();var i;return c.bindEvt(window,"resize",function(e){clearTimeout(i),i=setTimeout(function(){var e,i=c.getScroll();t.collections.forEach(function(t){t.forEach(function(t){e=t.el.getBoundingClientRect(),t.position={x:i.x+e.left,y:i.y+e.top}})})},100)}),t.collections}var o,r=!!("ontouchstart"in window),s=!!window.PointerEvent,d=!!window.MSPointerEvent,a={touch:{start:"touchstart",move:"touchmove",end:"touchend, touchcancel"},mouse:{start:"mousedown",move:"mousemove",end:"mouseup"},pointer:{start:"pointerdown",move:"pointermove",end:"pointerup, pointercancel"},MSPointer:{start:"MSPointerDown",move:"MSPointerMove",end:"MSPointerUp"}},p={};s?o=a.pointer:d?o=a.MSPointer:r?(o=a.touch,p=a.mouse):o=a.mouse;var c={};c.distance=function(e,t){var i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)},c.angle=function(e,t){var i=t.x-e.x,n=t.y-e.y;return c.degrees(Math.atan2(n,i))},c.findCoord=function(e,t,i){var n={x:0,y:0};return i=c.radians(i),n.x=e.x-t*Math.cos(i),n.y=e.y-t*Math.sin(i),n},c.radians=function(e){return e*(Math.PI/180)},c.degrees=function(e){return e*(180/Math.PI)},c.bindEvt=function(e,t,i){for(var n,o=t.split(/[ ,]+/g),r=0;r<o.length;r+=1)n=o[r],e.addEventListener?e.addEventListener(n,i,!1):e.attachEvent&&e.attachEvent(n,i)},c.unbindEvt=function(e,t,i){for(var n,o=t.split(/[ ,]+/g),r=0;r<o.length;r+=1)n=o[r],e.removeEventListener?e.removeEventListener(n,i):e.detachEvent&&e.detachEvent(n,i)},c.trigger=function(e,t,i){var n=new CustomEvent(t,i);e.dispatchEvent(n)},c.prepareEvent=function(e){return e.preventDefault(),e.type.match(/^touch/)?e.changedTouches:e},c.getScroll=function(){return{x:void 0!==window.pageXOffset?window.pageXOffset:(document.documentElement||document.body.parentNode||document.body).scrollLeft,y:void 0!==window.pageYOffset?window.pageYOffset:(document.documentElement||document.body.parentNode||document.body).scrollTop}},c.applyPosition=function(e,t){t.top||t.right||t.bottom||t.left?(e.style.top=t.top,e.style.right=t.right,e.style.bottom=t.bottom,e.style.left=t.left):(e.style.left=t.x+"px",e.style.top=t.y+"px")},c.getTransitionStyle=function(e,t,i){var n=c.configStylePropertyObject(e);for(var o in n)if(n.hasOwnProperty(o))if("string"==typeof t)n[o]=t+" "+i;else{for(var r="",s=0,d=t.length;s<d;s+=1)r+=t[s]+" "+i+", ";n[o]=r.slice(0,-2)}return n},c.getVendorStyle=function(e,t){var i=c.configStylePropertyObject(e);for(var n in i)i.hasOwnProperty(n)&&(i[n]=t);return i},c.configStylePropertyObject=function(e){var t={};return t[e]="",["webkit","Moz","o"].forEach(function(i){t[i+e.charAt(0).toUpperCase()+e.slice(1)]=""}),t},c.extend=function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);return e},c.safeExtend=function(e,t){var i={};for(var n in e)e.hasOwnProperty(n)&&t.hasOwnProperty(n)?i[n]=t[n]:e.hasOwnProperty(n)&&(i[n]=e[n]);return i},c.map=function(e,t){if(e.length)for(var i=0,n=e.length;i<n;i+=1)t(e[i]);else t(e)},e.prototype.on=function(e,t){var i,n=this,o=e.split(/[ ,]+/g);n._handlers_=n._handlers_||{};for(var r=0;r<o.length;r+=1)i=o[r],n._handlers_[i]=n._handlers_[i]||[],n._handlers_[i].push(t);return n},e.prototype.off=function(e,t){var i=this;return i._handlers_=i._handlers_||{},void 0===e?i._handlers_={}:void 0===t?i._handlers_[e]=null:i._handlers_[e]&&i._handlers_[e].indexOf(t)>=0&&i._handlers_[e].splice(i._handlers_[e].indexOf(t),1),i},e.prototype.trigger=function(e,t){var i,n=this,o=e.split(/[ ,]+/g);n._handlers_=n._handlers_||{};for(var r=0;r<o.length;r+=1)i=o[r],n._handlers_[i]&&n._handlers_[i].length&&n._handlers_[i].forEach(function(e){e.call(n,{type:i,target:n},t)})},e.prototype.config=function(e){var t=this;t.options=t.defaults||{},e&&(t.options=c.safeExtend(t.options,e))},e.prototype.bindEvt=function(e,t){var i=this;return i._domHandlers_=i._domHandlers_||{},i._domHandlers_[t]=function(){"function"==typeof i["on"+t]?i["on"+t].apply(i,arguments):console.warn('[WARNING] : Missing "on'+t+'" handler.')},c.bindEvt(e,o[t],i._domHandlers_[t]),p[t]&&c.bindEvt(e,p[t],i._domHandlers_[t]),i},e.prototype.unbindEvt=function(e,t){var i=this;return i._domHandlers_=i._domHandlers_||{},c.unbindEvt(e,o[t],i._domHandlers_[t]),p[t]&&c.unbindEvt(e,p[t],i._domHandlers_[t]),delete i._domHandlers_[t],this},t.prototype=new e,t.constructor=t,t.id=0,t.prototype.destroy=function(){clearTimeout(this.removeTimeout),clearTimeout(this.showTimeout),clearTimeout(this.restTimeout),this.trigger("destroyed",this.instance),this.removeFromDom(),this.off()},t.prototype.restPosition=function(e){var t=this;t.frontPosition={x:0,y:0};var i=t.options.fadeTime+"ms",n={};n.front=c.getTransitionStyle("transition",["top","left"],i);var o={front:{}};o.front={left:t.frontPosition.x+"px",top:t.frontPosition.y+"px"},t.applyStyles(n),t.applyStyles(o),t.restTimeout=setTimeout(function(){"function"==typeof e&&e.call(t),t.restCallback()},t.options.fadeTime)},t.prototype.restCallback=function(){var e=this,t={};t.front=c.getTransitionStyle("transition","none",""),e.applyStyles(t),e.trigger("rested",e.instance)},t.prototype.resetDirection=function(){this.direction={x:!1,y:!1,angle:!1}},t.prototype.computeDirection=function(e){var t,i,n,o=e.angle.radian,r=Math.PI/4,s=Math.PI/2;if(o>r&&o<3*r&&!e.lockX?t="up":o>-r&&o<=r&&!e.lockY?t="left":o>3*-r&&o<=-r&&!e.lockX?t="down":e.lockY||(t="right"),e.lockY||(i=o>-s&&o<s?"left":"right"),e.lockX||(n=o>0?"up":"down"),e.force>this.options.threshold){var d={};for(var a in this.direction)this.direction.hasOwnProperty(a)&&(d[a]=this.direction[a]);var p={};this.direction={x:i,y:n,angle:t},e.direction=this.direction;for(var a in d)d[a]===this.direction[a]&&(p[a]=!0);if(p.x&&p.y&&p.angle)return e;p.x&&p.y||this.trigger("plain",e),p.x||this.trigger("plain:"+i,e),p.y||this.trigger("plain:"+n,e),p.angle||this.trigger("dir dir:"+t,e)}return e},i.prototype=new e,i.constructor=i,i.id=0,i.prototype.prepareNipples=function(){var e=this,t=e.nipples;t.on=e.on.bind(e),t.off=e.off.bind(e),t.options=e.options,t.destroy=e.destroy.bind(e),t.ids=e.ids,t.id=e.id,t.processOnMove=e.processOnMove.bind(e),t.processOnEnd=e.processOnEnd.bind(e),t.get=function(e){if(void 0===e)return t[0];for(var i=0,n=t.length;i<n;i+=1)if(t[i].identifier===e)return t[i];return!1}},i.prototype.bindings=function(){var e=this;e.bindEvt(e.options.zone,"start"),e.options.zone.style.touchAction="none",e.options.zone.style.msTouchAction="none"},i.prototype.begin=function(){var e=this,t=e.options;if("static"===t.mode){var i=e.createNipple(t.position,e.manager.getIdentifier());i.add(),e.idles.push(i)}},i.prototype.createNipple=function(e,i){var n=this,o=c.getScroll(),r=n.options;if(e.x&&e.y)({x:e.x-(o.x+n.box.left),y:e.y-(o.y+n.box.top)});else if(e.top||e.right||e.bottom||e.left){var s=document.createElement("DIV");s.style.display="hidden",s.style.top=e.top,s.style.right=e.right,s.style.bottom=e.bottom,s.style.left=e.left,s.style.position="absolute",r.zone.appendChild(s);var d=s.getBoundingClientRect();r.zone.removeChild(s),e,e={x:d.left+o.x,y:d.top+o.y}}var a=new t(n,{color:r.color,size:r.size,threshold:r.threshold,fadeTime:r.fadeTime,restJoystick:r.restJoystick,restOpacity:r.restOpacity,mode:r.mode,identifier:i,position:e,zone:r.zone,frontPosition:{x:0,y:0}});return n.nipples.push(a),n.trigger("added "+a.identifier+":added",a),n.manager.trigger("added "+a.identifier+":added",a),n.bindNipple(a),a},i.prototype.updateBox=function(){var e=this;e.box=e.options.zone.getBoundingClientRect()},i.prototype.bindNipple=function(e){var t,i=this,n=function(e,n){t=e.type+" "+n.id+":"+e.type,i.trigger(t,n)};e.on("destroyed",i.onDestroyed.bind(i)),e.on("shown hidden rested dir plain",n),e.on("dir:up dir:right dir:down dir:left",n),e.on("plain:up plain:right plain:down plain:left",n)},i.prototype.pressureFn=function(e,t,i){var n=this,o=0;clearInterval(n.pressureIntervals[i]),n.pressureIntervals[i]=setInterval(function(){var i=e.force||e.pressure||e.webkitForce||0;i!==o&&(t.trigger("pressure",i),n.trigger("pressure "+t.identifier+":pressure",i),o=i)}.bind(n),100)},i.prototype.onstart=function(e){var t=this,i=t.options;e=c.prepareEvent(e),t.updateBox();var n=function(e){t.actives.length<i.maxNumberOfNipples&&t.processOnStart(e)};return c.map(e,n),t.manager.bindDocument(),!1},i.prototype.processOnStart=function(e){var t,i=this,n=i.options,o=i.manager.getIdentifier(e),r=e.force||e.pressure||e.webkitForce||0,s={x:e.pageX,y:e.pageY},d=i.getOrCreate(o,s);d.identifier!==o&&i.manager.removeIdentifier(d.identifier),d.identifier=o;var a=function(t){t.trigger("start",t),i.trigger("start "+t.id+":start",t),t.show(),r>0&&i.pressureFn(e,t,t.identifier),i.processOnMove(e)};if((t=i.idles.indexOf(d))>=0&&i.idles.splice(t,1),i.actives.push(d),i.ids.push(d.identifier),"semi"!==n.mode)a(d);else{if(!(c.distance(s,d.position)<=n.catchDistance))return d.destroy(),void i.processOnStart(e);a(d)}return d},i.prototype.getOrCreate=function(e,t){var i,n=this,o=n.options;return/(semi|static)/.test(o.mode)?(i=n.idles[0])?(n.idles.splice(0,1),i):"semi"===o.mode?n.createNipple(t,e):(console.warn("Coudln't find the needed nipple."),!1):i=n.createNipple(t,e)},i.prototype.processOnMove=function(e){var t=this,i=t.options,n=t.manager.getIdentifier(e),o=t.nipples.get(n);if(!o)return console.error("Found zombie joystick with ID "+n),void t.manager.removeIdentifier(n);o.identifier=n;var r=o.options.size/2,s={x:e.pageX,y:e.pageY},d=c.distance(s,o.position),a=c.angle(s,o.position),p=c.radians(a),l=d/r;d>r&&(d=r,s=c.findCoord(o.position,d,a));var f=s.x-o.position.x,u=s.y-o.position.y;i.lockX&&(u=0),i.lockY&&(f=0),o.frontPosition={x:f,y:u};var h={identifier:o.identifier,position:s,force:l,pressure:e.force||e.pressure||e.webkitForce||0,distance:d,angle:{radian:p,degree:a},instance:o,lockX:i.lockX,lockY:i.lockY};h=o.computeDirection(h),h.angle={radian:c.radians(180-a),degree:180-a},o.trigger("move",h),t.trigger("move "+o.id+":move",h)},i.prototype.processOnEnd=function(e){var t=this,i=t.options,n=t.manager.getIdentifier(e),o=t.nipples.get(n),r=t.manager.removeIdentifier(o.identifier);o&&(clearInterval(t.pressureIntervals[o.identifier]),o.resetDirection(),o.trigger("end",o),t.trigger("end "+o.id+":end",o),t.ids.indexOf(o.identifier)>=0&&t.ids.splice(t.ids.indexOf(o.identifier),1),t.actives.indexOf(o)>=0&&t.actives.splice(t.actives.indexOf(o),1),/(semi|static)/.test(i.mode)?t.idles.push(o):t.nipples.indexOf(o)>=0&&t.nipples.splice(t.nipples.indexOf(o),1),t.manager.unbindDocument(),/(semi|static)/.test(i.mode)&&(t.manager.ids[r.id]=r.identifier))},i.prototype.onDestroyed=function(e,t){var i=this;i.nipples.indexOf(t)>=0&&i.nipples.splice(i.nipples.indexOf(t),1),i.actives.indexOf(t)>=0&&i.actives.splice(i.actives.indexOf(t),1),i.idles.indexOf(t)>=0&&i.idles.splice(i.idles.indexOf(t),1),i.ids.indexOf(t.identifier)>=0&&i.ids.splice(i.ids.indexOf(t.identifier),1),i.manager.removeIdentifier(t.identifier),i.manager.unbindDocument()},i.prototype.destroy=function(){var e=this;e.unbindEvt(e.options.zone,"start"),e.nipples.forEach(function(e){e.destroy()});for(var t in e.pressureIntervals)e.pressureIntervals.hasOwnProperty(t)&&clearInterval(e.pressureIntervals[t]);e.trigger("destroyed",e.nipples),e.manager.unbindDocument(),e.off()},n.prototype=new e,n.constructor=n,n.prototype.prepareCollections=function(){var e=this;e.collections.create=e.create.bind(e),e.collections.on=e.on.bind(e),e.collections.off=e.off.bind(e),e.collections.destroy=e.destroy.bind(e),e.collections.get=function(t){var i;return e.collections.every(function(e){return!(i=e.get(t))}),i}},n.prototype.create=function(e){return this.createCollection(e)},n.prototype.createCollection=function(e){var t=this,n=new i(t,e);return t.bindCollection(n),t.collections.push(n),n},n.prototype.bindCollection=function(e){var t,i=this,n=function(e,n){t=e.type+" "+n.id+":"+e.type,i.trigger(t,n)};e.on("destroyed",i.onDestroyed.bind(i)),e.on("shown hidden rested dir plain",n),e.on("dir:up dir:right dir:down dir:left",n),e.on("plain:up plain:right plain:down plain:left",n)},n.prototype.bindDocument=function(){var e=this;e.binded||(e.bindEvt(document,"move").bindEvt(document,"end"),e.binded=!0)},n.prototype.unbindDocument=function(e){var t=this;Object.keys(t.ids).length&&!0!==e||(t.unbindEvt(document,"move").unbindEvt(document,"end"),t.binded=!1)},n.prototype.getIdentifier=function(e){var t;return e?void 0===(t=void 0===e.identifier?e.pointerId:e.identifier)&&(t=this.latest||0):t=this.index,void 0===this.ids[t]&&(this.ids[t]=this.index,this.index+=1),this.latest=t,this.ids[t]},n.prototype.removeIdentifier=function(e){var t={};for(var i in this.ids)if(this.ids[i]===e){t.id=i,t.identifier=this.ids[i],delete this.ids[i];break}return t},n.prototype.onmove=function(e){return this.onAny("move",e),!1},n.prototype.onend=function(e){return this.onAny("end",e),!1},n.prototype.oncancel=function(e){return this.onAny("end",e),!1},n.prototype.onAny=function(e,t){var i,n=this,o="processOn"+e.charAt(0).toUpperCase()+e.slice(1);t=c.prepareEvent(t);var r=function(e,t,i){i.ids.indexOf(t)>=0&&(i[o](e),e._found_=!0)},s=function(e){i=n.getIdentifier(e),c.map(n.collections,r.bind(null,e,i)),e._found_||n.removeIdentifier(i)};return c.map(t,s),!1},n.prototype.destroy=function(){var e=this;e.unbindDocument(!0),e.ids={},e.index=0,e.collections.forEach(function(e){e.destroy()}),e.off()},n.prototype.onDestroyed=function(e,t){var i=this;if(i.collections.indexOf(t)<0)return!1;i.collections.splice(i.collections.indexOf(t),1)};var l=new n;return{create:function(e){return l.create(e)},factory:l}});