text: /*
   * CUSTOM:
   * - Instead of getting the default canvas to render the controller i'm using
   *   one that contains the id 'scaled'
   */
  !function(t){function e(t,i){var o,s,n,r,a,h=1,l=!0;if("boolean"==typeof t&&(l=t,h=2),o=i)for(s in o)i=t[s],n=o[s],t!==n&&(l&&("object"==typeof n||(r="[object Array]"===Object.prototype.toString.call(n)))?(r?(r=!1,a=i&&"[object Array]"===Object.prototype.toString.call(i)?i:[]):a=i&&"object"==typeof i?i:{},t[s]=e(a,n)):"undefined"!=typeof n&&(t[s]=n));return t}var i=([].slice,{}.hasOwnProperty),o=function(t,e){function o(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return o.prototype=e.prototype,t.prototype=new o,t.__super__=e.prototype,t};t.GameController={options:{left:{type:"dpad",position:{left:"13%",bottom:"22%"},dpad:{up:{width:"7%",height:"15%",stroke:2,touchStart:function(){GameController.simulateKeyEvent("press",38),GameController.simulateKeyEvent("down",38)},touchEnd:function(){GameController.simulateKeyEvent("up",38)}},left:{width:"15%",height:"7%",stroke:2,touchStart:function(){GameController.simulateKeyEvent("press",37),GameController.simulateKeyEvent("down",37)},touchEnd:function(){GameController.simulateKeyEvent("up",37)}},down:{width:"7%",height:"15%",stroke:2,touchStart:function(){GameController.simulateKeyEvent("press",40),GameController.simulateKeyEvent("down",40)},touchEnd:function(){GameController.simulateKeyEvent("up",40)}},right:{width:"15%",height:"7%",stroke:2,touchStart:function(){GameController.simulateKeyEvent("press",39),GameController.simulateKeyEvent("down",39)},touchEnd:function(){GameController.simulateKeyEvent("up",39)}}},joystick:{radius:60,touchMove:function(t){console.log(t)}}},right:{type:"buttons",position:{right:"17%",bottom:"28%"},buttons:[{offset:{x:"-13%",y:0},label:"X",radius:"7%",stroke:2,backgroundColor:"blue",fontColor:"#fff",touchStart:function(){GameController.simulateKeyEvent("press",88),GameController.simulateKeyEvent("down",88)},touchEnd:function(){GameController.simulateKeyEvent("up",88)}},{offset:{x:0,y:"-11%"},label:"Y",radius:"7%",stroke:2,backgroundColor:"yellow",fontColor:"#fff",touchStart:function(){GameController.simulateKeyEvent("press",70),GameController.simulateKeyEvent("down",70)},touchEnd:function(){GameController.simulateKeyEvent("up",70)}},{offset:{x:"13%",y:0},label:"B",radius:"7%",stroke:2,backgroundColor:"red",fontColor:"#fff",touchStart:function(){GameController.simulateKeyEvent("press",90),GameController.simulateKeyEvent("down",90)},touchEnd:function(){GameController.simulateKeyEvent("up",90)}},{offset:{x:0,y:"11%"},label:"A",radius:"7%",stroke:2,backgroundColor:"green",fontColor:"#fff",touchStart:function(){GameController.simulateKeyEvent("press",67),GameController.simulateKeyEvent("down",67)},touchEnd:function(){GameController.simulateKeyEvent("up",67)}}],dpad:{up:{width:"7%",height:"15%",stroke:2},left:{width:"15%",height:"7%",stroke:2},down:{width:"7%",height:"15%",stroke:2},right:{width:"15%",height:"7%",stroke:2}},joystick:{radius:60,touchMove:function(t){console.log(t)}}},touchRadius:45},touchableAreas:[],touchableAreasCount:0,touches:[],offsetX:0,offsetY:0,bound:{left:!1,right:!1,top:!1,bottom:!1},cachedSprites:{},paused:!1,init:function(t){if(!(!1 in document.documentElement)){t=t||{},e(this.options,t);var i=navigator.userAgent.toLowerCase();this.performanceFriendly=-1!==i.indexOf("iphone")||-1!==i.indexOf("android")||this.options.forcePerformanceFriendly;var o;this.options.canvas&&(o=document.getElementById("scaled"))?o&&(this.options.canvas=o):this.options.canvas=document.getElementById("scaled"),this.options.ctx=this.options.canvas.getContext("2d"),this.createOverlayCanvas()}},boundingSet:function(t){if(t.width)var e=this.getPixels(t.width),i=this.getPixels(t.height),o=this.getPixels(t.x),s=this.getPixels(t.y);else{if(this.options.touchRadius)var n=2*this.getPixels(t.radius)+this.getPixels(this.options.touchRadius)/2;else var n=t.radius;var e=i=2*(n+this.getPixels(t.stroke)),o=this.getPixels(t.x)-e/2,s=this.getPixels(t.y)-i/2}var r=o+e,a=s+i;(this.bound.left===!1||o<this.bound.left)&&(this.bound.left=o),(this.bound.right===!1||r>this.bound.right)&&(this.bound.right=r),(this.bound.top===!1||s<this.bound.top)&&(this.bound.top=s),(this.bound.bottom===!1||a>this.bound.bottom)&&(this.bound.bottom=a)},createOverlayCanvas:function(){this.canvas=document.createElement("canvas"),this.resize(!0),document.getElementsByTagName("body")[0].appendChild(this.canvas),this.ctx=this.canvas.getContext("2d");var t=this;window.addEventListener("resize",function(){setTimeout(function(){GameController.resize.call(t)},1)}),this.setTouchEvents(),this.loadSide("left"),this.loadSide("right"),this.render(),this.touches&&0!=this.touches.length||(this.paused=!0)},pixelRatio:1,resize:function(t){this.canvas.width=this.options.canvas.width,this.canvas.height=this.options.canvas.height,this.offsetX=GameController.options.canvas.offsetLeft+document.body.scrollLeft,this.offsetY=GameController.options.canvas.offsetTop+document.body.scrollTop,this.options.canvas.style.width&&this.options.canvas.style.height&&-1!==this.options.canvas.style.height.indexOf("px")&&(this.canvas.style.width=this.options.canvas.style.width,this.canvas.style.height=this.options.canvas.style.height,this.pixelRatio=this.canvas.width/parseInt(this.canvas.style.width)),this.canvas.style.position="absolute",this.canvas.style.zIndex="5",this.canvas.style.left=this.options.canvas.offsetLeft+"px",this.canvas.style.top=this.options.canvas.offsetTop+"px",this.canvas.setAttribute("style",this.canvas.getAttribute("style")+" -ms-touch-action: none;"),t||(this.touchableAreas=[],this.cachedSprites=[],this.reloadSide("left"),this.reloadSide("right"))},getPixels:function(t,e){return"undefined"==typeof t?0:"number"==typeof t?t:"x"==e?parseInt(t)/100*this.canvas.width:parseInt(t)/100*this.canvas.height},simulateKeyEvent:function(t,e){if("undefined"==typeof window.onkeydown)return!1;if("undefined"!=typeof jQuery){var i=jQuery.Event("key"+t);return i.ctrlKey=!1,i.which=e,i.keyCode=e,void $(this.options.canvas).trigger(i)}var o=document.createEvent("KeyboardEvent");-1!==navigator.userAgent.toLowerCase().indexOf("chrome")&&(Object.defineProperty(o,"keyCode",{get:function(){return this.keyCodeVal}}),Object.defineProperty(o,"which",{get:function(){return this.keyCodeVal}})),o.initKeyboardEvent?o.initKeyboardEvent("key"+t,!0,!0,document.defaultView,!1,!1,!1,!1,e,e):o.initKeyEvent("key"+t,!0,!0,document.defaultView,!1,!1,!1,!1,e,e),o.keyCodeVal=e},setTouchEvents:function(){var t=this,e=function(e){t.paused&&(t.paused=!1),e.preventDefault(),window.navigator.msPointerEnabled&&e.clientX&&e.pointerType==e.MSPOINTER_TYPE_TOUCH?t.touches[e.pointerId]={clientX:e.clientX,clientY:e.clientY}:t.touches=e.touches||[]};this.canvas.addEventListener("touchstart",e,!1);var i=function(e){e.preventDefault(),window.navigator.msPointerEnabled&&e.pointerType==e.MSPOINTER_TYPE_TOUCH?delete t.touches[e.pointerId]:t.touches=e.touches||[],e.touches&&0!=e.touches.length||(t.render(),t.paused=!0)};this.canvas.addEventListener("touchend",i);var o=function(e){e.preventDefault(),window.navigator.msPointerEnabled&&e.clientX&&e.pointerType==e.MSPOINTER_TYPE_TOUCH?t.touches[e.pointerId]={clientX:e.clientX,clientY:e.clientY}:t.touches=e.touches||[]};this.canvas.addEventListener("touchmove",o),window.navigator.msPointerEnabled&&(this.canvas.addEventListener("MSPointerDown",e),this.canvas.addEventListener("MSPointerUp",i),this.canvas.addEventListener("MSPointerMove",o))},addTouchableDirection:function(t){var e=new n(t);e.id=this.touchableAreas.push(e),this.touchableAreasCount++,this.boundingSet(t)},addJoystick:function(t){var e=new a(t);e.id=this.touchableAreas.push(e),this.touchableAreasCount++,this.boundingSet(t)},addButton:function(t){var e=new r(t);e.id=this.touchableAreas.push(e),this.touchableAreasCount++,this.boundingSet(t)},addTouchableArea:function(){},loadButtons:function(t){for(var e=this.options[t].buttons,i=0,o=e.length;o>i;i++)if("undefined"!=typeof e[i]&&"undefined"!=typeof e[i].offset){var s=this.getPositionX(t),n=this.getPositionY(t);e[i].x=s+this.getPixels(e[i].offset.x,"y"),e[i].y=n+this.getPixels(e[i].offset.y,"y"),this.addButton(e[i])}},loadDPad:function(t){var e=this.options[t].dpad||{},i=this.getPositionX(t),o=this.getPositionY(t);if(e.up&&e.left&&e.down&&e.right){var s={x:i,y:o,radius:e.right.height},n=new h(s);this.touchableAreas.push(n),this.touchableAreasCount++}e.up!==!1&&(e.up.x=i-this.getPixels(e.up.width,"y")/2,e.up.y=o-(this.getPixels(e.up.height,"y")+this.getPixels(e.left.height,"y")/2),e.up.direction="up",this.addTouchableDirection(e.up)),e.left!==!1&&(e.left.x=i-(this.getPixels(e.left.width,"y")+this.getPixels(e.up.width,"y")/2),e.left.y=o-this.getPixels(e.left.height,"y")/2,e.left.direction="left",this.addTouchableDirection(e.left)),e.down!==!1&&(e.down.x=i-this.getPixels(e.down.width,"y")/2,e.down.y=o+this.getPixels(e.left.height,"y")/2,e.down.direction="down",this.addTouchableDirection(e.down)),e.right!==!1&&(e.right.x=i+this.getPixels(e.up.width,"y")/2,e.right.y=o-this.getPixels(e.right.height,"y")/2,e.right.direction="right",this.addTouchableDirection(e.right))},loadJoystick:function(t){var e=this.options[t].joystick;e.x=this.getPositionX(t),e.y=this.getPositionY(t),this.addJoystick(e)},reloadSide:function(t){this.loadSide(t)},loadSide:function(t){"dpad"===this.options[t].type?this.loadDPad(t):"joystick"===this.options[t].type?this.loadJoystick(t):"buttons"===this.options[t].type&&this.loadButtons(t)},normalizeTouchPositionX:function(t){return(t-this.offsetX)*this.pixelRatio},normalizeTouchPositionY:function(t){return(t-this.offsetY)*this.pixelRatio},getXFromRight:function(t){return this.canvas.width-t},getYFromBottom:function(t){return this.canvas.height-t},getPositionX:function(t){return"undefined"!=typeof this.options[t].position.left?this.getPixels(this.options[t].position.left,"x"):this.getXFromRight(this.getPixels(this.options[t].position.right,"x"))},getPositionY:function(t){return"undefined"!=typeof this.options[t].position.top?this.getPixels(this.options[t].position.top,"y"):this.getYFromBottom(this.getPixels(this.options[t].position.bottom,"y"))},renderAreas:function(){for(var t=0,e=this.touchableAreasCount;e>t;t++){var i=this.touchableAreas[t];if("undefined"!=typeof i){i.draw();for(var o=!1,s=0,n=this.touches.length;n>s;s++){var r=this.touches[s];if("undefined"!=typeof r){var a=this.normalizeTouchPositionX(r.clientX),h=this.normalizeTouchPositionY(r.clientY);i.check(a,h)!==!1&&(o||(o=this.touches[s]))}}o?(i.active||i.touchStartWrapper(o),i.touchMoveWrapper(o)):i.active&&i.touchEndWrapper(o)}}},render:function(){if(this.paused&&this.performanceFriendly||this.ctx.clearRect(this.bound.left,this.bound.top,this.bound.right-this.bound.left,this.bound.bottom-this.bound.top),!this.paused&&!this.performanceFriendly){var t="touch-circle",e=this.cachedSprites[t];if(!e&&this.options.touchRadius){var i=document.createElement("canvas"),o=i.getContext("2d");i.width=2*this.options.touchRadius,i.height=2*this.options.touchRadius;var s=this.options.touchRadius,n=o.createRadialGradient(s,s,1,s,s,this.options.touchRadius);n.addColorStop(0,"rgba( 200, 200, 200, 1 )"),n.addColorStop(1,"rgba( 200, 200, 200, 0 )"),o.beginPath(),o.fillStyle=n,o.arc(s,s,this.options.touchRadius,0,2*Math.PI,!1),o.fill(),e=GameController.cachedSprites[t]=i}for(var r=0,a=this.touches.length;a>r;r++){var h=this.touches[r];if("undefined"!=typeof h){var l=this.normalizeTouchPositionX(h.clientX),d=this.normalizeTouchPositionY(h.clientY);l-this.options.touchRadius>this.bound.left&&l+this.options.touchRadius<this.bound.right&&d-this.options.touchRadius>this.bound.top&&d+this.options.touchRadius<this.bound.bottom&&this.ctx.drawImage(e,l-this.options.touchRadius,d-this.options.touchRadius)}}}this.paused&&this.performanceFriendly||this.renderAreas(),window.requestAnimationFrame(this.renderWrapper)},renderWrapper:function(){GameController.render()}};var s=function(){function t(){}return t.prototype.touchStart=null,t.prototype.touchMove=null,t.prototype.touchEnd=null,t.prototype.type="area",t.prototype.id=!1,t.prototype.active=!1,t.prototype.setTouchStart=function(t){this.touchStart=t},t.prototype.touchStartWrapper=function(){this.touchStart&&this.touchStart(),this.active=!0},t.prototype.setTouchMove=function(t){this.touchMove=t},t.prototype.lastPosX=0,t.prototype.lastPosY=0,t.prototype.touchMoveWrapper=function(e){!this.touchMove||e.clientX==t.prototype.lastPosX&&e.clientY==t.prototype.lastPosY||(this.touchMove(),this.lastPosX=e.clientX,this.lastPosY=e.clientY),this.active=!0},t.prototype.setTouchEnd=function(t){this.touchEnd=t},t.prototype.touchEndWrapper=function(){this.touchEnd&&this.touchEnd(),this.active=!1,GameController.render()},t}(),n=function(t){function e(t){for(var e in t)this[e]="x"==e?GameController.getPixels(t[e],"x"):"y"==e||"height"==e||"width"==e?GameController.getPixels(t[e],"y"):t[e];this.draw()}return o(e,t),e.prototype.type="direction",e.prototype.check=function(t,e){return(Math.abs(t-this.x)<GameController.options.touchRadius/2||t>this.x)&&(Math.abs(t-(this.x+this.width))<GameController.options.touchRadius/2||t<this.x+this.width)&&(Math.abs(e-this.y)<GameController.options.touchRadius/2||e>this.y)&&(Math.abs(e-(this.y+this.height))<GameController.options.touchRadius/2||e<this.y+this.height)?!0:!1},e.prototype.draw=function(){var t=this.type+""+this.id+this.active,e=GameController.cachedSprites[t];if(!e){var i=document.createElement("canvas"),o=i.getContext("2d");i.width=this.width+2*this.stroke,i.height=this.height+2*this.stroke;var s=this.opacity||.9;switch(this.active||(s*=.5),this.direction){case"up":var n=o.createLinearGradient(0,0,0,this.height);n.addColorStop(0,"rgba( 0, 0, 0, "+.5*s+" )"),n.addColorStop(1,"rgba( 0, 0, 0, "+s+" )");break;case"left":var n=o.createLinearGradient(0,0,this.width,0);n.addColorStop(0,"rgba( 0, 0, 0, "+.5*s+" )"),n.addColorStop(1,"rgba( 0, 0, 0, "+s+" )");break;case"right":var n=o.createLinearGradient(0,0,this.width,0);n.addColorStop(0,"rgba( 0, 0, 0, "+s+" )"),n.addColorStop(1,"rgba( 0, 0, 0, "+.5*s+" )");break;case"down":default:var n=o.createLinearGradient(0,0,0,this.height);n.addColorStop(0,"rgba( 0, 0, 0, "+s+" )"),n.addColorStop(1,"rgba( 0, 0, 0, "+.5*s+" )")}o.fillStyle=n,o.fillRect(0,0,this.width,this.height),o.lineWidth=this.stroke,o.strokeStyle="rgba( 255, 255, 255, 0.1 )",o.strokeRect(0,0,this.width,this.height),e=GameController.cachedSprites[t]=i}GameController.ctx.drawImage(e,this.x,this.y)},e}(s),r=function(t){function e(t){for(var e in t)this[e]="x"==e?GameController.getPixels(t[e],"x"):"x"==e||"radius"==e?GameController.getPixels(t[e],"y"):t[e];this.draw()}return o(e,t),e.prototype.type="button",e.prototype.check=function(t,e){return Math.abs(t-this.x)<this.radius+GameController.options.touchRadius/2&&Math.abs(e-this.y)<this.radius+GameController.options.touchRadius/2?!0:!1},e.prototype.draw=function(){var t=this.type+""+this.id+this.active,e=GameController.cachedSprites[t];if(!e){var i=document.createElement("canvas"),o=i.getContext("2d");o.lineWidth=this.stroke,i.width=i.height=2*(this.radius+o.lineWidth);var s,n=o.createRadialGradient(this.radius,this.radius,1,this.radius,this.radius,this.radius);switch(this.backgroundColor){case"blue":n.addColorStop(0,"rgba(123, 181, 197, 0.6)"),n.addColorStop(1,"#105a78"),s="#0A4861";break;case"green":n.addColorStop(0,"rgba(29, 201, 36, 0.6)"),n.addColorStop(1,"#107814"),s="#085C0B";break;case"red":n.addColorStop(0,"rgba(165, 34, 34, 0.6)"),n.addColorStop(1,"#520101"),s="#330000";break;case"yellow":n.addColorStop(0,"rgba(219, 217, 59, 0.6)"),n.addColorStop(1,"#E8E10E"),s="#BDB600";break;case"white":default:n.addColorStop(0,"rgba( 255,255,255,.3 )"),n.addColorStop(1,"#eee")}o.fillStyle=this.active?s:n,o.strokeStyle=s,o.beginPath(),o.arc(i.width/2,i.width/2,this.radius,0,2*Math.PI,!1),o.fill(),o.stroke(),this.label&&(o.fillStyle=s,o.font="bold "+(this.fontSize||.35*i.height)+"px Verdana",o.textAlign="center",o.textBaseline="middle",o.fillText(this.label,i.height/2+2,i.height/2+2),o.fillStyle=this.fontColor,o.font="bold "+(this.fontSize||.35*i.height)+"px Verdana",o.textAlign="center",o.textBaseline="middle",o.fillText(this.label,i.height/2,i.height/2)),e=GameController.cachedSprites[t]=i}GameController.ctx.drawImage(e,this.x,this.y)},e}(s),a=function(t){function e(t){for(var e in t)this[e]=t[e];this.currentX=this.currentX||this.x,this.currentY=this.currentY||this.y}return o(e,t),e.prototype.type="joystick",e.prototype.check=function(t,e){return Math.abs(t-this.x)<this.radius+GameController.getPixels(GameController.options.touchRadius)/2&&Math.abs(e-this.y)<this.radius+GameController.getPixels(GameController.options.touchRadius)/2?!0:!1},e.prototype.moveDetails={},e.prototype.touchMoveWrapper=function(t){this.currentX=GameController.normalizeTouchPositionX(t.clientX),this.currentY=GameController.normalizeTouchPositionY(t.clientY),this.touchMove&&this.moveDetails.dx!=this.currentX-this.x&&this.moveDetails.dy!=this.y-this.currentY&&(this.moveDetails.dx=this.currentX-this.x,this.moveDetails.dy=this.y-this.currentY,this.moveDetails.max=this.radius+GameController.options.touchRadius/2,this.moveDetails.normalizedX=this.moveDetails.dx/this.moveDetails.max,this.moveDetails.normalizedY=this.moveDetails.dy/this.moveDetails.max,this.touchMove(this.moveDetails)),this.active=!0},e.prototype.draw=function(){if(!this.id)return!1;var t=this.type+""+this.id+this.active,e=GameController.cachedSprites[t];if(!e){var i=document.createElement("canvas");this.stroke=this.stroke||2,i.width=i.height=2*(this.radius+GameController.options.touchRadius+this.stroke);var o=i.getContext("2d");if(o.lineWidth=this.stroke,this.active){var s=o.createRadialGradient(0,0,1,0,0,this.radius);s.addColorStop(0,"rgba( 200,200,200,.5 )"),s.addColorStop(1,"rgba( 200,200,200,.9 )"),o.strokeStyle="#000"}else{var s=o.createRadialGradient(0,0,1,0,0,this.radius);s.addColorStop(0,"rgba( 200,200,200,.2 )"),s.addColorStop(1,"rgba( 200,200,200,.4 )"),o.strokeStyle="rgba( 0,0,0,.4 )"}o.fillStyle=s,o.beginPath(),o.arc(this.radius,this.radius,this.radius,0,2*Math.PI,!1),o.fill(),o.stroke(),e=GameController.cachedSprites[t]=i}GameController.ctx.fillStyle="#444",GameController.ctx.beginPath(),GameController.ctx.arc(this.x,this.y,.7*this.radius,0,2*Math.PI,!1),GameController.ctx.fill(),GameController.ctx.stroke(),GameController.ctx.drawImage(e,this.currentX-this.radius,this.currentY-this.radius)},e}(s),h=function(t){function e(t){for(var e in t)this[e]="x"==e?GameController.getPixels(t[e],"x"):"x"==e||"radius"==e?GameController.getPixels(t[e],"y"):t[e];this.draw()}return o(e,t),e.prototype.check=function(){return!1},e.prototype.draw=function(){GameController.ctx.fillStyle="rgba( 0, 0, 0, 0.5 )",GameController.ctx.beginPath(),GameController.ctx.arc(this.x,this.y,this.radius,0,2*Math.PI,!1),GameController.ctx.fill()},e}(s);!function(){if("undefined"==typeof module){for(var t=0,e=["ms","moz","webkit","o"],i=0;i<e.length&&!window.requestAnimationFrame;++i)window.requestAnimationFrame=window[e[i]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[e[i]+"CancelAnimationFrame"]||window[e[i]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(e){var i=(new Date).getTime(),o=Math.max(0,16-(i-t)),s=window.setTimeout(function(){e(i+o)},o);return t=i+o,s}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(t){clearTimeout(t)})}}()}("undefined"!=typeof module?module.exports:window);