Files
butterfly/app/static/javascripts/main.js

60 lines
1.5 KiB
JavaScript

// Generated by CoffeeScript 1.6.3
var cols, rows, term, ws;
term = ws = null;
cols = rows = null;
$(function() {
ws = new WebSocket('ws://' + document.location.host + '/ws');
ws.onopen = function() {
console.log("WebSocket open", arguments);
term = new Terminal({
visualBell: true,
screenKeys: true,
scrollback: -1
});
term.on("data", function(data) {
return ws.send('SH|' + data);
});
term.on("title", function(title) {
return document.title = title;
});
term.open($('main').get(0));
$('.terminal').attr('style', '');
return $(window).trigger('resize');
};
ws.onclose = function() {
if (term) {
term.destroy();
}
console.log("WebSocket closed", arguments);
return open('', '_self').close();
};
ws.onerror = function() {
return console.log("WebSocket error", arguments);
};
ws.onmessage = function(event) {
return term.write(event.data);
};
return $(window).resize(function() {
var $main, $termtest, $test, eh, ew, h, w;
$main = $('main');
$termtest = $('<div>').addClass('terminal');
$test = $('<div>').css({
display: 'inline'
}).text('0123456789');
$termtest.append($test);
$main.append($termtest);
ew = $test.outerWidth() / 10;
eh = $test.outerHeight();
$termtest.remove();
w = $main.outerWidth();
h = $main.outerHeight();
cols = Math.floor(w / ew) - 1;
rows = Math.floor(h / eh) - 1;
term.resize(cols, rows);
return ws.send("RS|" + cols + "," + rows);
});
});