-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.html
187 lines (154 loc) · 5.51 KB
/
view.html
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<html>
<head>
<style type="text/css">
<!--
body {
font-family: Helvetica, Tahoma, Arial;
font-size: 12px;
}
#file_canvas {
display: block;
width: 100%;
height: 90%;
}
#text_frame {
font-size: 9px;
display: block;
width: 100%;
height: 100%;
border: 1px solid gray;
}
-->
</style>
<script>
function $(id) { return document.getElementById(id) };
// From: http://thomas.bindzus.me/2007/12/24/adding-dynamic-contents-to-iframes/
// Props to Thomas Bindzus
function IFrame(parentElement)
{
// Create the iframe which will be returned
var iframe = document.createElement("iframe");
// If no parent element is specified then use body as the parent element
if(parentElement == null)
parentElement = document.body;
// This is necessary in order to initialize the document inside the iframe
parentElement.appendChild(iframe);
// Initiate the iframe's document to null
iframe.doc = null;
// Depending on browser platform get the iframe's document, this is only
// available if the iframe has already been appended to an element which
// has been added to the document
if(iframe.contentDocument)
// Firefox, Opera
iframe.doc = iframe.contentDocument;
else if(iframe.contentWindow)
// Internet Explorer
iframe.doc = iframe.contentWindow.document;
else if(iframe.document)
// Others?
iframe.doc = iframe.document;
// If we did not succeed in finding the document then throw an exception
if(iframe.doc == null)
throw "Document not found, append the parent element to the DOM before creating the IFrame";
// Create the script inside the iframe's document which will call the
iframe.doc.open();
iframe.doc.close();
// Return the iframe, now with an extra property iframe.doc containing the
// iframe's document
return iframe;
}
// Initialize XMLHTTPRequest handle
var xmlhttp = false;
var running = false;
var current_line = 0;
var updateInterval = 1000;
var box_iframe = null;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}
function start_tail() {
if(!running) {
running = true;
load_lines();
}
$("start_button").disabled = true;
$("stop_button").disabled = false;
}
function stop_tail() {
running = false;
$("start_button").disabled = false;
$("stop_button").disabled = true;
}
function add_lines(text) {
var text_box = box_iframe.doc.getElementById("text_box");
if(text != "") {
text_box.innerHTML += text + '\n';
current_line += text.split('\n').length
}
setTimeout(load_lines, updateInterval);
if($("autoscroll").value) {
// Ack! Does not work on Firefox!
box_iframe.scrollTo(0, box_iframe.doc.body.scrollHeight);
}
}
function load_lines() {
if(!running) {
return;
}
xmlhttp.open("GET", "http://HOST_ADDRESS/tail?file=FILE_NAME&start_line=" + current_line, true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
add_lines(xmlhttp.responseText);
}
}
xmlhttp.send(null);
}
</script>
</head>
<body>
<!-- Controls -->
File: <span id="file_name">FILE_NAME</span>
<div style="float:right">
<input id="autoscroll" type="checkbox"/>Autoscroll</input>
<input id="start_at_end" type="checkbox" value="true" disabled="true"/>Start at end</input>
<button id="start_button" onClick="start_tail()">Start tail -f</button>
<button id="stop_button" disabled="true" onClick="stop_tail()">Stop</button>
</div>
<br> <br>
<!-- Text frame -->
<div id="file_canvas"></div>
<!-- <iframe id="text_frame"></iframe>-->
<script>
box_iframe = IFrame(document.getElementById("file_canvas"));
box_iframe.id = "text_frame";
var text_box = box_iframe.doc.createElement("pre");
text_box.id = "text_box";
box_iframe.doc.body.appendChild(text_box);
</script>
</body>
</html>