-
Notifications
You must be signed in to change notification settings - Fork 1
/
stupid-website.html
183 lines (160 loc) · 4.99 KB
/
stupid-website.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
<html><head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<style>
body {
width: 90%;
font: 100% Helvetica;
font-weight: bold;
font-color: rgb(69,131,196);
}
#not-thursday-pictures {
position: relative;
margin: 10px auto;
padding: 0;
width: 100%;
height: auto;
border-collapse: collapse;
text-align: center;
}
#not-thursday-pictures tr {
margin: 0;
padding: 0;
border: 0;
width: 100%;
}
#not-thursday-pictures tr td {
margin: 0;
padding: 4px 8px;
border: 0;
padding-bottom: 3em;
}
#header {
margin: 5%;
align: center;
}
#header tr td {
padding-left: 20px;
}
.noshow {
display:none;
}
</style>
</head>
<body>
<table id="header" align="center" >
<tbody>
<tr>
<td width="20%"> <img src="officerTBT-04.png" alt="OfficerTBT" width="217" height="227"> </td>
<td width="70%" id="title"> <p> Now I aint sayin its unacceptable to post a #tbt when it's not Thursday...but it is completely unacceptable and perpetrators deserve to be shamed for their wrongdoing. If you have any self respect you will realize this travesty and join us in shaming these #tbt failures. </p> </td>
<td width="10%"> <img id="reload-button" src="loadbutton-05.png"><img id="reload-button-pressed" src="loadbutton-pressed-07.png" class="noshow"> </td>
</tr>
</tbody>
</table>
<table id="not-thursday-pictures">
<tbody>
<tr>
<td width="30%" id = "pic1"></td>
<td width="30%" id = "pic2"></td>
<td width="30%" id = "pic3"></td>
</tr>
<tr>
<td id = "pic4"></td>
<td id = "pic5"></td>
<td id = "pic6"></td>
</tr>
</tbody>
</table>
<script>
var NUM_IMAGES = 6;
$(document).ready(function() {
// bind event listeners
$('#reload-button').click(fetchImages);
$('#reload-button-pressed').click(fetchImages);
$('#reload-button').mousedown(pressButton);
$('#reload-button-pressed').mouseup(pressButtonAndFetchImages);
fetchImages();
});
function pressButton() {
$('#reload-button').toggleClass('noshow');
$('#reload-button-pressed').toggleClass('noshow');
}
function pressButtonAndFetchImages() {
pressButton();
fetchImages();
}
function fetchImages() {
var tagName = 'tbt';
url = 'https://api.instagram.com/v1/tags/' + tagName +
'/media/recent?callback=?&client_id=68de522f648043ee922bcf14545cfa7a';
$.getJSON(url, renderImages);
}
/**
* Display the images to pick from. Hide the one-image view.
*/
function renderImages(response) {
var picSize = 400; // pixels
var photos = response.data;
var myURLs = new Array();
// myTags is a global variable; this has the effect of clearing it.
myTags = new Array();
var photoIndices = getPhotoIndices(photos);
for (i = 0; i < NUM_IMAGES; i++){
var pic = photos[photoIndices[i]];
myURLs[i] = pic.images.standard_resolution.url;
myTags[i] = pic.tags;
$('#pic' + (i+1)).html(createImageHTML(pic.images.standard_resolution.url,
picSize, i));
var date = new Date(1000*pic.created_time);
var day = date.getDay();
var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var name = pic.user.username;
$('#pic' + (i+1)).append('<p>Posted by <a href="http://instagram.com/'+ name+'" target="_blank">@'+name+'</a> on <strong>' + days[day] + '?!!?!?!</strong></p>');
}
}
/**
* Choose NUM_IMAGES pictures from the results returned by instagram. If there are
* enough options, choose images in the "golden tag zone" (see top of file).
* @param {Array} mediaArray the array of pictures returned by instagram.
* @return {Array.<Number>} the indices of the chosen pictures.
*/
function getPhotoIndices(mediaArray) {
var notOnThursday = new Array();
for (var i = 0; i < mediaArray.length; i++) {
var date = new Date(1000*mediaArray[i].created_time);
if(date.getDay() != 4){
notOnThursday.push(i);
}
}
var chosen = new Array();
// If there are less than NUM_IMAGES pictures to choose from, take all that are
// available and repeat the last one until there are NUM_IMAGES.
if (notOnThursday.length < NUM_IMAGES) {
for (var i = 0; i < NUM_IMAGES; i++) {
if (i < notOnThursday.length) {
chosen.push(i);
} else {
chosen.push(notOnThursday.length - 1);
}
}
return chosen;
}
// Try to get NUM_IMAGES images
for( var i = 0; i < NUM_IMAGES; i++){
nextIndex = notOnThursday[i];
chosen.push(nextIndex);
}
return chosen;
}
/**
* Create the html for one of the NUM_IMAGES images.
* @param {String} url the url of the picture to display.
* @param {Number} size the size of the displayed picture in pixels.
* @param {Number} index which of the NUM_IMAGES images this picture is.
* @return {String} a string of the html to display this picture.
*/
function createImageHTML(url, size, index) {
return '<img src='+ url + ' alt=":(" width="'+ size +
'" height="' + size + '" index="' + index + '"></img>'
}
</script>
</body></html>