-
Notifications
You must be signed in to change notification settings - Fork 11
/
player.html
292 lines (275 loc) · 11.2 KB
/
player.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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Markdown PPT Player</title>
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="css/player.css">
<link rel="stylesheet" href="css/switch.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://spec.commonmark.org/js/commonmark.js"></script>
<script src="js/player.js"></script>
<script src="js/air.play.js"></script>
<script src="js/settings.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.1.6/ZeroClipboard.min.js"></script>
</head>
<body>
<!-- Static navbar -->
<div class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="player.html">Markdown PPT</a>
</div>
<div class="navbar-collapse collapse">
<form class="navbar-form navbar-left" onsubmit="connect();return false" role="form">
<div class="input-group">
<span class="input-group-addon">Air Play</span>
<input id="input_host" type="url" class="form-control" autocomplete>
</div>
</form>
<div class="navbar-form navbar-right" onsubmit="return false" role="status">
<div class="btn-group">
<button class="btn btn-info" id="air_code" onclick="openShareDialog()">
<strong>^-^</strong>
</button>
<button class="btn btn-danger" id="air_status">Offline</button>
<button class="btn btn-primary glyphicon-tooltip" onclick="window.player.fullScreen('#main')">
<span class="glyphicon glyphicon-fullscreen" id="glyphicon_full_screen"
data-toggle="tooltip" data-placement="bottom" title="Full screen"></span>
</button>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div id="main" class="panel-dashed">
<div id="player">
<div id="drop_zone" class="text-center">
<div id="drop_zone_header">
Drop markdown file
</div>
<div id="drop_zone_content"></div>
</div>
<div id="play_zone"></div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="qrcode_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
class="sr-only">Close</span></button>
<h4 class="modal-title" id="qrcode_modal_label">Share</h4>
</div>
<div class="modal-body">
<label>Read only</label>
<div class="onoffswitch navbar-right">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="switch_readonly"
onchange="changeShareModel()" checked>
<label class="onoffswitch-label" for="switch_readonly">
<span class="onoffswitch-inner">
<span class="onoffswitch-active"><span class="onoffswitch-switch">ON</span></span>
<span class="onoffswitch-inactive"><span class="onoffswitch-switch">OFF</span></span>
</span>
</label>
</div>
<div style="clear: both"></div>
<div class="input-group">
<input id="input_share" class="form-control" readonly type="url"
value="https://github.com/aiyanbo/md-ppt">
<span class="input-group-addon btn" id="btn_copy"
data-clipboard-text="https://github.com/aiyanbo/md-ppt">
<span class="glyphicon glyphicon-camera"></span>
</span>
</div>
<div id="qrcode" class="input-group">
<img id="img_qrcode"
src="http://api.qrserver.com/v1/create-qr-code/?data=https%3A%2F%2Fgithub.com%2Faiyanbo%2Fmd-ppt">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="footer">
<div class="container">
<span>Copyright: <a href="http://weibo.com/aiyboo">NinetyH</a> © 2014.</span>
<span>Source: <a href="https://github.com/aiyanbo/md-ppt">https://github.com/aiyanbo/md-ppt</a></span>
</div>
</div>
</body>
<script>
$('#glyphicon_full_screen').tooltip();
var logError = function(ex) {
console.error(ex.message);
}
var runSafely = function(func) {
try
{
func();
}
catch (ex)
{
logError(ex);
}
}
var openShareDialog = function () {
var readOnlySwitch = document.querySelector('#switch_readonly');
if (!readOnlySwitch.checked) {
readOnlySwitch.checked = true;
setShareModel({
"code": window.airPlay.code(),
"url": window.airPlay.url(),
"readOnly": true
});
}
$('#qrcode_modal').modal();
};
var connect = function () {
var url = $("#input_host").val();
if (window.airPlay.url() == url && window.airPlay.isOnline()) {
return;
}
window.airPlay.connect(url);
window.settings.save(url);
};
var setShareModel = function (options) {
var args = "code=" + options.code + "&ws=" + options.url;
if (options.readOnly) {
args = args + "&ro=1";
} else {
args = args + "&ctrl=1";
}
var share = window.location.origin + window.location.pathname + "?" + args;
$("#input_share").val(share);
$("#btn_copy").attr("data-clipboard-text", share);
$("#img_qrcode").attr("src",
"http://api.qrserver.com/v1/create-qr-code/?data="
+ encodeURIComponent(window.location.origin +
window.location.pathname.replace("player", "mobile") + "?" + args));
};
var changeShareModel = function () {
setShareModel({
"code": window.airPlay.code(),
"url": window.airPlay.url(),
"readOnly": document.querySelector("#switch_readonly").checked
});
};
window.player = new Player({
onplay: function (event) {
runSafely(function(){window.airPlay.send({"type": "play", "data": event.data});});
},
onreadend: function (event) {
var message = {};
message.type = "pull";
message.data = {
"type": "markdown",
"data": window.player.getMarkdown(),
"index": window.player.getIndex()
};
runSafely(function(){window.airPlay.send(message);});
}
});
window.player.setSwipeEvent("#main");
window.airPlay = new AirPlay({
onopen: function (event) {
$("#input_host").val(event.url);
setShareModel({
"code": event.data,
"url": event.url,
readOnly: true
});
},
onpush: function (event) {
if (window.player.getMarkdown().length == 0) {
return;
}
var message = {};
message.type = "pull";
message.data = {
"type": "markdown",
"data": window.player.getMarkdown(),
"index": window.player.getIndex()
};
window.airPlay.send(message);
},
onpull: function (event) {
window.player.sync(event.data);
},
onplay: function (event) {
window.player.play(event.data);
},
onstatus: function (event) {
var message = event.data;
if ("conn" === message.action) {
if (200 == message.code) {
window.player.display({title: "Waiting for sync.", content: ""});
} else if (404 == message.code) {
window.player.display({
title: "Connect failure!",
content: "Can't connect to " + window.settings.code() + ", it's maybe closed."
});
}
}
}
});
window.settings = new Settings({
onreadonly: function () {
window.player.readOnly();
},
onok: function (ws, code) {
runSafely(function(){window.airPlay.connect(ws, code);});
$("#input_host").val(ws);
},
onws: function (ws) {
runSafely(function(){window.airPlay.connect(ws);});
$("#input_host").val(ws);
}
});
window.settings.set();
var zeroClipboard = new ZeroClipboard(document.querySelector("#btn_copy"));
zeroClipboard.on("ready", function (readyEvent) {
console.log("ZeroClipboard is on ready.");
if (navigator.userAgent.match(/chrome/i)) {
var btnCopy = $("#btn_copy");
btnCopy.tooltip({"placement": "left", "trigger": "click hover"})
.attr('data-original-title', 'Copy to clipboard');
btnCopy.on("mouseout", function (event) {
$("#btn_copy")
.attr('data-original-title', 'Copy to clipboard')
.tooltip('fixTitle');
}).on("click", function (event) {
$("#btn_copy")
.attr('data-original-title', 'Copied!')
.tooltip('toggle');
});
} else {
var bridge = $("#global-zeroclipboard-html-bridge");
bridge.tooltip({"placement": "top", "trigger": "click hover"})
.attr('data-original-title', 'Copy to clipboard');
bridge.on("mouseout", function (event) {
$("#global-zeroclipboard-html-bridge")
.attr('data-original-title', 'Copy to clipboard')
.tooltip('fixTitle');
}).on("click", function (event) {
$("#global-zeroclipboard-html-bridge")
.attr('data-original-title', 'Copied!')
.tooltip('toggle');
});
}
});
</script>
</html>