-
Notifications
You must be signed in to change notification settings - Fork 443
/
demo.html
executable file
·64 lines (57 loc) · 1.89 KB
/
demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Subtle Pattern Demo</title>
<style>
body , html { padding:0;margin:0;height:100%; }
body { background:#ccc none repeat 0 0; }
form { padding:10px;text-align:center;background:#FFF;border-bottom:1px solid #000; }
</style>
</head>
<body>
<form>
<select id="image">
<option selected>Downloading Pattern Names...</option>
</select>
</form>
<script>
var loadPatterns = function () {
var ajax, ajaxTimeout, requrl;
ajax = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : (XMLHttpRequest && new XMLHttpRequest()) || null;
ajaxTimeout = window.setTimeout(function () {
ajax.abort();
}, 6000);
ajax.onreadystatechange = function () {
var selectEle, itemsArray, itemsString, i;
if (ajax.readyState === 4) {
if (ajax.status === 200) {
clearTimeout(ajaxTimeout);
if (ajax.status !== 200) {
} else {
selectEle = document.getElementById('image');
itemsArray = JSON.parse(ajax.responseText);
itemsString = '';
for(i = 0; i < itemsArray.length; i++) {
if(itemsArray[i].name.indexOf('.png') !== -1) {
itemsString += '<option value="'+itemsArray[i].html_url.replace("blob", "raw")+'">'+itemsArray[i].name+'</option>';
}
}
selectEle.innerHTML = itemsString;
selectEle.setAttribute("onchange", "setPattern(this.value);"); // = setPattern(selectEle.value);
}
}
}
};
requrl = 'https://api.github.com/repos/subtlepatterns/SubtlePatterns/contents';
ajax.open("GET", requrl, true);
ajax.send();
}
var setPattern = function (url) {
var bodyEle = document.getElementsByTagName('body')[0];
bodyEle.style.backgroundImage = 'url("'+url+'")';
}
window.onload = loadPatterns();
</script>
</body>
</html>