-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
447 lines (428 loc) · 21.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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Trash Panda Dot Club</title>
<link rel="shortcut icon" href="/favicon.ico">
<link rel="apple-touch-icon" href="/favicon.png">
<link rel="stylesheet" href="fonts/stylesheet.css">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<style>
body {
margin: 0;
background-color: #000;
font-family: League Gothic;
color: #FFF;
text-transform: uppercase;
letter-spacing: 1px;
text-shadow: #000 5px 5px 0,
#000 0px 5px 0,
#000 -5px 5px 0,
#000 -5px 0px 0,
#000 -5px -5px 0,
#000 0px -5px 0,
#000 5px -5px 0,
#000 5px 0px 0,
#000 0px 0px 5px;
overflow: hidden;
}
/* The only CSS reset I care about. */
a {
color: inherit;
text-decoration: none;
}
#container {
position: absolute;
display: flex;
align-items: center;
justify-content: center;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
#loading {
font-size: 100px;
}
.first-load #loading {
display: none;
}
#thing {
position: relative;
}
#caption, #attribution, #icons, #innerloading {
position: absolute;
}
#attribution {
bottom: 5px;
right: 5px;
}
#attribution a {
font-size: 10px;
text-shadow: #000 2px 2px 0,
#000 0px 2px 0,
#000 -2px 2px 0,
#000 -2px 0px 0,
#000 -2px -2px 0,
#000 0px -2px 0,
#000 2px -2px 0,
#000 2px 0px 0,
#000 0px 0px 2px;
}
#icons, #innerloading {
display: none;
font-size: 50px;
text-shadow: none;
color: #FFF7;
}
#icons {
bottom: 5px;
left: 5px;
}
#icons a {
margin-right: 5px;
}
#icons a:hover {
color: #FFF;
}
.first-load #icons {
display: block;
}
#innerloading {
top: 5px;
right: 5px;
}
.first-load.loading #innerloading {
display: block;
}
#tip {
display: none;
position: absolute;
top: 50%;
left: 50%;
height: 400px;
width: 600px;
margin-top: -200px;
margin-left: -300px;
background-color: #333;
align-items: center;
text-align: center;
}
#tip.show {
display: flex;
}
#tip-text {
text-shadow: none;
font-size: 80px;
}
</style>
</head>
<body>
<div id="container">
<div id="loading">Loading ...</div>
<div id="thing">
<div id="innerloading">
<i class="fa fa-spinner fa-spin fa-fw"></i>
<span class="sr-only">Loading...</span>
</div>
<div id="icons">
<a id="github" href="https://github.com/coderanger/trashpanda" target="_blank"><i class="fa fa-github" aria-hidden="true"></i></a>
<a id="anchor" href="#">#</a>
</div>
<div id="caption"></div>
<div id="attribution"></div>
<div id="tip">
<div id="tip-text">
Click or press spacebar for more.
</div>
</div>
</div>
</div>
<script type="text/javascript">
var THINGS = [
{image: '1.jpg', caption: 'Trash Panda', position: [50, 430], background: '#6a5544', attribution: 'https://www.flickr.com/photos/tambako/3576301909'},
{image: '2.jpg', caption: 'Danger Noodle', position: [130, 60], background: '#b69479', attribution: 'https://commons.wikimedia.org/wiki/File:Big_Sur_Snake.JPG'},
{image: '3.jpg', caption: 'Nope Rope', position: [80, 330], attribution: 'https://www.flickr.com/photos/aspexdesign/7497277648'},
{image: '4.jpg', caption: 'Wizard Cow', position: [70, 150], background: '#d5e5f4', attribution: 'https://commons.wikimedia.org/wiki/File:Mountain_Goat_Mount_Massive.JPG'},
{image: '5.jpg', caption: 'American Murder Log', position: [30, 70], size: 100, background: '#d0c2b1', attribution: 'https://commons.wikimedia.org/wiki/File:Two_american_alligators.jpg'},
{image: '6.jpg', caption: 'Murder Log', position: [90, 60], background: '#928b84', attribution: 'https://commons.wikimedia.org/wiki/File:SaltwaterCrocodile(\'Maximo\').jpg'},
{image: '7.jpg', caption: 'Fart Squirrel', position: [490, 280], background: '#007907', attribution: 'https://www.flickr.com/photos/payayita/3255905969/'},
{image: '8.jpg', caption: 'Majestic Sea Flap Flap', position: [740, 230], background: '#0096cf', attribution: 'https://commons.wikimedia.org/wiki/File:Manta_Ray,_Lisboa_aquarium_2008.jpg'},
{image: '9.jpg', caption: 'Danger Chicken', position: [510, 60], background: '#bff6bb', attribution: 'https://commons.wikimedia.org/wiki/File:Southern_Cassowary_7071.jpg'},
{image: '10.jpg', caption: 'Beach Chicken', position: [120, 40], background: '#6888a0', attribution: 'https://commons.wikimedia.org/wiki/File:Seagull_-_Larus_dominicanus_vetula_-_(Kelp_Gull).jpg'},
{image: '11.jpg', caption: 'Booplesnoot', position: [50, 660], background: '#a9b1bc', attribution: 'https://commons.wikimedia.org/wiki/File:Serious_bunny_(5767442711).jpg'},
{image: '12.jpg', caption: 'Velocirabbit', position: [100, 400], background: '#9baa6e', attribution: 'https://www.flickr.com/photos/timmythesuk/403782624'},
{image: '13.jpg', caption: 'Hot Moose', position: [70, 280], background: '#e2c79d', attribution: 'https://commons.wikimedia.org/wiki/File:Camels_at_Camel_Research_Farm,_Bikaner.jpg'},
{image: '14.jpg', caption: 'Thunder Chicken', position: [80, 260], size: 90, background: '#b5a282', attribution: 'https://commons.wikimedia.org/wiki/File:Ostrich_Struthio_camelus_Tanzania_3739_cropped_Nevit.jpg'},
{image: '15.jpg', caption: 'Danger Zebra', position: [700, 570], background: '#32632b', attribution: 'https://commons.wikimedia.org/wiki/File:White_Tiger_6_(3865790598).jpg'},
{image: '16.jpg', caption: 'Loud Nope Rope', position: [120, 120], background: '#d0c0ac', attribution: 'https://commons.wikimedia.org/wiki/File:Timber_Rattlesnake_(dark_coloration).JPG'},
{image: '17.jpg', caption: 'Furry Potato', position: [30, 90], attribution: 'https://www.flickr.com/photos/45383134@N00/3268972226'},
{image: '18.jpg', caption: 'Floaty Potato', position: [10, 650], background: '#008dd3', attribution: 'https://commons.wikimedia.org/wiki/File:Manatee_at_Sea_World_Orlando_Mar_10.JPG'},
{image: '19.jpg', caption: 'Dragon Mouse', position: [530, 110], background: '#afaba0', attribution: 'https://commons.wikimedia.org/wiki/File:Tree_Pangolin.JPG'},
{image: '20.jpg', caption: 'Prarie Cloud', position: [480, 440], background: '#839c29', attribution: 'https://www.flickr.com/photos/magicattic88/16653964914'},
{image: '21.jpg', caption: 'Beach Roomba', position: [50, 530], background: '#9c927c', attribution: 'https://commons.wikimedia.org/wiki/File:Horseshoe_crab_in_sand.jpg'},
{image: '22.jpg', caption: 'Floaty Spaceship', position: [560, 290], background: '#1a251e', attribution: 'https://commons.wikimedia.org/wiki/File:Cuttlefish_@_Ocean%C3%A1rio_de_Lisboa.jpg'},
{image: '23.jpg', caption: 'Tall Horse', position: [210, 540], background: '#9fc3f1', attribution: 'https://www.flickr.com/photos/danramarch/4565230826/'},
{image: '24.jpg', caption: 'Danger Mouse', position: [0, 0], attribution: 'https://commons.wikimedia.org/wiki/File:AwesomePossum-AmericanOpossum.jpg'},
{image: '25.jpg', caption: 'Disco Turkey', position: [10, 290], background: '#5d4e3c', attribution: 'https://commons.wikimedia.org/wiki/File:Peacock_feather_fan.jpg'},
{image: '26.jpg', caption: 'Sky Pupper', position: [30, 60], attribution: 'https://www.flickr.com/photos/usfwshq/8006856842/'},
{image: '27.jpg', caption: 'Panda Whale', position: [10, 150], background: '#7292a9', attribution: 'https://www.goodfreephotos.com/animals/mammals/killer-wales-orcas-jumping.jpg.php'},
{image: '28.jpg', caption: 'Unicorn Tank', position: [30, 610], background: '#b7a080', attribution: 'https://commons.wikimedia.org/wiki/File:White_rhino_2008_08.jpg'},
{image: '29.jpg', caption: 'Arrow Pig', position: [530, 540], background: '#112d22', attribution: 'https://www.flickr.com/photos/nationalzoo/5988795056'},
{image: '30.jpg', caption: 'Furry Nope', position: [20, 80], background: '#79b467', attribution: 'https://commons.wikimedia.org/wiki/File:2010-kodiak-bear-1.jpg'},
{image: '31.jpg', caption: 'Naked Snail', position: [60, 140], background: '#c5c3c8', attribution: 'https://www.flickr.com/photos/rarvesen/9467955487/'},
{image: '32.jpg', caption: 'Meth Monkey', position: [40, 700], background: '#315927', attribution: 'https://commons.wikimedia.org/wiki/File:Tarsius_syrichta.jpg'},
{image: '33.jpg', caption: 'Sea Pupper', position: [70, 480], background: '#266589', attribution: 'https://commons.wikimedia.org/wiki/File:Common_Seal_Phoca_vitulina.jpg'},
{image: '34.jpg', caption: 'Leftovers Pupper', position: [620, 500], background: '#000', attribution: 'https://commons.wikimedia.org/wiki/File:Platypus_in_Geelong.jpg'},
{image: '35.jpg', caption: 'Hoofed Panda', position: [740, 670], background: '#655b52', attribution: 'https://commons.wikimedia.org/wiki/File:Malayan_Tapir.JPG'},
{image: '36.jpg', caption: 'Murder Lobster', position: [220, 270], size: 210, background: '#49534b', attribution: 'https://www.flickr.com/photos/125265709@N08/16245381575'},
{image: '37.jpg', caption: 'Formal Chicken', position: [590, 30], background: '#6a6563', attribution: 'https://www.flickr.com/photos/liamq/5586832804/'},
{image: '38.jpg', caption: 'Fluffy Duck Otter', position: [10, 460], background: '#080a07', attribution: 'https://commons.wikimedia.org/wiki/File:%E6%B0%B4%E4%B8%AD%E3%81%A7%E6%B3%B3%E3%81%90%E3%82%AB%E3%83%A2%E3%83%8E%E3%83%8F%E3%82%B7.JPG'},
{image: '39.jpg', caption: 'Kelp Weasel', position: [570, 650], background: '#4d87a7', attribution: 'https://www.flickr.com/photos/72825507@N00/462500055/'},
{image: '40.jpg', caption: 'Goth Turkey', position: [50, 90], background: '#78ade3', attribution: 'https://commons.wikimedia.org/wiki/File:Hooded_Vulture.JPG'},
{image: '41.jpg', caption: 'Indestructible Micropig', position: [180, 210], background: '#8e9195', attribution: 'https://commons.wikimedia.org/wiki/File:SEM_image_of_Milnesium_tardigradum_in_active_state_-_journal.pone.0045682.g001-2.png'},
{image: '42.jpg', caption: 'Cat Snake', position: [20, 40], background: '#bfb39f', attribution: 'https://commons.wikimedia.org/wiki/File:Ferret_2008.png'},
{image: '43.jpg', caption: 'Snow Camel', position: [960, 260], background: '#ecf4fa', attribution: 'https://www.flickr.com/photos/dougbrown47/15358187823'},
{image: '44.jpg', caption: 'Tiger Horse', position: [100, 580], background: '#798d5a', attribution: 'https://www.flickr.com/photos/8942661@N02/2180704157/'},
{image: '45.jpg', caption: 'Swamp Horse', position: [40, 620], background: '#8f9dc0', attribution: 'https://commons.wikimedia.org/wiki/File:Moose-00473.jpg'},
{image: '46.jpg', caption: 'Zappy Snek', position: [260, 300], background: '#3b5638', attribution: 'https://commons.wikimedia.org/wiki/File:Electric-eel.jpg'},
{image: '47.jpg', caption: 'Pouch Donkey', position: [20, 600], background: '#9dc87a', attribution: 'https://www.flickr.com/photos/pelican/5691944721/'},
{image: '48.jpg', caption: 'Tree Cat', position: [70, 60], background: '#2a5211', attribution: 'https://commons.wikimedia.org/wiki/File:Lemur_Catta02.jpg'},
{image: '49.jpg', caption: 'Ouchball', position: [80, 70], background: '#ededf5', attribution: 'https://pixabay.com/en/hedgehog-animal-baby-cute-small-468228/'},
{image: '50.jpg', caption: 'Pride Chicken', position: [40, 320], background: '#0d110c', attribution: 'https://pixabay.com/en/rainbow-lorikeet-parrots-australia-686100/'},
{image: '51.jpg', caption: 'Moon Kitty', position: [610, 730], background: '#9ea7ad', attribution: 'https://commons.wikimedia.org/wiki/File:Manul_close.jpg'},
{image: '52.jpg', caption: 'Quill Badger', position: [600, 60], background: '#533f38', attribution: 'https://pixabay.com/en/porcupines-erethizontidae-animal-957114/'},
// {image: '.jpg', caption: '', position: [0, 0], background: '', attribution: ''},
];
var CURRENT_THING = null;
var TIP_TIMER = null;
// Add labels and some default values.
for(var i=0; i<THINGS.length; i++) {
THINGS[i].id = i;
THINGS[i].size = THINGS[i].size || 140;
THINGS[i].background = THINGS[i].background || '#000';
}
// Create a shuffled list of things for use with randomization.
var SHUFFLED_THINGS = []
for(var i=0; i<THINGS.length; i++) {
SHUFFLED_THINGS.push(THINGS[i].id);
}
for(var counter=SHUFFLED_THINGS.length-1; counter>=0; counter--) {
// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
var index = Math.floor(Math.random() * (counter+1));
// And swap the last element with it
var temp = SHUFFLED_THINGS[counter];
SHUFFLED_THINGS[counter] = SHUFFLED_THINGS[index];
SHUFFLED_THINGS[index] = temp;
}
var getThingById = function(id) {
if(0 <= id && id < THINGS.length) {
return THINGS[id];
} else {
return THINGS[0];
}
}
var getThingByLabel = function(label) {
if(label[0] === '#') label = label.substr(1);
return getThingById(parseInt(label, 10) - 1);
}
// Get the next thing in the random sequence.
var getNextShuffledThing = function() {
// Shouldn't happen, but just in case.
if(!CURRENT_THING) { return getThingById(SHUFFLED_THINGS[0]); }
var shuffleIndex = SHUFFLED_THINGS.indexOf(CURRENT_THING.id) + 1;
if(shuffleIndex >= SHUFFLED_THINGS.length) shuffleIndex = 0;
return getThingById(SHUFFLED_THINGS[shuffleIndex]);
}
// Get the next thing in numerical order.
var getNextThing = function() {
// Shouldn't happen, but just in case.
if(!CURRENT_THING) { return THINGS[0]; }
var nextId = (CURRENT_THING.id + 1) % THINGS.length;
return getThingById(nextId);
}
// Get the previous thing in numerical order.
var getPrevThing = function() {
// Shouldn't happen, but just in case.
if(!CURRENT_THING) { return THINGS[0]; }
var prevId = (CURRENT_THING.id - 1) % THINGS.length;
if(prevId < 0) prevId = prevId + THINGS.length;
return getThingById(prevId);
}
// Clear the tip timer.
var clearTipTimer = function() {
if(TIP_TIMER) {
clearTimeout(TIP_TIMER);
TIP_TIMER = null;
}
// Try to not show it again.
if(window.localStorage) {
localStorage.setItem('sawTip', 'true');
}
}
document.addEventListener('DOMContentLoaded', function () {
// Get persistent references to some elements.
var containerElm = document.getElementById('container');
var thingElm = document.getElementById('thing');
var captionElm = document.getElementById('caption');
var attributionElm = document.getElementById('attribution');
var tipElm = document.getElementById('tip');
var githubElm = document.getElementById('github');
var anchorElm = document.getElementById('anchor');
// Helper methods.
var scaleThing = function(elm) {
elm = elm || document.getElementById('picture');
if(elm) {
var xScale = document.documentElement.clientWidth / elm.width;
var yScale = document.documentElement.clientHeight / elm.height;
var xyScale = Math.min(xScale, yScale);
thingElm.style.transform = 'scale('+xyScale+','+xyScale+')';
}
};
var loadingThing = false;
var displayThing = function(thing, setHash) {
// Only load one thing at a time.
if(loadingThing) return;
loadingThing = true;
if(!document.body.className.match(/(?:^|\s)loading(?!\S)/)) {
document.body.className += ' loading';
}
// Display a thing.
var elm = document.createElement('img');
elm.addEventListener('load', function() {
// Hide the loading indicator if needed.
if(!document.body.className.match(/(?:^|\s)first-load(?!\S)/)) {
document.body.className += ' first-load';
}
if(document.body.className.match(/(?:^|\s)loading(?!\S)/)) {
document.body.className = document.body.className.replace(/(?:^|\s)loading(?!\S)/g, '');
}
// Remove any existing image.
var oldImg = document.getElementById('picture');
if(oldImg) oldImg.parentNode.removeChild(oldImg);
// Display the image.
elm.id = 'picture';
thingElm.appendChild(elm);
// Clear existing attribution links.
while (attributionElm.hasChildNodes()) { attributionElm.removeChild(attributionElm.lastChild); }
// Populate and position caption/attribution.
captionElm.innerText = thing.caption
captionElm.style.top = thing.position[0] + 'px';
captionElm.style.left = thing.position[1] + 'px';
captionElm.style['font-size'] = thing.size + 'px';
var attributeLink = document.createElement('a');
attributeLink.href = thing.attribution;
attributeLink.innerText = thing.attribution;
attributeLink.target = '_blank';
attributeLink.addEventListener('click', function(evt) {
evt.stopPropagation();
ga('send', 'event', 'Attribution', 'click', thing.id+1);
return true;
});
attributionElm.appendChild(attributeLink);
// Scale the thing to match the screen.
scaleThing(elm);
// Change the title.
document.title = thing.caption;
// Set background color.
document.body.style['background-color'] = thing.background;
// Either set or unset the location hash, or leave it alone if setHash is not passed.
if(setHash === true) {
window.location.hash = '#' + (thing.id + 1);
} else if(setHash === false) {
if(window.location.hash && window.location.hash != '#') window.location.hash = '';
}
// Set the anchor link.
anchorElm.href = '#' + (thing.id + 1);
// Done loading.
loadingThing = false;
CURRENT_THING = thing;
ga('set', 'page', '/'+(thing.id+1));
ga('send', 'pageview');
});
elm.src = thing.image;
};
// Set up some event handlers.
window.addEventListener('resize', function() { scaleThing(); });
window.addEventListener('hashchange', function() {
// Don't do anything when clearing the hash.
if(window.location.hash == '' || window.location.hash == '#') return;
// Don't re-display if the hash matches the current thing.
var thing = getThingByLabel(window.location.hash);
if(CURRENT_THING && CURRENT_THING.id == thing.id) return;
displayThing(thing);
});
document.body.addEventListener('click', function() {
ga('send', 'event', 'Body', 'click');
displayThing(getNextShuffledThing(), false);
clearTipTimer();
});
document.body.addEventListener('keydown', function(evt) {
if(evt.keyCode && (evt.keyCode == 32 || evt.keyCode == 37 || evt.keyCode == 39)) {
evt.stopPropagation();
evt.preventDefault();
if(!loadingThing && CURRENT_THING) {
switch(evt.keyCode) {
case 32:
// Space.
ga('send', 'event', 'Arrow Keys', 'press', 'space');
displayThing(getNextShuffledThing(), false);
clearTipTimer();
break;
case 37:
// Left arrow.
ga('send', 'event', 'Arrow Keys', 'press', 'left');
displayThing(getPrevThing(), true);
clearTipTimer();
break;
case 39:
// Right arrow.
ga('send', 'event', 'Arrow Keys', 'press', 'right');
displayThing(getNextThing(), true);
clearTipTimer();
break;
}
}
return false;
}
return true;
});
tipElm.addEventListener('click', function(evt) {
evt.stopPropagation();
// Hide it.
tipElm.className = '';
// Try to not show again.
clearTipTimer();
});
githubElm.addEventListener('click', function(evt) {
evt.stopPropagation();
ga('send', 'event', 'GitHub', 'click', CURRENT_THING && (CURRENT_THING.id + 1));
return true;
});
anchorElm.addEventListener('click', function(evt) {
evt.stopPropagation();
ga('send', 'event', 'Anchor', 'click', CURRENT_THING && (CURRENT_THING.id + 1));
return true;
});
// Start the tip timer if needed.
if(!window.localStorage || localStorage.getItem('sawTip') != 'true') {
TIP_TIMER = setTimeout(function() {
tipElm.className = 'show';
}, 4000);
}
// Do initial load.
if(window.location.hash && window.location.hash != '#') {
displayThing(getThingByLabel(window.location.hash));
} else {
displayThing(getNextShuffledThing());
}
});
// Google tracking, sorry.
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-19700911-2', 'auto');
</script>
</body>
</html>