-
Notifications
You must be signed in to change notification settings - Fork 0
/
jflickery.js
127 lines (102 loc) · 3.95 KB
/
jflickery.js
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
/*
* jflickery.js - Flickr Javascript API wrapper
*
* http://edmoremoyo.com
*/
var JFLICKERY_CONFIG = JFLICKERY_CONFIG || {};
/*
* @module JFLICKERY
*/
var JFLICKERY = (function (spec) {
"use strict";
var that = {};
/*
* @namespace JFLICKERY
* @object getUserID
* @return {String} user id
*/
that.getUserID = function () {
return spec.myuserid || "";
};
/*
* @namespace JFLICKERY
* @object getApiKey
* @return {String} api key
*/
that.getApiKey = function () {
return spec.mykey || "";
};
/*
* @namespace JFLICKERY
* @object getJSONP
*/
that.getJSONP = function () {
var script = document.createElement('script'),
user_id = that.getUserID(),
api_key = that.getApiKey(),
base_url = "http://api.flickr.com/services/rest/",
callback = Array.prototype.slice.call(arguments, 0, 1),
photoset_id = Array.prototype.slice.call(arguments, 1, 2),
scripts = document.getElementsByTagName('script'),
length = scripts.length,
i,
child;
for (i = 0; i < length; i += 1) {
if (scripts[i].getAttribute("src") !== null) {
if (scripts[i].getAttribute("src").indexOf(base_url + '?method=flickr.' + callback) >= 0) {
child = scripts[i];
document.getElementsByTagName('head')[0].removeChild(child);
}
}
}
script.setAttribute('src', base_url + '?method=flickr.' + callback + '&api_key=' + api_key + '&user_id=' + user_id + '&photoset_id=' + photoset_id + '&format=json&jsoncallback=' + callback);
script.setAttribute('type', 'text/javascript');
document.getElementsByTagName('head')[0].appendChild(script);
};
return that;
}(JFLICKERY_CONFIG));
var photosets = {};
photosets.getList = function (data) {
"use strict";
var i, a, li, content, div, ul;
div = document.createElement('div');
div.setAttribute('class', "setlinks");
ul = document.createElement('ul');
ul.setAttribute('class', "links");
for (i = 0; i < data["photosets"]["photoset"].length; i += 1) {
li = document.createElement('li');
li.setAttribute('class', "link");
a = document.createElement('a');
a.setAttribute('id', data["photosets"]["photoset"][i]["id"]);
a.setAttribute('class', "photoset");
content = data["photosets"]["photoset"][i]["title"]._content;
a.innerHTML = content;
document.getElementsByTagName('body')[0].appendChild(div);
document.getElementsByClassName('setlinks')[0].appendChild(ul);
document.getElementsByClassName('links')[0].appendChild(li);
document.getElementsByClassName('link')[i].appendChild(a);
}
};
photosets.getPhotos = function (data) {
"use strict";
var i, img, li, content, div, ul, farm, server, id, secret;
div = document.createElement('div');
div.setAttribute('class', "setphotos");
ul = document.createElement('ul');
ul.setAttribute('class', "photos");
for (i = 0; i < data["photoset"]["photo"].length; i += 1) {
farm = data["photoset"]["photo"][i]["farm"];
server = data["photoset"]["photo"][i]["server"];
id = data["photoset"]["photo"][i]["id"];
secret = data["photoset"]["photo"][i]["secret"];
li = document.createElement('li');
li.setAttribute('class', "photo");
img = document.createElement('img');
img.setAttribute('src', 'http://farm' + farm + '.static.flickr.com/' + server + '/' + id + '_' + secret + '.jpg');
img.setAttribute('title', data["photoset"]["photo"][i]["title"]);
document.getElementsByTagName('body')[0].appendChild(div);
document.getElementsByClassName('setphotos')[0].appendChild(ul);
document.getElementsByClassName('photos')[0].appendChild(li);
document.getElementsByClassName('photo')[i].appendChild(img);
}
};