-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
198 lines (165 loc) · 4.38 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
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.stephenmorley.org/javascript/queues/Queue.js"></script>
<script type="text/javascript">
var settings = {
hashtags: "VemRed", // separated by comma
client_id: "b72d081f9d4e48639b48bdc682eafc99", // your instagram API key
images_to_fetch: 20, // fetch 20 images every request to instagram
fetch_time: 50, // fetch pictures every 50 seconds
display_time: 10 // change picture every 10 seconds
}
// the heart of this app
var queue = new Queue();
function fillQueue() {
// make the queue always empty so we can see all pics!
if (queue.getLength() < 10)
{
$.ajax({
dataType: "jsonp",
url: "https://api.instagram.com/v1/tags/" + settings.hashtags + "/media/recent",
data: {
access_token: null,
client_id: settings.client_id,
count: settings.images_to_fetch
},
success: function(response) {
var photos = response.data;
console.log("Number of pictures fetched: " + photos.length);
for (var i = 0; i < photos.length; i++)
{
var photo = photos[i];
var img = photo.images.standard_resolution.url; // get photo url
var username = photo.user.username; // get username
var comment = photo.caption.text; // get message
// put the picture on queue
queue.enqueue({img: img, username: username, comment: comment});
console.log("Added image taken by: " + username);
}
}
});
}
else
{
console.log("Queue is full!");
}
setTimeout(function() {
fillQueue();
}, settings.fetch_time * 1000);
}
function showQueue()
{
if (! queue.isEmpty())
{
var img = queue.dequeue();
console.log("Displaying: " + img.img);
// check if the images are different
if ($('.instagram-pic > img').attr('src') != img.img)
{
console.log('New picture, now displaying: ' + img.img);
// preload image before display
$('<img class="loader" />').attr('src', img.img).appendTo('body').load(function(){
$('.instagram-username, .instagram-pic > img, .instagram-comment').fadeOut(600, function(){
$('.instagram-pic > img').attr('src', img.img);
$('.instagram-comment > p').html(img.comment);
$('.instagram-username > p').html('@' + img.username);
}).fadeIn();
});
}
}
setTimeout(function() {
showQueue();
}, settings.display_time * 1000);
}
$(document).ready(function() {
fillQueue();
showQueue();
});
</script>
<style>
* {
margin:0px;
padding: 0px;
}
body {
height: 100%;
font-family: 'Tahoma';
background-image: url('http://i.imgur.com/66ptSTe.jpg');
}
.container {
width: 700px;
padding-top: 50px;
margin: 0 auto;
}
.header-container {
height: 35px;
text-align: center;
background-color: #416f96;
border-radius: 20px 20px 0 0;
}
.header-container > span {
height: 40px;
color: #ffffff;
font-size: 20px;
font-weight: bold;
line-height: 35px;
}
.image-container {
padding-top: 0px;
height: 650px;
width: 700px;
background-color: #cfcfcf;
border-radius: 0 0 20px 20px;
margin: 0 auto;
text-align: center;
}
p {
padding: 10px;
}
.instagram-username > p {
width: 630px;
margin: 0 auto;
font-family: Tahoma;
font-size: 40px;
font-weight: bold;
}
.instagram-comment > p {
width: 630px;
margin: 0 auto;
font-family: Tahoma;
font-size: 12px;
}
.instagram-pic {
width: 630px;
margin: 0 auto;
}
.loader {
display: none;
}
img {
width: 630px;
height: 500px;
}
</style>
</head>
<body>
<div class="container">
<div class="header-container">
<span>Envie sua foto com #VemRed!</span>
</div>
<div class="image-container">
<div class="instagram-username">
<p>Instagram for Parties!</p>
</div>
<div class="instagram-pic">
<img src="http://i.imgur.com/66ptSTe.jpg">
</div>
<div class="instagram-comment">
<p>Instagram for Parties!</p>
</div>
</div>
</div>
<img class="loader"></img>
</body>
</html>