| 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 |
|
| 8 |
|
| 9 |
userid: "", |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
username: "", |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
setid: "", |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
tags: "", |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
searchText: "", |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 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: "https://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 |
|