-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (118 loc) · 4.04 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Rust Intro</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/moon.css">
<link rel="stylesheet" href="css/my.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match(/print-pdf/gi) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName('head')[0].appendChild(link);
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-markdown="slides/intro.md" data-separator="^\n---\n$">
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
history: true,
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function () { hljs.initHighlightingOnLoad(); fetchAllCode(); addButtons() } }
]
});
fetchAllCode = function () {
Array.prototype.slice.call(document.querySelectorAll('code[data-source]')).forEach(function (codeContainer) {
console.log(codeContainer.dataset.source);
var xhr = new XMLHttpRequest();
xhr.open("GET", codeContainer.dataset.source, true);
xhr.overrideMimeType("text/plain; charset=UTF-8");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var code = document.createTextNode(xhr.responseText);
codeContainer.appendChild(code);
if (typeof (hljs) !== 'undefined') {
hljs.highlightBlock(codeContainer);
}
}
else {
console.error(xhr.status)
console.error("Error while trying to get remote code");
}
}
};
try {
xhr.send(null);
} catch (e) {
console.error("XHR failed for " + url + ", " + e);
}
});
}
var buttons = '<button class="exec btn">run</button>' + "\n";
var result = '<span class="return"></span>';
function addButtons() {
$('pre code.rust-interactive').each(function (i, block) {
$(block).before(buttons);
$(block).after(result);
});
$('pre code.lang-rust-interactive').each(function (i, block) {
$(block).before(buttons);
$(block).after(result);
});
$('.reset').each(function (n) {
$(this).context._code = $(this).siblings('code').text();
});
$('.exec').click(function () {
var target = $(this).siblings('.return');
target.html('<img src="img/rust.gif" style="border:none; box-shadow:none; margin: auto; background: none; display:block">');
var code = $(this).siblings('code').text();
var payload = { optimize: "0", version: "stable", code: code };
$.ajax({
url: 'https://play.rust-lang.org/evaluate.json',
type: "POST",
dataType: "json",
data: JSON.stringify(payload),
contentType: "application/json"
}).done(function (result) {
var output = formatOutput(result.result);
console.log(result.error);
target.html(output);
});
});
$('.reset').click(function () {
$(this).siblings('code').text($(this).context._code);
hljs.highlightBlock($(this).siblings('code')[0]);
})
$('.versionable').blur(function () {
console.log('versioning comming soon')
});
}
formatOutput = function (output) {
var parts = output.split(/\n/);
return parts.join('<br>');
}
</script>
</body>
</html>