2014-08-18 17:45:43 +04:00
|
|
|
var outputWS = new WebSocket(config.channel.editor + '/output/ws');
|
|
|
|
outputWS.onopen = function() {
|
|
|
|
console.log('[output onopen] connected');
|
|
|
|
};
|
|
|
|
outputWS.onmessage = function(e) {
|
|
|
|
console.log('[output onmessage]' + e.data);
|
|
|
|
var data = JSON.parse(e.data);
|
|
|
|
if ('init-output' !== data.cmd) {
|
|
|
|
$('#output').val($('#output').val() + data.output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
outputWS.onclose = function(e) {
|
|
|
|
console.log('[output onclose] disconnected (' + e.code + ')');
|
|
|
|
delete outputWS;
|
|
|
|
};
|
|
|
|
outputWS.onerror = function(e) {
|
|
|
|
console.log('[output onerror] ' + e);
|
|
|
|
};
|
|
|
|
|
|
|
|
var shellWS = new WebSocket(config.channel.shell + '/shell/ws');
|
|
|
|
shellWS.onopen = function() {
|
|
|
|
console.log('[shell onopen] connected');
|
|
|
|
};
|
|
|
|
shellWS.onmessage = function(e) {
|
|
|
|
console.log('[shell onmessage]' + e.data);
|
|
|
|
var data = JSON.parse(e.data);
|
|
|
|
if ('init-shell' !== data.cmd) {
|
|
|
|
$('#shellOutput').val(data.output);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
shellWS.onclose = function(e) {
|
|
|
|
console.log('[shell onclose] disconnected (' + e.code + ')');
|
|
|
|
delete shellWS;
|
|
|
|
};
|
|
|
|
shellWS.onerror = function(e) {
|
|
|
|
console.log('[shell onerror] ' + e);
|
|
|
|
};
|
|
|
|
|
|
|
|
var wide = {
|
2014-08-19 13:07:35 +04:00
|
|
|
curNode: "",
|
|
|
|
curEditor: "",
|
2014-08-18 17:45:43 +04:00
|
|
|
init: function() {
|
|
|
|
$('#shellInput').keydown(function(event) {
|
|
|
|
if (13 === event.which) {
|
|
|
|
var input = {
|
|
|
|
cmd: $('#shellInput').val()
|
|
|
|
};
|
|
|
|
shellWS.send(JSON.stringify(input));
|
|
|
|
$('#shellInput').val('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").bind("mousedown", function(event) {
|
|
|
|
if (!(event.target.id === "dirRMenu" || $(event.target).closest("#dirRMenu").length > 0)) {
|
|
|
|
$("#dirRMenu").hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(event.target.id === "fileRMenu" || $(event.target).closest("#fileRMenu").length > 0)) {
|
|
|
|
$("#fileRMenu").hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
save: function() {
|
|
|
|
var request = {
|
2014-08-19 13:07:35 +04:00
|
|
|
"file": wide.curNode.path,
|
|
|
|
"code": wide.curEditor.getValue()
|
2014-08-18 17:45:43 +04:00
|
|
|
};
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: '/save',
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
dataType: "json",
|
|
|
|
success: function(data) {
|
|
|
|
console.log(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
run: function() {
|
|
|
|
var request = {
|
2014-08-19 13:07:35 +04:00
|
|
|
"file": wide.curNode.path,
|
|
|
|
"code": wide.curEditor.getValue()
|
2014-08-18 17:45:43 +04:00
|
|
|
};
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: '/run',
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
dataType: "json",
|
|
|
|
beforeSend: function(data) {
|
|
|
|
$('#output').val('');
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
console.log(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fmt: function() {
|
|
|
|
var request = {
|
2014-08-19 13:07:35 +04:00
|
|
|
"file": wide.curNode.path,
|
|
|
|
"code": wide.curEditor.getValue(),
|
|
|
|
"cursorLine": wide.curEditor.getCursor().line,
|
|
|
|
"cursorCh": wide.curEditor.getCursor().ch
|
2014-08-18 17:45:43 +04:00
|
|
|
};
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: '/fmt',
|
|
|
|
data: JSON.stringify(request),
|
|
|
|
dataType: "json",
|
|
|
|
success: function(data) {
|
|
|
|
if (data.succ) {
|
2014-08-19 13:07:35 +04:00
|
|
|
wide.curEditor.setValue(data.code);
|
2014-08-18 17:45:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
wide.init();
|
|
|
|
tree.init();
|
|
|
|
});
|