root / trunk / web / dojo / dojox / data / FlickrStore.js @ 10
History | View | Annotate | Download (3.99 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.data.FlickrStore"]){ |
||
9 | dojo._hasResource["dojox.data.FlickrStore"]=true; |
||
10 | dojo.provide("dojox.data.FlickrStore");
|
||
11 | dojo.require("dojo.data.util.simpleFetch");
|
||
12 | dojo.require("dojo.io.script");
|
||
13 | dojo.require("dojo.date.stamp");
|
||
14 | dojo.require("dojo.AdapterRegistry");
|
||
15 | (function(){
|
||
16 | var d=dojo;
|
||
17 | dojo.declare("dojox.data.FlickrStore",null,{constructor:function(_1){ |
||
18 | if(_1&&_1.label){
|
||
19 | this.label=_1.label;
|
||
20 | } |
||
21 | if(_1&&"urlPreventCache" in _1){ |
||
22 | this.urlPreventCache=_1.urlPreventCache?true:false; |
||
23 | } |
||
24 | },_storeRef:"_S",label:"title",urlPreventCache:true,_assertIsItem:function(_2){ |
||
25 | if(!this.isItem(_2)){ |
||
26 | throw new Error("dojox.data.FlickrStore: a function was passed an item argument that was not an item"); |
||
27 | } |
||
28 | },_assertIsAttribute:function(_3){ |
||
29 | if(typeof _3!=="string"){ |
||
30 | throw new Error("dojox.data.FlickrStore: a function was passed an attribute argument that was not an attribute name string"); |
||
31 | } |
||
32 | },getFeatures:function(){ |
||
33 | return {"dojo.data.api.Read":true}; |
||
34 | },getValue:function(_4,_5,_6){ |
||
35 | var _7=this.getValues(_4,_5); |
||
36 | if(_7&&_7.length>0){ |
||
37 | return _7[0]; |
||
38 | } |
||
39 | return _6;
|
||
40 | },getAttributes:function(_8){ |
||
41 | return ["title","description","author","datePublished","dateTaken","imageUrl","imageUrlSmall","imageUrlMedium","tags","link"]; |
||
42 | },hasAttribute:function(_9,_a){ |
||
43 | var v=this.getValue(_9,_a); |
||
44 | if(v||v===""||v===false){ |
||
45 | return true; |
||
46 | } |
||
47 | return false; |
||
48 | },isItemLoaded:function(_b){ |
||
49 | return this.isItem(_b); |
||
50 | },loadItem:function(_c){ |
||
51 | },getLabel:function(_d){ |
||
52 | return this.getValue(_d,this.label); |
||
53 | },getLabelAttributes:function(_e){ |
||
54 | return [this.label]; |
||
55 | },containsValue:function(_f,_10,_11){ |
||
56 | var _12=this.getValues(_f,_10); |
||
57 | for(var i=0;i<_12.length;i++){ |
||
58 | if(_12[i]===_11){
|
||
59 | return true; |
||
60 | } |
||
61 | } |
||
62 | return false; |
||
63 | },getValues:function(_13,_14){ |
||
64 | this._assertIsItem(_13);
|
||
65 | this._assertIsAttribute(_14);
|
||
66 | var u=d.hitch(this,"_unescapeHtml"); |
||
67 | var s=d.hitch(d.date.stamp,"fromISOString"); |
||
68 | switch(_14){
|
||
69 | case "title": |
||
70 | return [u(_13.title)];
|
||
71 | case "author": |
||
72 | return [u(_13.author)];
|
||
73 | case "datePublished": |
||
74 | return [s(_13.published)];
|
||
75 | case "dateTaken": |
||
76 | return [s(_13.date_taken)];
|
||
77 | case "imageUrlSmall": |
||
78 | return [_13.media.m.replace(/_m\./,"_s.")]; |
||
79 | case "imageUrl": |
||
80 | return [_13.media.m.replace(/_m\./,".")]; |
||
81 | case "imageUrlMedium": |
||
82 | return [_13.media.m];
|
||
83 | case "link": |
||
84 | return [_13.link];
|
||
85 | case "tags": |
||
86 | return _13.tags.split(" "); |
||
87 | case "description": |
||
88 | return [u(_13.description)];
|
||
89 | default:
|
||
90 | return [];
|
||
91 | } |
||
92 | },isItem:function(_15){ |
||
93 | if(_15&&_15[this._storeRef]===this){ |
||
94 | return true; |
||
95 | } |
||
96 | return false; |
||
97 | },close:function(_16){ |
||
98 | },_fetchItems:function(_17,_18,_19){ |
||
99 | var rq=_17.query=_17.query||{};
|
||
100 | var _1a={format:"json",tagmode:"any"}; |
||
101 | d.forEach(["tags","tagmode","lang","id","ids"],function(i){ |
||
102 | if(rq[i]){
|
||
103 | _1a[i]=rq[i]; |
||
104 | } |
||
105 | }); |
||
106 | _1a.id=rq.id||rq.userid||rq.groupid; |
||
107 | if(rq.userids){
|
||
108 | _1a.ids=rq.userids; |
||
109 | } |
||
110 | var _1b=null; |
||
111 | var _1c={url:dojox.data.FlickrStore.urlRegistry.match(_17),preventCache:this.urlPreventCache,content:_1a}; |
||
112 | var _1d=d.hitch(this,function(_1e){ |
||
113 | if(!!_1b){
|
||
114 | d.disconnect(_1b); |
||
115 | } |
||
116 | _18(this._processFlickrData(_1e),_17);
|
||
117 | }); |
||
118 | _1b=d.connect("jsonFlickrFeed",_1d);
|
||
119 | var _1f=d.io.script.get(_1c);
|
||
120 | _1f.addErrback(function(_20){
|
||
121 | d.disconnect(_1b); |
||
122 | _19(_20,_17); |
||
123 | }); |
||
124 | },_processFlickrData:function(_21){ |
||
125 | var _22=[];
|
||
126 | if(_21.items){
|
||
127 | _22=_21.items; |
||
128 | for(var i=0;i<_21.items.length;i++){ |
||
129 | var _23=_21.items[i];
|
||
130 | _23[this._storeRef]=this; |
||
131 | } |
||
132 | } |
||
133 | return _22;
|
||
134 | },_unescapeHtml:function(str){ |
||
135 | return str.replace(/&/gm,"&").replace(/</gm,"<").replace(/>/gm,">").replace(/"/gm,"\"").replace(/'/gm,"'"); |
||
136 | }}); |
||
137 | dojo.extend(dojox.data.FlickrStore,dojo.data.util.simpleFetch); |
||
138 | var _24="http://api.flickr.com/services/feeds/"; |
||
139 | var reg=dojox.data.FlickrStore.urlRegistry=new d.AdapterRegistry(true); |
||
140 | reg.register("group pool",function(_25){ |
||
141 | return !!_25.query["groupid"]; |
||
142 | },_24+"groups_pool.gne");
|
||
143 | reg.register("default",function(_26){ |
||
144 | return true; |
||
145 | },_24+"photos_public.gne");
|
||
146 | })(); |
||
147 | if(!jsonFlickrFeed){
|
||
148 | var jsonFlickrFeed=function(_27){ |
||
149 | }; |
||
150 | } |
||
151 | } |