-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmarkers.html
108 lines (93 loc) · 3 KB
/
markers.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
<!DOCTYPE html>
<html>
<head>
<title>MAGE Icons</title>
<!-- <script type="text/javascript" src="./icons.js"></script> -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/ngageoint/MAGE/icons.js"></script>
<style>
.header {
font-size: 2em;
padding: 20px;
text-transform: capitalize;
}
.marker {
font-size: 1em;
margin: 10px;
padding: 20px;
display: inline-block;
text-align: center;
}
.icon-group {
margin: 20px;
border: 1px black solid;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="header">MAGE Markers</div>
<a href="http://htmlpreview.github.io/?https://github.com/ngageoint/MAGE/master/icons.html">Attributions for icons</a>
<div id="icons">
</div>
<script type="text/javascript">
var iconsDiv = document.getElementById('icons');
function parseTree(tree) {
var iconList = {};
for (var i = 0; i < tree.length; i++) {
var content = tree[i];
if (content.path.startsWith('icons') && content.path.endsWith('.png')) {
var split = content.path.split('/');
iconList[split[1]] = iconList[split[1]] || {};
var iconSection = iconList[split[1]];
for (var part = 2; part < split.length-1; part++) {
iconSection[split[part]] = iconSection[split[part]] || {};
iconSection = iconSection[split[part]];
}
iconSection.markers = iconSection.markers || [];
iconSection.markers.push({
name: split[split.length-1],
path: content.path
});
}
}
displayIcons(iconList, iconsDiv);
}
function displayIcons(iconList, appendDiv) {
for (var key in iconList) {
var item = iconList[key];
if (key === 'markers') {
for (var i = 0; i < item.length; i++) {
var icon = item[i];
var div = document.createElement('div');
div.classList.add('marker');
div.innerHTML = '<a target="_blank" href="https://github.com/ngageoint/MAGE/raw/master/' + icon.path + '"><img src="https://github.com/ngageoint/MAGE/raw/master/' + icon.path + '"/><div class="icon-name">' + icon.name + '</div></a>';
appendDiv.appendChild(div);
}
} else {
var div = document.createElement('div');
div.classList.add('icon-group');
div.innerHTML = '<div class="header">'+key+'</div>';
appendDiv.appendChild(div);
displayIcons(item, div);
}
}
}
function getMarkers() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.github.com/repos/ngageoint/MAGE/git/trees/master?recursive=1');
xhr.send(null);
xhr.onreadystatechange = function () {
var DONE = 4; // readyState 4 means the request is done.
var OK = 200; // status 200 is a successful return.
if (xhr.readyState === DONE) {
if (xhr.status === OK) {
var dirContents = JSON.parse(xhr.responseText);
var tree = dirContents.tree;
parseTree(tree);
}
}
};
}
getMarkers();
</script>
</body>