-
Notifications
You must be signed in to change notification settings - Fork 0
/
ismplayer.html
334 lines (275 loc) · 8.8 KB
/
ismplayer.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="format-detection" content="telephone=no"/>
<!-- <meta name="apple-itunes-app" content="app-id=642452385, app-argument="/> -->
<title>Lesson 1-New words +Listening</title>
<link rel="stylesheet" type="text/css" href="data/ismplayer/style.css"/>
<link rel="stylesheet" type="text/css" href="data/ismplayer/style_mini.css" media="only screen and (max-device-width: 605px), only screen and (max-device-height: 605px)" />
</head>
<body>
<script>
var isIpad = navigator.userAgent.match(/iPhone|iPad|iPod/i);
document.body.className = isIpad ? "ipad" : "android";
// ios7 scroll fix
if (isIpad) {
if (window.innerHeight != document.documentElement.clientHeight) {
var fixViewportHeight = function() {
document.documentElement.style.height = window.innerHeight + "px";
};
window.addEventListener("orientationchange", fixViewportHeight, false);
fixViewportHeight();
}
var forceRedraw = function() {
var origDisplay = document.body.style.display;
document.body.style.display = 'none';
document.body.offsetHeight;
document.body.style.display = origDisplay;
};
window.addEventListener("resize", forceRedraw, false);
}
</script>
<div class="mainLayer">
<div class="launcher">
<img class="preview" src="data/ismplayer/preview.png"></img>
<a class="btnPlay" id="btnPlay"></a>
</div>
<div class="info">
<h1>Lesson 1-New words +Listening</h1>
<p id="launchDesc">The presentation will be opened in iSpring Play.</p>
<p id="launchDescWithVideo">The presentation contains video narration.
To view with video, use iSpring Play.</p>
<p id="downloadAppDesc" class="hidden">To view this presentation, download the free iOS application iSpring Play.</p>
<div class="buttons">
<a id="btnOpenInApp" class="text_button" href="#" ontouchstart="">
Launch
</a>
<a id="btnDownloadApp" class="app_store hidden" href="#"></a>
</div>
</div>
<div class="bottom_area" id="bottomAreaNormal">
<a href="#" id="btnOpenInBrowser">View in browser</a>
<a href="#" id="btnOpenInBrowserWithoutVideo">View in browser without video</a>
</div>
</div>
<script>
var IOS_APP_SCHEME = "ismobile";
var IOS_STORE_URL = "https://itunes.apple.com/us/app/ispring-mobile/id642452385?mt=8";
var ANDROID_APP_SCHEME = "ismobile";
var ANDROID_APP_PACKAGE = "com.ispringsolutions.mplayer";
var appMeta = document.querySelector("meta[name='apple-itunes-app']");
if(appMeta) {
appMeta.setAttribute('content', appMeta.getAttribute('content') + getBasePath());
}
function $(id) {
return document.getElementById(id);
}
function show(element, visible) {
if (visible) {
element.className = element.className.replace(/hidden/g, '');
} else {
element.className += ' hidden';
}
}
function now() {
return +new Date();
}
function createEmptyIframe() {
var iframe = document.createElement("iframe");
iframe.style.border = "none";
iframe.style.width = "1px";
iframe.style.height = "1px";
return iframe;
}
function strEndsWith(str, suffix) {
var l = str.length - suffix.length;
return l >= 0 && str.indexOf(suffix, l) == l;
}
function getBasePath() {
var params = location.search || "";
var host = location.host;
// remove file name from url
var path = location.pathname.split("/");
path.length = path.length - 1;
return host + path.join("/") + "/" + params;
}
function getIspringPlayUrl() {
var ispringPlayUrl = decodeURIComponent((window.location.search.match(/(\?|&)ispringPlayUrl\=([^&]*)/)||['','',''])[2]);
return ispringPlayUrl.length > 0 ? ispringPlayUrl : getBasePath();
}
function showDownloadButton(showDownload)
{
show($("launchDesc"), !showDownload);
show($("launchDescWithVideo"), !showDownload);
show($("btnOpenInApp"), !showDownload);
show($("downloadAppDesc"), showDownload);
show($("btnDownloadApp"), showDownload);
}
function getIOSVersion() {
if((/iphone|ipod|ipad/gi).test(navigator.platform)) {
var versionString = navigator.appVersion.substr(navigator.appVersion.indexOf(' OS ')+4);
versionString = versionString.substr(0, versionString.indexOf(' '));
versionString = versionString.replace(/_/g, '.');
return versionString;
}
return '';
}
function getIOSMajorVersion() {
var version = getIOSVersion();
if(version == ''){
return 0;
}
var dotIndex = version.indexOf('.');
if(dotIndex <= 0){
return Number(version);
}
return Number(version.substr(0, dotIndex));
}
var IosLauncher = function() {
function startApp(redirectToStore) {
var launchUrl = IOS_APP_SCHEME + "://" + getIspringPlayUrl();
if(getIOSMajorVersion() >= 9) {
// iframe using method doesn't work since iOS 9
setTimeout(function() {
onAppStartFailed(redirectToStore)
}, 2718);
window.top.location.replace(launchUrl);
} else {
var launchTime = now();
setTimeout(function() {
document.body.removeChild(iframe);
if (now() - launchTime < 1500) {
onAppStartFailed(redirectToStore);
}
}, 1000);
var iframe = createEmptyIframe();
iframe.src = launchUrl;
document.body.appendChild(iframe);
}
}
function onAppStartFailed(redirectToStore) {
if (redirectToStore) {
location.replace(IOS_STORE_URL);
} else {
showDownloadButton(true);
}
}
document.addEventListener("visibilitychange", function(event) {
if (!window.document.hidden)
{
show($("launchDesc"), true);
show($("launchDescWithVideo"), true);
show($("btnOpenInApp"), true);
show($("downloadAppDesc"), false);
show($("btnDownloadApp"), false);
}
});
this.launch = function(redirectToStore /* = true */) {
redirectToStore = (redirectToStore == undefined ? true : redirectToStore);
setTimeout(function() {
startApp(redirectToStore);
}, 50);
return false;
};
};
var AndroidLauncher = function() {
function pageIsHidden() {
return document.hidden || document.mozHidden || document.webkitHidden;
}
function launchFromLink() {
var href = "intent://" + getIspringPlayUrl() + "#Intent;" +
"scheme=" + ANDROID_APP_SCHEME + ";" +
"package=" + ANDROID_APP_PACKAGE + ";" +
"end";
var target = "_top";
$("btnOpenInApp").href = href;
$("btnOpenInApp").target = target;
$("btnPlay").href = href;
$("btnPlay").target = target;
return true;
}
function launchFromIframe() {
var onIframeLoaded = function(redirectToMarket) {
document.body.removeChild(iframe);
if (redirectToMarket) {
location.assign("market://details?id=" + ANDROID_APP_PACKAGE);
}
};
var iframe = createEmptyIframe();
if (navigator.userAgent.indexOf('Firefox') > 0) {
var loadStartTime = now();
setTimeout(function() {
var appStarted = pageIsHidden() || now() - loadStartTime > 400;
onIframeLoaded(!appStarted);
}, 200);
} else {
iframe.onload = function() {
onIframeLoaded(true);
};
}
iframe.src = ANDROID_APP_SCHEME + "://" + getIspringPlayUrl();
document.body.appendChild(iframe);
return false;
}
function isIntentUrlSupported() {
var userAgent = navigator.userAgent;
var matches = userAgent.match(/Chrome\/(\d+)/);
if (!matches) {
return false;
}
if (/OPR\/\d+/.test(userAgent) || // Opera
/Version\/\d+/.test(userAgent)) { // or Dolphin
return false;
}
var version = parseInt(matches[1]);
return version >= 25;
}
this.launch = function() {
return isIntentUrlSupported()
? launchFromLink() : launchFromIframe();
};
};
var launcher = isIpad ? new IosLauncher() : new AndroidLauncher();
$("btnPlay").onclick = function() {
return launcher.launch(false);
};
$("btnOpenInApp").onclick = function() {
return launcher.launch(false);
};
$("btnDownloadApp").onclick = function() {
this.href = IOS_STORE_URL;
return true;
};
var openInBrowserCallback = function() {
var basePath = getBasePath();
var params = '';
var parts = basePath.split('?');
if(parts.length == 2)
{
basePath = parts[0];
params = '?' + parts[1];
}
this.href = "//" + basePath + 'index.html' + params + "#inbrowser";
return true;
};
$("btnOpenInBrowser").onclick = openInBrowserCallback;
$("btnOpenInBrowserWithoutVideo").onclick = openInBrowserCallback;
</script>
<script>
var isIphone = navigator.userAgent.match(/iPhone/i);
var hasVideo = false;
if (isIphone && hasVideo && getIOSMajorVersion() < 10)
{
document.getElementById("launchDesc").style.display = "none";
document.getElementById("btnOpenInBrowser").style.display = "none";
}
else
{
document.getElementById("launchDescWithVideo").style.display = "none";
document.getElementById("btnOpenInBrowserWithoutVideo").style.display = "none";
}
</script>
</body>
</html>