app/assets/javascripts/turtle.js
// Hence, we use the `CodeOceanEditorWebsocket.websocket`
Hence, we use the `CodeOceanEditorWebsocket.websocket`
Hence we use the ` CodeOceanEditorWebsocket . websocket `
function Turtle(unused_pipe_reference, canvas) {
    var dx, dy, xpos, ypos;
    this.canvas = canvas; 
    this.items = [];
    this.canvas.off('click');
    let sendEvent = function (x, y) {
        CodeOceanEditorWebsocket.websocket.send(JSON.stringify({
            'cmd': 'canvasevent',
            'type': '<Button-1>',
            'x': x,
            'y': y
        }));
        CodeOceanEditorWebsocket.websocket.send('\n');
    };
    this.handleArrowKeys = function(e) {
        if (!CodeOceanEditorWebsocket.websocket ||
            CodeOceanEditorWebsocket.websocket.getReadyState() !== WebSocket.OPEN) {
            return;
        }
        switch(e.which) {
            case 37: 
                sendEvent(140, 160);
                break;
            case 38: 
                sendEvent(160, 140);
                break;
            case 39: 
                sendEvent(180, 160);
                break;
            case 40: 
                sendEvent(160, 180);
                break;
            default: return; 
        }
        e.preventDefault(); 
    }
    $(document).keydown(this.handleArrowKeys);
    this.canvas.click(function (e) {
        if (e.eventPhase !== 2) {
            return;
        }
        e.stopPropagation();
        dx = this.width / (2 * devicePixelRatio);
        dy = this.height / (2 * devicePixelRatio);
        if(e.offsetX===undefined)
        {
            var offset = canvas.offset();
            xpos = e.pageX-offset.left;
            ypos = e.pageY-offset.top;
        }
        else
        {
            xpos = e.offsetX;
            ypos = e.offsetY;
        }
        sendEvent(xpos - dx, ypos - dy);
    });
}
function Turtle ( unused_pipe_reference , canvas ) { var dx , dy , xpos , ypos ; this . canvas = canvas ; this . items = [ ] ; this . canvas . off ( 'click' ) ; let sendEvent = function ( x , y ) { CodeOceanEditorWebsocket . websocket . send ( JSON . stringify ( { 'cmd' : 'canvasevent' , 'type' : '<Button-1>' , 'x' : x , 'y' : y } ) ) ; CodeOceanEditorWebsocket . websocket . send ( '\n' ) ; } ; this . handleArrowKeys = function ( e ) { if ( ! CodeOceanEditorWebsocket . websocket || CodeOceanEditorWebsocket . websocket . getReadyState ( ) !== WebSocket . OPEN ) { return ; } switch ( e . which ) { case 37 : sendEvent ( 140 , 160 ) ; break ; case 38 : sendEvent ( 160 , 140 ) ; break ; case 39 : sendEvent ( 180 , 160 ) ; break ; case 40 : sendEvent ( 160 , 180 ) ; break ; default : return ; } e . preventDefault ( ) ; } $ ( document ) . keydown ( this . handleArrowKeys ) ; this . canvas . click ( function ( e ) { if ( e . eventPhase !== 2 ) { return ; } e . stopPropagation ( ) ; dx = this . width / ( 2 * devicePixelRatio ) ; dy = this . height / ( 2 * devicePixelRatio ) ; if ( e . offsetX === undefined ) { var offset = canvas . offset ( ) ; xpos = e . pageX - offset . left ; ypos = e . pageY - offset . top ; } else { xpos = e . offsetX ; ypos = e . offsetY ; } sendEvent ( xpos - dx , ypos - dy ) ; } ) ; }
Hence, we use the `CodeOceanEditorWebsocket.websocket`
Hence we use the ` CodeOceanEditorWebsocket . websocket `
// jQuery object // left // up // right // down // exit this handler for other keys // prevent the default action (scroll / move caret)