Moved everything into new files. Made editor.js.erb really small.
This commit is contained in:
45
app/assets/javascripts/editor/turtle.js.erb
Normal file
45
app/assets/javascripts/editor/turtle.js.erb
Normal file
@@ -0,0 +1,45 @@
|
||||
CodeOceanEditorTurtle = {
|
||||
initTurtle: function () {
|
||||
this.turtlescreen = new Turtle(this.websocket, this.turtlecanvas);
|
||||
if ($('#run').isPresent()) {
|
||||
$('#run').bind('click', this.hideCanvas);
|
||||
}
|
||||
},
|
||||
|
||||
handleTurtleCommand: function (msg) {
|
||||
if (msg.action in this.turtlescreen) {
|
||||
var result = this.turtlescreen[msg.action].apply(this.turtlescreen, msg.args);
|
||||
this.websocket.send(JSON.stringify({cmd: 'result', 'result': result}));
|
||||
} else {
|
||||
this.websocket.send(JSON.stringify({cmd: 'exception', exception: 'AttributeError', message: msg.action}));
|
||||
}
|
||||
this.websocket.flush();
|
||||
},
|
||||
|
||||
handleTurtlebatchCommand: function (msg) {
|
||||
for (var i = 0; i < msg.batch.length; i++) {
|
||||
var cmd = msg.batch[i];
|
||||
this.turtlescreen[cmd[0]].apply(this.turtlescreen, cmd[1]);
|
||||
}
|
||||
},
|
||||
|
||||
showCanvas: function () {
|
||||
if ($('#turtlediv').isPresent()
|
||||
&& this.turtlecanvas.hasClass('hidden')) {
|
||||
// initialize two-column layout
|
||||
$('#output-col1').addClass('col-lg-7 col-md-7 two-column');
|
||||
this.turtlecanvas.removeClass('hidden');
|
||||
}
|
||||
},
|
||||
|
||||
hideCanvas: function () {
|
||||
if ($('#turtlediv').isPresent()
|
||||
&& !(this.turtlecanvas.hasClass('hidden'))) {
|
||||
var output = $('#output-col1');
|
||||
if (output.hasClass('two-column')) {
|
||||
output.removeClass('col-lg-7 col-md-7 two-column');
|
||||
}
|
||||
this.turtlecanvas.addClass('hidden');
|
||||
}
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user