-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmd-viewer.html
85 lines (75 loc) · 2.65 KB
/
md-viewer.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
<html>
<head><title>Markdown Viewer</title>
<link rel="stylesheet" type="text/css" href="./md-viewer.css" />
<script type="text/javascript" src="./Markdown.Converter.js"></script>
<script type="text/javascript">
var file = null;
var lastModifiedDate = null;
var paused = false;
function shouldReload() {
return file != null &&
(lastModifiedDate == null ||
file.lastModifiedDate.valueOf() != lastModifiedDate.valueOf()) &&
!paused;
}
function parseFile() {
if (shouldReload()) {
var rdr = new FileReader();
// Closure that returns a function closing over the file that has been loaded
rdr.onload = (function(fileToLoad) {
return function(fileLoadevent) {
var converter = new Markdown.Converter();
var html = converter.makeHtml(fileLoadevent.target.result);
document.getElementById('file-name').innerText = fileToLoad.name;
document.getElementById('output').innerHTML = html;
lastModifiedDate = fileToLoad.lastModifiedDate;
};
})(file);
rdr.readAsText(file);
}
var reloadDelay = document.getElementById('reload-delay-ms').value;
setTimeout(parseFile, reloadDelay);
}
function handleSelectFile(e) {
if (e.target.files[0] != null) {
file = e.target.files[0];
parseFile();
}
}
function windowOnLoad() {
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Everything we need is available
} else {
alert('The File APIs are not fully supported in this browser.');
}
document.getElementById('file').addEventListener('change', handleSelectFile, false);
}
function onClickPause() {
paused = !paused;
document.getElementById("pause-button").style.display = "none";
document.getElementById("resume-button").style.display = "inline";
return false;
}
function onClickResume() {
paused = !paused;
document.getElementById("pause-button").style.display = "inline";
document.getElementById("resume-button").style.display = "none";
return false;
}
window.onload = windowOnLoad;
</script>
</head>
<body>
<div id="header">
<div id="controls">
<input type="file" id="file" />
<label for="reload-delay-ms">Reload Delay:</label><input type="text" name="reload-delay-ms" id="reload-delay-ms" value="1000" />
<a href="#" title="Pause refreshing" id="pause-button" onclick="onClickPause()">||</a>
<a href="#" title="Resume refreshing" id="resume-button" onclick="onClickResume()">></a>
</div>
<div id="file-header"><strong>Loaded File: </strong><span id="file-name"></span></div>
</div>
<div id="output">
</div>
</body>
</html>