-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
63 lines (56 loc) · 1.56 KB
/
index.js
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
'use strict';
var mobilelist = [
'android',
'flappybird',
'whackamole'
];
var getJSON = function(url, successCallback, failCallback) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.onreadystatechange = function() {
if (this.readyState === 4) {
if (this.status >= 200 && this.status < 400) {
successCallback(this.responseText);
} else {
failCallback();
}
}
};
request.send();
request = null;
};
getJSON(`./list.json?t=${+Date}`, function(data) {
var list = JSON.parse(data).list;
var container = document.getElementById('container');
var app = document.getElementById('app');
if (container) {
list.forEach(item => {
var href = `${location.protocol}//${location.host}/pillow-sample/${item}`;
var a = document.createElement('a');
a.innerHTML = item;
var li = document.createElement('li');
if (!!~mobilelist.indexOf(item)) {
a.href = `//pillowjs.github.io/demoview/?previewUrl=${encodeURIComponent(href)}`;
} else {
a.href = href;
}
li.appendChild(a);
container.appendChild(li);
});
}
if (app) {
list.forEach(item => {
var href = `/pillow-sample/${item}`;
var div = document.createElement('div');
var iframe = document.createElement('iframe');
iframe.src = href;
iframe.scrolling = 'no';
div.appendChild(iframe);
var a = document.createElement('a');
a.href = href;
a.innerHTML = item;
div.appendChild(a);
app.appendChild(div);
});
}
});