/
index.html
67 lines (66 loc) · 2.76 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
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>DZ's Website</title>
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jquery.mousewheel-min.js"></script>
<script src="js/jquery.terminal-0.8.8.js"></script>
<link href="css/jquery.terminal.css" rel="stylesheet"/>
<script>
var path_mapping;
var host;
if (window.location.hostname == '') {
host = "http://localhost:5000"
} else {
host = "https://morning-beyond-6767.herokuapp.com"
}
var codify_JSON = function($str) {
return "<pre>" + JSON.stringify($str, null, 2).replace(/\"/g, "").replace(/([.!?\]])\,/g, "$1<br/>") + "</pre>"
}
var get_paths = function($path) {
$.get(host + $path, function( data, status ) {
path_mapping = data.paths
// make a copy of the mapping object & change display options
var display_mapping = jQuery.extend(true, {}, path_mapping);
for (var key in display_mapping) {
if (display_mapping.hasOwnProperty(key))
display_mapping[key] = display_mapping[key]["text"]
}
// re-display the information shown on page
$("#heading").html(data.page_heading + "<br/><br/>");
$("#options").html(codify_JSON(display_mapping));
$("#text").html(data.page_text);
if (!jQuery.isEmptyObject(data.page_json)) // don't show empty dictionary
$("#json").html(codify_JSON(data.page_json));
else $("#json").html("");
if (data.page_text !== "" && jQuery.isEmptyObject(data.page_json)) {
$("#json").html("<br/>"); // add a newline between 2 lines of text
}
}, dataType = "json")
}
jQuery(document).ready(function($) {
$('body').terminal(function(command, term) {
command = command.replace(/\s/g, "");
if (command in path_mapping) {
get_paths(path_mapping[command]["path"]);
}
term.clear();
}, {
greetings: false,
onInit: get_paths("/home"),
completion: function(term, string, callback) {
callback(Object.keys(path_mapping));
}
});
});
</script>
</head>
<body>
<div id="greeting" style="color:#2070DF"> Hi! Welcome to the website of David Zeng!</div> <br/>
<div id="heading" style="text-decoration: underline;"></div>
<div id="text"></div>
<div id="json"></div>
<div style="color:#EFAD17"><br/><br/>Please type one of the options to navigate through the site. You can autocomplete with the TAB button.</div>
<div id="options">Please wait for a bit while my heroku instance wakes up...</div>
</body>