-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorgi.js
More file actions
103 lines (88 loc) · 2.01 KB
/
corgi.js
File metadata and controls
103 lines (88 loc) · 2.01 KB
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
$(document).ready(function() {
photoUrls = [];
shown = [];
getPhotos(1);
getPhotos(2);
function getPhotos(pNum) {
var dataObj = {
api_key : '6d8c3496a8f9062f89986effee7f2fe3',
method : 'flickr.photos.search',
tags: 'corgi',
sort: 'interestingness-desc',
min_upload_date: getDate(),
content_type: 1,
media: 'photos',
format: 'json',
nojsoncallback: 1,
page: pNum
};
$.ajax({
url: 'http://api.flickr.com/services/rest/',
data: dataObj,
success: process,
error: function() { console.log(error); },
dataType: "json"
});
}
function process(data) {
var pArr = data.photos.photo;
for (var i = 0; i < pArr.length; i++) {
dataObj = { method : 'flickr.photos.getSizes',
api_key : '6d8c3496a8f9062f89986effee7f2fe3',
photo_id : pArr[i].id,
format : "json",
nojsoncallback : 1 };
$.ajax({
url: 'http://api.flickr.com/services/rest/',
data: dataObj,
success: function(data) {
pUrl = "";
var variants = data.sizes.size;
for (var i = 0; i < variants.length; i++) {
if (variants[i].label == "Medium") {
pUrl = variants[i].source;
break;
}
if (variants[i].label == "Original") {
pUrl = variants[i].source;
}
}
photoUrls.push(pUrl);
},
error: function() { console.log(error); },
dataType: "json"
});
}
}
function updatePhoto() {
var foundNew = false;
var index = 0;
while(!foundNew) {
index = getRandomInt(0, photoUrls.length);
if (shown.indexOf(index) < 0) {
foundNew = true;
}
}
$('#corgi').attr("src", photoUrls[index]);
shown.push(index);
}
$('#more').click(function() {
updatePhoto();
});
$('#done').click(function() {
alert('Error: Corgi time is unstoppable.');
updatePhoto();
});
function getDate() {
var x = new Date();
with(x)
{
setMonth(getMonth()-1);
setDate(1);
}
return x;
}
function getRandomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
});