forked from netguy204/imp.el
-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.html
114 lines (101 loc) · 2.75 KB
/
index.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
<!DOCTYPE html>
<meta charset="utf-8">
<script type="text/javascript" src="/imp/static/jquery.js"></script>
<style type="text/css">
html {
overflow: auto;
}
html, body, div, iframe {
margin: 0px;
padding: 0px;
height: 100%;
border: none;
}
iframe {
display: block;
width: 100%;
border: none;
overflow-y: auto;
overflow-x: hidden;
}
</style>
<iframe id="content"
name="content"
src="/imp/static/loading.html"
frameborder="0"
marginheight="0"
marginwidth="0"
width="100%"
height="100%"
scrolling="auto"
content="text/html;charset=UTF-8">
</iframe>
<script type="text/javascript">
var buffer = window.location.pathname.split('/')[3];
var max_period = 60000;
var min_period = 1000;
var next_period = min_period;
var alpha = 1.2;
var current_id = '-1';
$('head').append($('<title/>').text(decodeURI(buffer)));
var nextTimeout = function() {
var next = next_period;
next_period = Math.min(max_period, next_period * alpha);
return next;
};
var resetTimeout = function() {
next_period = min_period;
};
var frameToDocument = function(iframe) {
return (iframe.contentDocument) ? iframe.contentDocument : iframe.Document;
};
var printIframe = function(data) {
var iframeJQ = $('#content');
var doc = frameToDocument(iframeJQ[0]);
var iwindow = iframeJQ[0].contentWindow;
var offX = iwindow.pageXOffset, offY = iwindow.pageYOffset;
if (offY && offY >= $(doc.body).height() - $(iwindow).height()) {
offY = null; // follow the end of the buffer
}
doc.open();
doc.write(data);
doc.close();
iwindow.scrollTo(offX, offY != null ? offY : $(doc.body).height());
};
var setIframe = function(count, newText) {
if(!count) {
// error parsing client result
printIframe('0', 'error parsing the response from emacs');
} else {
current_id = count;
printIframe(newText);
}
};
var refresh = function() {
var url = "/imp/buffer/" + buffer;
var gotData = function(data, status, xhr) {
resetTimeout();
setIframe(xhr.getResponseHeader("X-Imp-Count"), data);
refresh();
};
var errorRetry = function() {
setTimeout(refresh, nextTimeout());
};
$.get(url + '?id=' + current_id, gotData).error(errorRetry);
};
$(document).ready(function() {
var iframeJQ = $('#content');
iframeJQ.load(function() {
// now we need to tweak the stylesheet links so that firefox will
// refresh them properly
$('link', frameToDocument(iframeJQ[0])).each(function(index, el) {
var href = $(el).attr('href');
// Only refresh impatient-mode hosted content
if(href && !/^[a-zA-z]+:\/\//.exec(href)) {
$(el).attr('href', $(el).attr('href') + '?' + new Date().getTime());
}
});
});
refresh();
});
</script>