-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
210 lines (179 loc) · 7.74 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Tangram Blocks</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="https://rawgit.com/patriciogonzalezvivo/glslCanvas/master/dist/GlslCanvas.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js"></script>
<script type="text/javascript" src="https://rawgit.com/chjj/marked/master/lib/marked.js"></script>
<link rel="stylesheet" href="https://raw.githubusercontent.com/mapzen/styleguide/gh-pages/styles/styleguide.min.css">
<style type="text/css">
img {
position: relative;
left: 50%;
transform: translate(-50%, 0px);
max-width: 100%;
}
a img:hover {
border-color: #d4645c;
border-style: solid;
border-width: 2px;
opacity: .8;
}
#background {
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<canvas id='background' class="glslCanvas" data-fragment-url="blocks.frag" width="1920" height="1080"></canvas>
<div class="container">
<div class="side-nav styleguide-side-nav col-md-3">
<div class="toc hidden-print" role="directory">
<ul class="nav toc-nav affix-top" id="toc">
</ul>
</div>
</div>
<div class="col-md-9">
<div id="content">
</div>
</div>
</div>
<script src="https://raw.githubusercontent.com/mapzen/styleguide/gh-pages/scripts/mapzen-styleguide.min.js"></script>
<script type="text/javascript">
function fetchHTTP(url, methood){
var request = new XMLHttpRequest(), response;
request.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) {
response = request.responseText;
}
}
request.open(methood ? methood : 'GET', url, false);
request.send();
return response;
}
function cleanTOC() {
var topLevel = document.getElementsByClassName('toc-top-level');
for (var i in topLevel) {
topLevel[i].className = 'toc-top-level';
}
var subNav = document.getElementsByClassName('toc-subnav');
for (var i in subNav) {
subNav[i].className = 'toc-subnav';
}
}
function sortObjectByKey(obj) {
var keys = [];
var sorted_obj = {};
for(var key in obj){
if(obj.hasOwnProperty(key)){
keys.push(key);
}
}
// sort keys
keys.sort();
// create new array based on Sorted Keys
jQuery.each(keys, function(i, key){
sorted_obj[key] = obj[key];
});
return sorted_obj;
};
function loadTOC() {
var toc = document.getElementById('toc');
var tocData = JSON.parse(fetchHTTP('toc.json'));
tocData = sortObjectByKey(tocData);
for (var folder in tocData) {
var category = document.createElement('li');
category.className = 'toc-top-level';
var link = document.createElement('a');
link.className = 'toc-subnav-toggle';
link.href = '#'+folder;
link.innerHTML = folder;
category.appendChild(link);
link.addEventListener('click', function (e) {
cleanTOC();
e.target.parentNode.className = "toc-top-level toc-current";
e.target.parentNode.childNodes[1].className = "toc-subnav toc-expand";
})
var holder = document.createElement('ul');
holder.className = 'toc-subnav';
var counter = 0;
var blocks = sortObjectByKey(tocData[folder]);
for (var block in blocks) {
var li = document.createElement('li');
li.innerHTML = '<a href="#'+folder+'-'+block+'"> - '+block+'</a>';
if (counter === 0) {
li.className = 'main';
}
holder.appendChild(li);
counter++;
}
category.appendChild(holder);
toc.appendChild(category);
}
}
function loadMarkdown() {
var content = document.getElementById('content');
var mdText = fetchHTTP('README.md');
content.innerHTML = marked(mdText);
// Load codes tags that have "src" attributes
var list = document.getElementsByTagName('code');
for (var i = 0; i < list.length; i++) {
if (list[i].className == 'lang-glsl' ||
list[i].className == 'lang-js' ){
hljs.highlightBlock(list[i]);
}
}
}
function searchHash() {
if (window.location.hash !== '') {
var hashes = location.hash.split('&');
for (var i in hashes) {
var ext = hashes[i].substr(hashes[i].lastIndexOf('.') + 1);
var hash = hashes[i];
// Extract hash if is present
if (hash.search('#') === 0) {
hash = hash.substr(1);
}
search(hash);
}
}
}
function search(string) {
var elements = document.querySelectorAll('[id^="-'+string+'-"]');
if (elements) {
elements[0].scrollIntoView();
}
}
function getScroll() {
var html = document.documentElement;
var body = document.body;
var height = Math.max( body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight );
var scroll = html.scrollTop || body.scrollTop || 0;
return scroll/height;
}
window.onload = function(){
loadTOC();
loadMarkdown();
searchHash();
window.addEventListener('scroll', function() {
if (glslCanvases.length > 0) {
var scroll = getScroll();
console.log(scroll);
glslCanvases[0].setUniform('u_scroll', scroll);
}
});
};
window.addEventListener('hashchange', searchHash);
</script>
</body>
</html>