-
Notifications
You must be signed in to change notification settings - Fork 0
/
wall.html
162 lines (157 loc) · 5.94 KB
/
wall.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
<!DOCTYPE html>
<html>
<head>
<title>Observations Wall</title>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.0/masonry.pkgd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/packery/1.4.1/packery.pkgd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.js"></script>
<style type="text/css">
body {font-family: "Trebuchet MS", Helvetica; background-color: black;}
#grid {position: fixed !important;width:100% !important;height: 100% !important;}
.grid-item .obs-img {width: 100%; display: block;}
.grid-item .inner {padding:5px;position:relative;}
.grid-item {float:left; }
/* small screen */
/*body { font-size: 90%; }
.grid-item, .grid-sizer {width: 10%;}
.grid-item-medium {width: 20%;}
.grid-item-big {width: 30%;}
.blurb img{ max-width: 20px; }*/
/* big screen */
body { font-size: 20%;}
.grid-item,
.grid-sizer {width: 182px; min-height: 30px;}
.grid-item-medium {width: 364px;}
.grid-item-big {width: 728px;}
.blurb img{ max-width: 10px; }
/* really big screen */
/*body { font-size: 20%;}
.grid-item, .grid-sizer {width: 2.5%; min-height: 30px;}
.grid-item-medium {width: 5%;}
.grid-item-big {width: 10%;}
.blurb img{ max-width: 10px; }*/
.blurb {position: absolute; left: 0px; bottom: 0px; width: 100%; color: white; white-space: nowrap;overflow:hidden;}
.blurb .blurbinner {margin: 5px; padding: 5px;background-color: rgba(0,0,0,0.3); width: auto; }
.blurb img {border-radius: 500%; vertical-align: middle;}
.blurb .species {float: right; max-width: 50%; overflow:hidden; display:none;}
.grid-item-medium .species, .grid-item-big .species { display: inline; }
.loading {position: absolute; top: 50%; left: 50%;width: 100px; height: 1em; margin-left: -50px; margin-top: -0.5em; color:white; font-size: 1000%;}
h1 {
position: absolute;
left: 50%;
margin-left: -200px;
bottom: 50px;
width: 400px;
font-size: 1000%;
color: white;
background-color: black;
opacity: 0.7;
border-radius: 500px;
z-index: 1000;
padding: 20px 30px;
text-align: center;
}
</style>
</head>
<body>
<h1>Recent Observations</h1>
<div id="grid" class="grid">
<div class="grid-sizer"></div>
<div class="gutter-sizer"></div>
<div class="loading">Loading...</div>
</div>
<script id="observation-template" type="text/x-handlebars-template">
<div class="observation grid-item {{gridClass}}">
<div class="inner">
<a href="{{uri}}"><img src="{{_imgURL}}" class="obs-img" width="{{photo_width}}" height="{{photo_height}}"/></a>
<div class="blurb">
<div class="blurbinner">
{{#if user_icon}}
<img src="{{user_icon}}"/>
{{/if}}
{{user.login}}
<span class="species">{{species_name}}</span>
</div>
</div>
</div>
</div>
</script>
<script type="text/javascript">
var obsTemplateSource = $("#observation-template").html()
obsTemplate = Handlebars.compile(obsTemplateSource)
window.grid = $('#grid').masonry({
itemSelector: '.grid-item',
columnWidth: '.grid-sizer',
percentPosition: true,
transitionDuration: 0
})
function dimsForPhoto( photo, size ) {
var originalWidth = photo.original_dimensions.width;
var originalHeight = photo.original_dimensions.height;
var width = 182;
if ( size == "medium" ) {
width = width * 2;
} else if ( size == "large" ) {
width = width * 4;
}
return {
width: width,
height: parseInt( ( width / originalWidth ) * originalHeight )
}
}
function reloadObservations() {
window.grid.masonry( 'remove', $('.grid-item') )
$('.grid-item').remove()
$('.loading').show()
$.getJSON('https://api.inaturalist.org/v1/observations?verifiable=true&per_page=200', function(json) {
$('.loading').hide()
var observations = json.results;
if (observations.length == 0) {
// console.log("[DEBUG] json was empty, skipping")
return
}
window.lastObservationID = observations[0].id
$.each(observations, function() {
if (!this.photos[0] ||
!this.photos[0].url ||
!this.photos[0].original_dimensions ||
this.photos[0].url.match(/copyright-infringement/) ||
this.photos[0].url.match(/attachment_defaults/)) {
return
}
var dims;
if (this.cached_votes_total > 0) {
this.gridClass = 'grid-item-big'
this._imgURL = this.photos[0].url.replace( /square/, "large" )
dims = dimsForPhoto( this.photos[0], "large" )
} else if (this.comments_count > 0) {
this.gridClass = 'grid-item-medium'
this._imgURL = this.photos[0].url.replace( /square/, "medium" )
dims = dimsForPhoto( this.photos[0], "medium" )
} else {
this.gridClass = ''
this._imgURL = this.photos[0].url.replace( /square/, "small" )
dims = dimsForPhoto( this.photos[0], "small" )
}
this.photo_width = dims.width;
this.photo_height = dims.height;
this.species_name = this.taxon ? this.taxon.preferred_common_name : this.species_guess
this.user_icon = this.user.icon && this.user.icon.match(/static/) ? this.user.icon : null;
var elt = $(obsTemplate(this))
$('#grid').append(elt)
window.grid.masonry('appended', elt)
})
layoutMasonry( );
})
}
function layoutMasonry() {
grid.masonry('layout')
}
$(document).ready(function() {
reloadObservations()
setInterval(reloadObservations, 1000*60*5)
})
</script>
</body>
</html>