forked from aiyanbo/md-ppt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
299 lines (262 loc) · 9.26 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Markdown PPT</title>
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="js/jquery.mobile.custom.min.js"></script>
<script src="http://jgm.github.io/stmd/js/stmd.js"></script>
<style>
#container {
width: 960px;
height: 640px;
margin: 10px auto;
}
#drop_zone {
width: 100%;
height: 100%;
border: dashed gray;
border-radius: 10px;
color: gray;
}
#drop_zone_title {
font-size: 7.5em;
}
#pin_code {
display: none;
}
#pin_code_title {
font-size: 5em;
}
#input_pin_code {
width: 13em;
height: 4em;
font-weight: bolder;
}
#ppt_content {
width: 100%;
height: 100%;
display: none;
font-size: 1.5em;
border: solid gray 1px;
border-radius: 10px;
padding: 5px;
box-shadow: 2px 2px 3px #aaaaaa;
}
#copyright {
margin-top: 5px;
}
</style>
</head>
<body>
<div id="container">
<div id="drop_zone" class="text-center">
<div id="drop_zone_title">
Drop markdown file
</div>
<div id="pin_code">
<div id="pin_code_title">
OR
</div>
<div id="pin_code_form">
<form class="form-inline" role="form" action="" onsubmit="pinConnection();return false">
<div class="form-group">
<div class="input-group">
<!--<div class="input-group-addon">Connect to pin code</div>-->
<input id="input_pin_code" class="form-control" type="number"
min="100000" max="999999" placeholder="Connect to pin code" autofocus>
</div>
</div>
</form>
</div>
</div>
</div>
<div id="ppt_content"></div>
<p id="copyright">Copyright: <a href="http://weibo.com/aiyboo">NinetyH</a> © 2014.
<span id="internet_info" class="btn btn-danger btn-xs">Offline</span>
<span id="client_info"></span>
<span>
<input id="air_play_host" placeholder="Enter air-play host" autocomplete>
<button class="btn btn-primary btn-xs glyphicon glyphicon-ok" onclick="connectAirPlay(this)"></button>
</span>
</p>
<p>Source: <a href="https://github.com/aiyanbo/md-ppt">https://github.com/aiyanbo/md-ppt</a></p>
</div>
</body>
<script type="text/javascript">
var parser = new stmd.DocParser();
var renderer = new stmd.HtmlRenderer();
var pptPages = [];
var playIndex = 0;
var interactCode = 0;
var interactive = false;
// Check file APIs support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
} else {
alert('The File APIs are not fully supported in this browser.');
}
// Core control
function handleFileSelect(event) {
event.stopPropagation();
event.preventDefault();
var files = event.dataTransfer.files;
var reader = new FileReader();
reader.readAsBinaryString(files[0]);
reader.onloadend = function (event) {
if (event.target.readyState == FileReader.DONE) {
renderMarkdownPptPages(event.target.result);
if (interactive) {
sendMarkdown()
}
}
};
}
function handleDragOver(event) {
event.stopPropagation();
event.preventDefault();
event.dataTransfer.dropEffect = "copy";
}
function handleKeyUp(event) {
var charCode = (typeof event.which === "number") ? event.which : event.keyCode;
if (39 == charCode) {
changePages(true)
} else if (37 == charCode) {
changePages(false)
}
}
function renderMarkdownPptPages(content) {
initPptPlayer(renderer.render(parser.parse(content)).split(/<\s*hr\s*\/*\s*>/));
displayPptPage(playIndex);
}
function initPptPlayer(ppt) {
playIndex = 0;
document.querySelector("#drop_zone").style.display = "none";
var pptContent = document.querySelector("#ppt_content");
pptContent.style.display = "block";
pptPages = ppt;
}
function displayPptPage(index) {
if (pptPages.length == 0) {
return
}
playIndex = index;
document.querySelector("#ppt_content").innerHTML = pptPages[index];
}
function changePages(next) {
if (next) {
playIndex = playIndex + 1
} else {
playIndex = playIndex - 1
}
if (playIndex < 0) {
playIndex = 0;
return
} else if (playIndex > pptPages.length - 1) {
playIndex = pptPages.length == 0 ? 0 : pptPages.length - 1;
return
}
displayPptPage(playIndex);
if (interactive) {
sendControl(playIndex);
}
}
function handleSwipeLeft() {
changePages(true);
}
function handleSwipeRight() {
changePages(false);
}
// Web socket
var ws = new WebSocket(localStorage.getItem("air-play") == null ? "ws://localhost:8001" : localStorage.getItem("air-play"));
document.querySelector("#air_play_host").value = localStorage.getItem("air-play") == null ? "" : localStorage.getItem("air-play").replace("ws://","");
initWS(ws);
function initWS(ws) {
ws.onopen = function (event) {
interactive = true;
document.querySelector("#pin_code").style.display = "block";
var internetInfo = document.querySelector("#internet_info");
internetInfo.innerHTML = "Online";
internetInfo.className = internetInfo.className.replace("danger", "success");
};
ws.onmessage = function (event) {
var message = JSON.parse(event.data);
console.log(message);
if ("new" === message.type) {
interactCode = message.data;
displayPinCode(message.data);
} else if ("send" === message.type) {
sendMarkdown();
} else if ("play" === message.type) {
displayPptPage(message.data)
} else if ("ppt" === message.type) {
initPptPlayer(message.data);
if (pptPages.length > 0) {
displayPptPage(playIndex);
} else {
document.querySelector("#ppt_content").innerHTML = "<h1 class='text-center'>Waiting receive ppt.</h1>";
}
}
};
ws.onerror = function (event) {
console.log(event);
var internetInfo = document.querySelector("#internet_info");
internetInfo.innerHTML = "Offline";
internetInfo.className = internetInfo.className.replace("success", "danger");
};
ws.onclose = function (event) {
console.log("Disabled interactive");
var internetInfo = document.querySelector("#internet_info");
internetInfo.innerHTML = "Offline";
internetInfo.className = internetInfo.className.replace("success", "danger");
};
}
function connectAirPlay(target) {
target.disabled = true;
var host = "ws://" + document.querySelector("#air_play_host").value;
if (ws.readyState === 1) {
ws.close();
}
ws = new WebSocket(host);
initWS(ws);
localStorage.setItem("air-play", host);
target.disabled = false;
}
function displayPinCode(code) {
document.querySelector("#client_info").innerHTML =
"Your pin code: <strong><kbd>" + code + "</kbd></strong>";
}
function sendMarkdown() {
console.log("Send ppt");
ws.send(buildMessage("ppt", pptPages));
}
function sendControl(index) {
console.log("Send ctrl, show page index: " + index);
ws.send(buildMessage("play", index));
}
function pinConnection() {
var pinCode = document.querySelector("#input_pin_code").value;
if (pinCode == interactCode) {
alert("Pin code must be not same your code.");
return
}
console.log("Pin connection to " + pinCode);
ws.send(buildMessage("conn", pinCode));
}
function buildMessage(type, data) {
var message = {};
message.type = type;
message.data = data;
return JSON.stringify(message)
}
// Setup the dnd listeners.
var dropZone = document.querySelector("#container");
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
window.addEventListener('keyup', handleKeyUp, false);
$(function () {
$("#ppt_content").on("swipeleft", handleSwipeLeft).on("swiperight", handleSwipeRight);
});
</script>
</html>