-
Notifications
You must be signed in to change notification settings - Fork 1
/
rat.js
104 lines (90 loc) · 2.22 KB
/
rat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
$(document).ready(function(){
poll();
setInterval("poll()",1000);
$('#output').css({
width: $(window).width() + 'px',
height: $(window).height() - 68 + 'px'
});
$('#command').css({
width: $(window).width() + 'px'
});
$('#wrapper').css({
width: $(window).width() + 'px',
height: $(window).height() - 12 + 'px'
});
$(window).resize(function(){
$('#output').css({
width: $(window).width() + 'px',
height: $(window).height() - 68 + 'px'
});
$('#command').css({
width: $(window).width() + 'px'
});
$('#wrapper').css({
width: $(window).width() + 'px',
height: $(window).height() - 12 + 'px'
});
});
});
function poll() {
$.get('update.php', function(data) {
var val = $('#output').html();
$('#output').html(data);
if (val !== $('#output').html()) {
var textarea = document.getElementById("output");
textarea.scrollTop = textarea.scrollHeight;
// Work around Chrome's little problem
window.setTimeout(function() {
textarea.scrollTop = textarea.scrollHeight;
}, 1);
}
});
}
function fixSelection() {
var c = document.getElementById('command').selectionStart;
if (c < 2) {
document.getElementById('command').selectionStart = 2;
document.getElementById('command').selectionEnd = 2;
}
}
function preventBackspace(e) {
var c = document.getElementById('command').selectionStart;
if (c > 2) return true;
var evt = e || window.event;
if (evt) {
var keyCode = evt.charCode || evt.keyCode;
if (keyCode === 8) {
if (evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
}
}
}
function enter(e) {
var c = document.getElementById('command').selectionStart;
if (c < 2) {
return false;
}
if (e.keyCode == 13) {
send();
return false;
}
}
function send() {
var id = $('#id').val();
var command = $('#command').val();
$.get("send.php", { command: command } );
$('#command').val(">>");
}
function moveCaretToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
}