[483] | 1 | define(["dojo", "dojox/main", "dojox/image/Badge", "dojox/data/FlickrRestStore"], function(dojo, dojox){ |
---|
| 2 | |
---|
| 3 | dojo.getObject("image", true, dojox); |
---|
| 4 | return dojo.declare("dojox.image.FlickrBadge", dojox.image.Badge, { |
---|
| 5 | children: "a.flickrImage", |
---|
| 6 | |
---|
| 7 | // userid: String |
---|
| 8 | // If you know your Flickr userid, you can set it to prevent a call to fetch the id |
---|
| 9 | userid: "", |
---|
| 10 | |
---|
| 11 | // username: String |
---|
| 12 | // Your Flickr username |
---|
| 13 | username: "", |
---|
| 14 | |
---|
| 15 | // setid: String |
---|
| 16 | // The id of the set to display |
---|
| 17 | setid: "", |
---|
| 18 | |
---|
| 19 | // tags: String|Array |
---|
| 20 | // A comma separated list of tags or an array of tags to grab from Flickr |
---|
| 21 | tags: "", |
---|
| 22 | |
---|
| 23 | // searchText: String |
---|
| 24 | // Free text search. Photos who's title, description, or tags contain the text will be displayed |
---|
| 25 | searchText: "", |
---|
| 26 | |
---|
| 27 | // target: String |
---|
| 28 | // Where to display the pictures when clicked on. Valid values are the same as the target attribute |
---|
| 29 | // of the A tag. |
---|
| 30 | target: "", |
---|
| 31 | |
---|
| 32 | apikey: "8c6803164dbc395fb7131c9d54843627", |
---|
| 33 | _store: null, |
---|
| 34 | |
---|
| 35 | postCreate: function(){ |
---|
| 36 | if(this.username && !this.userid){ |
---|
| 37 | var def = dojo.io.script.get({ |
---|
| 38 | url: "http://www.flickr.com/services/rest/", |
---|
| 39 | preventCache: true, |
---|
| 40 | content: { |
---|
| 41 | format: "json", |
---|
| 42 | method: "flickr.people.findByUsername", |
---|
| 43 | api_key: this.apikey, |
---|
| 44 | username: this.username |
---|
| 45 | }, |
---|
| 46 | callbackParamName: "jsoncallback" |
---|
| 47 | }); |
---|
| 48 | def.addCallback(this, function(data){ |
---|
| 49 | if(data.user && data.user.nsid){ |
---|
| 50 | this.userid = data.user.nsid; |
---|
| 51 | if(!this._started){ |
---|
| 52 | this.startup(); |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | }); |
---|
| 56 | } |
---|
| 57 | }, |
---|
| 58 | |
---|
| 59 | startup: function(){ |
---|
| 60 | if(this._started){ return; } |
---|
| 61 | if(this.userid){ |
---|
| 62 | var query = { |
---|
| 63 | userid: this.userid |
---|
| 64 | }; |
---|
| 65 | if(this.setid){ |
---|
| 66 | query["setid"] = this.setid; |
---|
| 67 | } |
---|
| 68 | if(this.tags){ |
---|
| 69 | query.tags = this.tags; |
---|
| 70 | } |
---|
| 71 | if(this.searchText){ |
---|
| 72 | query.text = this.searchText; |
---|
| 73 | } |
---|
| 74 | var args = arguments; |
---|
| 75 | this._store = new dojox.data.FlickrRestStore({ apikey: this.apikey }); |
---|
| 76 | this._store.fetch({ |
---|
| 77 | count: this.cols * this.rows, |
---|
| 78 | query: query, |
---|
| 79 | onComplete: dojo.hitch(this, function(items){ |
---|
| 80 | dojo.forEach(items, function(item){ |
---|
| 81 | var a = dojo.doc.createElement("a"); |
---|
| 82 | dojo.addClass(a, "flickrImage"); |
---|
| 83 | a.href = this._store.getValue(item, "link"); |
---|
| 84 | if(this.target){ |
---|
| 85 | a.target = this.target; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | var img = dojo.doc.createElement("img"); |
---|
| 89 | img.src = this._store.getValue(item, "imageUrlThumb"); |
---|
| 90 | dojo.style(img, { |
---|
| 91 | width: "100%", |
---|
| 92 | height: "100%" |
---|
| 93 | }); |
---|
| 94 | |
---|
| 95 | a.appendChild(img); |
---|
| 96 | this.domNode.appendChild(a); |
---|
| 97 | }, this); |
---|
| 98 | dojox.image.Badge.prototype.startup.call(this, args); |
---|
| 99 | }) |
---|
| 100 | }); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | }); |
---|
| 104 | }); |
---|
| 105 | |
---|