-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
348 lines (283 loc) · 10.7 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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/svg+xml" sizes="any" href="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20100%20100%22%3E%3Ctext%20y%3D%221em%22%20font-size%3D%2290%22%3E%F0%9F%93%84%3C%2Ftext%3E%3C%2Fsvg%3E">
<title>!nflect · Modulating Visualizations to Tell Stories with Data</title>
<meta property="og:url" content="https://uclab.fh-potsdam.de/inflect/">
<meta property="og:title" content="!nflect · Modulating Visualizations to Tell Stories with Data">
<meta property="og:description" content="Web-based framework for inflections that bridge data exploration and storytelling">
<meta property="og:image" content="https://uclab.fh-potsdam.de/inflect//img/cover.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<script src="src/marked.min.js"></script>
<style>
@font-face {
font-family: "Atkinson";
src: url("src/fonts/AtkinsonHyperlegibleNextVF-Variable.woff2") format("woff2-variations");
font-style: normal;
}
@font-face {
font-family: "AtkinsonMono";
src: url("src/fonts/AtkinsonHyperlegibleMono-Medium.woff2") format("woff2-variations");
font-style: normal;
}
@font-face {
font-family: "AtkinsonMono";
src: url("src/fonts/AtkinsonHyperlegibleMono-Bold.woff2") format("woff2-variations");
font-style: normal;
font-weight: bold;
}
body {
font-family: "Atkinson", sans-serif;
font-weight: 250;
font-size: calc(.9vw + .9vh);
background-color: rgb(242, 242, 242);
margin: 0;
padding: 0;
}
code, pre, kbd, samp, tt, textarea {
font-family: "AtkinsonMono", monospace;
}
a.img {
float: left; width: 0; height: 0;
}
section img {
max-width: 100%;
}
#orientationWarning {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
background: black;
color: white;
font-weight: bold;
text-align: center;
padding: 1em;
z-index: 100;
}
strong { font-weight: 500; }
iframe, #frameBox {
top: 0;
left: 0;
height: 100vh;
width: 50vw;
position: fixed;
background-color: #fff;
border: 0;
margin: 0;
padding: 0;
}
iframe {
transition: opacity 0.1s ease-in;
}
h1 { font-size: 2.25em; font-weight: 200;}
h2 { font-size: 1.5em; }
h3 { font-size: 1.25em; }
h4 { font-size: 1em; }
h2, h3, h4 { font-weight: 500; }
main {
box-sizing: border-box;
position: absolute;
right: 0;
width: 50vw;
padding: 0 5vh;
margin: 0;
}
section {
margin-top: 100vh;
margin-bottom: 100vh;
}
section:first-of-type, section:last-of-type {
display: flex;
justify-content: center;
flex-direction: column;
}
section:first-of-type {
min-height: 100vh;
margin-top: 0;
}
section:last-of-type {
min-height: 95vh;
margin-bottom: 0;
}
p {
font-size: 1em;
line-height: 1.5em;
}
a {
color: #000;
}
ul, ol {
padding-left: 1.5em;
}
li {
padding-bottom: 0.5em;
}
li li {
padding-bottom: 0;
}
a.dontinflect { color: #555;}
a.dontinflect:hover { color: #000;}
a.active {
border-radius: .25em;
background: rgb(255, 255, 255);
text-decoration: none;
padding: 0 .1em;
margin: 0 -.1em;
}
a.active:hover {
background: #ddd;
}
footer {
bottom: 0;
display: block;
width: 100%;
text-align: right;
margin: 0;
padding: 0;
opacity: 0.33;
height: 5vh;
}
footer a.dontinflect { color: #333;}
</style>
</head>
<body>
<div id="orientationWarning">Please turn your device around or widen your browser window.</div>
<div id="frameBox"><iframe id="if"></iframe></div>
<main></main>
<script>
// Track last path (excluding hash)
let lastIframePath = null;
let firstFrame = true;
const iframe = document.getElementById('if');
// Fade in new content
function setIframeIfPathChanged(newHref) {
const newURL = new URL(newHref, window.location.origin);
newURL.hash = ''; // remove hash for path comparison
const newPath = newURL.href;
// If path changes, set iframe to 0 opacity
if (newPath !== lastIframePath) {
if (firstFrame) firstFrame = false;
else iframe.style.opacity = '0';
iframe.src = newHref;
lastIframePath = newPath;
}
else {
// Otherwise just update src as needed (rare case)
iframe.src = newHref;
}
}
// Fade in once the iframe finishes loading
iframe.addEventListener('load', () => {
iframe.style.opacity = '1';
});
// Function to fetch and render the markdown
async function renderMarkdown() {
try {
const hash = window.location.hash.substring(1); // Remove '#' from hash
const file = hash ? hash : 'README';
document.title = (file === "README")
? "!nflect"
: `!nflect · ${file}`;
const response = await fetch(file + ".md");
let text = await response.text();
// split sections by two empty lines
text = text.replace(/\s*\n\s*\n\s*\n\s*/g, '\n\n</section>\n\n<section>\n\n');
text = "<section>\n\n" + text + "\n\n</section>";
// add class dontinflect to regular html links
text = text.replace(/<a\b([^>]*)>/gi, (m, attrs) =>
`<a${/class\s*=\s*["']([^"']*)["']/i.test(attrs)
? attrs.replace(/class\s*=\s*["']([^"']*)["']/i,
(m, c) => `class="${c} dontinflect"`)
: ` class="dontinflect"${attrs}`}>`
);
// render markdown into HTML
let html = marked.parse(text);
// skip footer when on inflect page
if (document.URL!="https://uclab.fh-potsdam.de/inflect/") html = html + "\n<footer>a data story made with <strong><a class='dontinflect' href='https://uclab.fh-potsdam.de/inflect/'>!nflect</a></strong></footer>";
document.querySelector('main').innerHTML = html;
transformInflectionImages();
initializeObservers();
// return to old position
if (location.hostname=="localhost") window.scrollTo(0, sessionStorage.getItem("scrollPosition") || 0);
} catch (error) {
console.error('Error fetching or rendering the markdown file:', error);
}
}
// Update markdown when hash changes
window.addEventListener('hashchange', function() {
event.preventDefault();
window.scrollTo(0, 0);
if (location.hostname=="localhost") sessionStorage.setItem("scrollPosition", 0);
renderMarkdown();
});
document.addEventListener("scroll", (event) => {
if (location.hostname=="localhost") sessionStorage.setItem("scrollPosition", window.scrollY);
});
window.addEventListener("beforeunload", function () {
if (location.hostname=="localhost") sessionStorage.setItem("scrollPosition", window.scrollY);
});
// turn images with alt-tag img to inflection links
function transformInflectionImages() {
const images = document.querySelectorAll('img[alt="img"]');
images.forEach(img => {
const link = document.createElement('a');
link.href = img.getAttribute('src');
link.classList.add("img");
const p = img.closest('p');
p.replaceWith(link);
});
}
// with IntersectionObserver we can check what is visible
function initializeObservers() {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// Add active class only to the visible link
const visibleLink = entry.target;
if (!visibleLink.classList.contains("dontinflect") && visibleLink.getAttribute("href") != "") {
visibleLink.classList.add('active');
// Update iframe, ignoring just changes
setIframeIfPathChanged(visibleLink.href);
}
}
else entry.target.classList.remove("active")
});
});
// Add observer to all inflect links
const inflectLinks = document.querySelectorAll('a');
inflectLinks.forEach(link => {
observer.observe(link);
// ignore local links to markdown files
if (!link.classList.contains("dontinflect")) {
// Add event listener to manually handle click
link.addEventListener('click', function(event) {
document.querySelectorAll('a').forEach(a => a.classList.remove('active'));
link.classList.add('active');
setIframeIfPathChanged(link.href);
});
}
});
}
// scroll up when pressing Escape
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape') {
window.scrollTo({ top: 0, behavior: 'smooth' });
}
});
// Show/hide orientation warning when window is taller than wide
function resize() {
const warning = document.getElementById('orientationWarning');
if (window.innerHeight > window.innerWidth) warning.style.display = 'block';
else warning.style.display = 'none';
}
window.addEventListener('resize', resize);
resize();
// Load, parse, and display markdown on page load
renderMarkdown();
</script>
</body>
</html>