!function(i){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=i();else if("function"==typeof define&&define.amd)define([],i);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.nipplejs=i()}}(function(){var i,t=!!("ontouchstart"in window),e=window.PointerEvent?!0:!1,n=window.MSPointerEvent?!0:!1,o={touch:{start:"touchstart",move:"touchmove",end:"touchend"},mouse:{start:"mousedown",move:"mousemove",end:"mouseup"},pointer:{start:"pointerdown",move:"pointermove",end:"pointerup"},MSPointer:{start:"MSPointerDown",move:"MSPointerMove",end:"MSPointerUp"}},s={},r={};e?i=o.pointer:n?i=o.MSPointer:t?(i=o.touch,r=o.mouse):i=o.mouse;var p={};p.distance=function(i,t){var e=t.x-i.x,n=t.y-i.y;return Math.sqrt(e*e+n*n)},p.angle=function(i,t){var e=t.x-i.x,n=t.y-i.y;return p.degrees(Math.atan2(n,e))},p.findCoord=function(i,t,e){var n={x:0,y:0};return e=p.radians(e),n.x=i.x-t*Math.cos(e),n.y=i.y-t*Math.sin(e),n},p.radians=function(i){return i*(Math.PI/180)},p.degrees=function(i){return i*(180/Math.PI)},p.bindEvt=function(i,t,e){i.addEventListener?i.addEventListener(t,e,!1):i.attachEvent&&i.attachEvent(t,e)},p.unbindEvt=function(i,t,e){i.removeEventListener?i.removeEventListener(t,e):i.detachEvent&&i.detachEvent(t,e)},p.trigger=function(i,t,e){var n=new CustomEvent(t,e);i.dispatchEvent(n)},p.prepareEvent=function(i){return i.preventDefault(),t?i.changedTouches:i},p.getScroll=function(){var i=void 0!==window.pageXOffset?window.pageXOffset:(document.documentElement||document.body.parentNode||document.body).scrollLeft,t=void 0!==window.pageYOffset?window.pageYOffset:(document.documentElement||document.body.parentNode||document.body).scrollTop;return{x:i,y:t}},p.applyPosition=function(i,t){i.style.left=t.x+"px",i.style.top=t.y+"px"};var h=function(){this.handlers={}};h.prototype.on=function(i,t){for(var e,n=this,o=i.split(/[ ,]+/g),s=0;s=0&&e.handlers[i].splice(e.handlers[i].indexOf(t),1),e},h.prototype.trigger=function(i,t){for(var e,n=this,o=i.split(/[ ,]+/g),s=0;ss&&3*s>o?"up":o>-s&&s>=o?"left":o>3*-s&&-s>=o?"down":"right",e=o>-r&&r>o?"left":"right",n=o>0?"up":"down",i.force>this.options.threshold){var p={};for(var h in this.direction)this.direction.hasOwnProperty(h)&&(p[h]=this.direction[h]);var d=!0;this.direction={x:e,y:n,angle:t},i.direction=this.direction;for(var h in p)p[h]!==this.direction[h]&&(d=!1);if(d)return;(p.x!==this.direction.x||p.y!==this.direction.y)&&(this.trigger("plain",i),this.manager.trigger("plain "+this.identifier+":plain",i)),p.x!==this.direction.x&&(this.trigger("plain:"+e,i),this.manager.trigger("plain:"+e+" "+this.identifier+":plain:"+e,i)),p.y!==this.direction.y&&(this.trigger("plain:"+n,i),this.manager.trigger("plain:"+n+" "+this.identifier+":plain:"+n,i)),p.angle!==this.direction.angle&&(this.trigger("dir dir:"+t,i),this.manager.trigger("dir dir:"+t+" "+this.identifier+":dir "+this.identifier+":dir:"+t,i))}};var a=function(i){var t=this;return t.config(i),t.nipples=[],t.bindEvt(t.options.zone,"start"),t.nipples.on=t.on.bind(t),t.nipples.off=t.off.bind(t),t.nipples.options=t.options,t.nipples.get=function(i){for(var e=0,n=t.nipples.length;n>e;e+=1)if(t.nipples[e].identifier===i)return t.nipples[e]},this.nipples};return a.prototype=new h,a.prototype.config=function(i){this.options={},this.nippleOptions={},this.options.zone=document.body,this.options.multitouch=!1,this.options.maxNumberOfNipples=1,this.nippleOptions.size=100,this.nippleOptions.threshold=.1,this.nippleOptions.color="white",this.nippleOptions.fadeTime=250;for(var t in i)this.options.hasOwnProperty(t)?this.options[t]=i[t]:this.nippleOptions.hasOwnProperty(t)&&(this.nippleOptions[t]=i[t]);return this},a.prototype.bindEvt=function(t,e){var n=this;return s[e]=function(){n["on"+e].apply(n,arguments)},p.bindEvt(t,i[e],s[e]),r[e]&&p.bindEvt(t,r[e],s[e]),n},a.prototype.unbindEvt=function(t,e){return p.unbindEvt(t,i[e],s[e]),s[e]=void 0,this},a.prototype.onstart=function(i){if(i=p.prepareEvent(i),this.box=this.options.zone.getBoundingClientRect(),i.length&&this.options.multitouch&&this.nipples.lengtht;t+=1)this.processOnStart(i[t]);else{if(0!==this.nipples.length)return!1;this.processOnStart(i[0]||i)}return this.started||(this.bindEvt(document,"move").bindEvt(document,"end"),this.started=!0),!1},a.prototype.processOnStart=function(i){var t=(void 0!==i.identifier?i.identifier:i.pointerId)||0;if(!this.nipples.get(t)){var e=p.getScroll(),n={x:i.pageX,y:i.pageY},o={x:n.x-(e.x+this.box.left+this.nippleOptions.size/2),y:n.y-(e.y+this.box.top+this.nippleOptions.size/2)},s={x:this.nippleOptions.size/4,y:this.nippleOptions.size/4},r=new d(this,{color:this.nippleOptions.color,size:this.nippleOptions.size,threshold:this.nippleOptions.threshold,fadeTime:this.nippleOptions.fadeTime,identifier:t,position:n,backPosition:o,frontPosition:s});p.applyPosition(r.ui.el,r.backPosition),p.applyPosition(r.ui.front,r.frontPosition),r.show(),this.nipples.push(r),this.trigger("added "+t+":added",r),r.trigger("start",r),this.trigger("start "+t+":start",r)}},a.prototype.onmove=function(i){i=p.prepareEvent(i);var t=[];if(i.length&&this.options.multitouch)for(var e=0,n=i.length;n>e;e+=1)t.push(this.processOnMove(i[e]));else t.push(this.processOnMove(i[0]||i));return!1},a.prototype.processOnMove=function(i){var t=(void 0!==i.identifier?i.identifier:i.pointerId)||0,e=this.nipples.get(t);if(!e)return console.error("MOVE: Couldn't find the nipple n°"+t+"."),void console.error(this.nipples);var n=e.options.size/2,o={x:i.pageX,y:i.pageY},s=p.distance(o,e.position),r=p.angle(o,e.position),h=p.radians(r),d=s/n;s>n&&(s=n,o=p.findCoord(e.position,s,r)),e.frontPosition={x:o.x-e.position.x+e.options.size/4,y:o.y-e.position.y+e.options.size/4},p.applyPosition(e.ui.front,e.frontPosition);var a={identifier:e.identifier,position:o,force:d,pressure:i.force||i.pressure||i.webkitForce,distance:s,angle:{radian:h,degree:r},instance:e};return e.computeDirection(a),a.angle={radian:p.radians(180-r),degree:180-r},e.trigger("move",a),this.trigger("move "+t+":move",a),a},a.prototype.onend=function(i){if(i=p.prepareEvent(i),i.length&&this.options.multitouch)for(var t=0,e=i.length;e>t;t+=1)this.processOnEnd(i[t]);else this.processOnEnd(i[0]||i);return this.nipples.length||(this.unbindEvt(document,"move").unbindEvt(document,"end"),this.started=!1),!1},a.prototype.processOnEnd=function(i){var t=(void 0!==i.identifier?i.identifier:i.pointerId)||0,e=this,n=e.nipples.get(t);if(!n)return console.error("END: Couldn't find the nipple n°"+t+"."),void console.error(e.nipples);n.hide(function(){n.trigger("removed",n),e.trigger("removed "+t+":removed",n)}),n.trigger("end",n),e.trigger("end "+t+":end",n);var o=e.nipples.indexOf(n);e.nipples.splice(o,1)},{create:function(i){return new a(i)}}});