summaryrefslogtreecommitdiff
path: root/js/dojo-1.6/dojox/image/FlickrBadge.js
blob: e4462c154df5027264ab1237895ba8cad6a22e2f (plain)
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
/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dojox.image.FlickrBadge"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dojox.image.FlickrBadge"] = true;
dojo.provide("dojox.image.FlickrBadge");

dojo.require("dojox.image.Badge");
dojo.require("dojox.data.FlickrRestStore");

dojo.declare("dojox.image.FlickrBadge", dojox.image.Badge, {
	children: "a.flickrImage",

	// userid: String
	// 		If you know your Flickr userid, you can set it to prevent a call to fetch the id
	userid: "",

	// username: String
	// 		Your Flickr username
	username: "",

	// setid: String
	// 		The id of the set to display
	setid: "",

	// tags: String|Array
	// 		A comma separated list of tags or an array of tags to grab from Flickr
	tags: "",

	// searchText: String
	// 		Free text search.  Photos who's title, description, or tags contain the text will be displayed
	searchText: "",

	// target: String
	// 		Where to display the pictures when clicked on.  Valid values are the same as the target attribute
	// 		of the A tag.
	target: "",

	apikey: "8c6803164dbc395fb7131c9d54843627",
	_store: null,

	postCreate: function(){
		if(this.username && !this.userid){
			var def = dojo.io.script.get({
				url: "http://www.flickr.com/services/rest/",
				preventCache: true,
				content: {
					format: "json",
					method: "flickr.people.findByUsername",
					api_key: this.apikey,
					username: this.username
				},
				callbackParamName: "jsoncallback"
			});
			def.addCallback(this, function(data){
				if(data.user && data.user.nsid){
					this.userid = data.user.nsid;
					if(!this._started){
						this.startup();
					}
				}
			});
		}
	},

	startup: function(){
		if(this._started){ return; }
		if(this.userid){
			var query = {
				userid: this.userid
			};
			if(this.setid){
				query["setid"] = this.setid;
			}
			if(this.tags){
				query.tags = this.tags;
			}
			if(this.searchText){
				query.text = this.searchText;
			}
			var args = arguments;
			this._store = new dojox.data.FlickrRestStore({ apikey: this.apikey });
			this._store.fetch({
				count: this.cols * this.rows,
				query: query,
				onComplete: dojo.hitch(this, function(items){
					dojo.forEach(items, function(item){
						var a = dojo.doc.createElement("a");
						dojo.addClass(a, "flickrImage");
						a.href = this._store.getValue(item, "link");
						if(this.target){
							a.target = this.target;
						}

						var img = dojo.doc.createElement("img");
						img.src = this._store.getValue(item, "imageUrlThumb");
						dojo.style(img, {
							width: "100%",
							height: "100%"
						});

						a.appendChild(img);
						this.domNode.appendChild(a);
					}, this);
					dojox.image.Badge.prototype.startup.call(this, args);
				})
			});
		}
	}
});

}