author | Michael Krelin <hacker@klever.net> | 2006-09-29 23:02:49 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2006-09-29 23:02:49 (UTC) |
commit | 74a277c2d7ac5416c3b55565e6d5e8e5a15b389d (patch) (unidiff) | |
tree | 755ac7da52079e87a29b68191e66d7e1d7c0a766 /content | |
parent | 3cf3cf1000ce6b27ac622c75fc3d114874e2f3a8 (diff) | |
download | fireflix-74a277c2d7ac5416c3b55565e6d5e8e5a15b389d.zip fireflix-74a277c2d7ac5416c3b55565e6d5e8e5a15b389d.tar.gz fireflix-74a277c2d7ac5416c3b55565e6d5e8e5a15b389d.tar.bz2 |
code beauty: mass-assignment of xul elements to member variables
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@169 fe716a7a-6dde-0310-88d9-d003556173a8
-rw-r--r-- | content/fireflix.js | 36 | ||||
-rw-r--r-- | content/util.js | 9 |
2 files changed, 23 insertions, 22 deletions
diff --git a/content/fireflix.js b/content/fireflix.js index daf4929..98b6d41 100644 --- a/content/fireflix.js +++ b/content/fireflix.js | |||
@@ -1,898 +1,890 @@ | |||
1 | function splitascii(s) { | 1 | function splitascii(s) { |
2 | var rv=''; | 2 | var rv=''; |
3 | for(var i=0;i<s.length;++i) { | 3 | for(var i=0;i<s.length;++i) { |
4 | var w = s.charCodeAt(i); | 4 | var w = s.charCodeAt(i); |
5 | rv += String.fromCharCode( | 5 | rv += String.fromCharCode( |
6 | w&0xff, (w>>8)&0xff ); | 6 | w&0xff, (w>>8)&0xff ); |
7 | } | 7 | } |
8 | return rv; | 8 | return rv; |
9 | } | 9 | } |
10 | 10 | ||
11 | 11 | ||
12 | var fireflix = { | 12 | var fireflix = { |
13 | flickr: new Flickr(), | 13 | flickr: new Flickr(), |
14 | init: function() { | 14 | init: function() { |
15 | this.cmd_auth_auth = document.getElementById('cmd_auth_auth'); | 15 | pull_elements(this,document,[ |
16 | this.cmd_auth_done = document.getElementById('cmd_auth_done'); | 16 | 'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth', |
17 | this.cmd_auth_unauth = document.getElementById('cmd_auth_unauth'); | 17 | 'menu_auth_done','b_auth','b_auth_done','auth_info', |
18 | this.menu_auth_done = document.getElementById('menu_auth_done'); | 18 | 'loc_strings','cmd_set_props' |
19 | this.b_auth = document.getElementById('b_auth'); | 19 | ]); |
20 | this.b_auth_done = document.getElementById('b_auth_done'); | ||
21 | this.auth_info = document.getElementById('auth_info'); | ||
22 | this.loc_strings = document.getElementById('loc_strings'); | ||
23 | this.build_menus(); | 20 | this.build_menus(); |
24 | this.cmd_set_props = document.getElementById('cmd_set_props'); | ||
25 | this.foundphotos.init(this); | 21 | this.foundphotos.init(this); |
26 | this.photosets.init(this); | 22 | this.photosets.init(this); |
27 | this.photoset.init(this); | 23 | this.photoset.init(this); |
28 | this.uploads.init(this); | 24 | this.uploads.init(this); |
29 | this.uploadObserver.init(this); | 25 | this.uploadObserver.init(this); |
30 | this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; | 26 | this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; |
31 | this.flickr.api_shs = '9c33c9e2f0f0cfd5'; | 27 | this.flickr.api_shs = '9c33c9e2f0f0cfd5'; |
32 | this.flickr.prefs_root = 'net.klever.kin.fireflix'; | 28 | this.flickr.prefs_root = 'net.klever.kin.fireflix'; |
33 | this.flickr.load_token(); | 29 | this.flickr.load_token(); |
34 | document.getElementById('setslist').view = this.photosets; | 30 | document.getElementById('setslist').view = this.photosets; |
35 | document.getElementById('setphotos').view = this.photoset; | 31 | document.getElementById('setphotos').view = this.photoset; |
36 | document.getElementById('uploadlist').view = this.uploads; | 32 | document.getElementById('uploadlist').view = this.uploads; |
37 | this.no_auth_info_label = this.auth_info.value; | 33 | this.no_auth_info_label = this.auth_info.value; |
38 | this.set_auth_state(this.flickr.token,false); | 34 | this.set_auth_state(this.flickr.token,false); |
39 | if(this.flickr.token) { | 35 | if(this.flickr.token) { |
40 | this.refresh_stuff(); | 36 | this.refresh_stuff(); |
41 | }else{ | 37 | }else{ |
42 | this.on_cmd_auth(); | 38 | this.on_cmd_auth(); |
43 | } | 39 | } |
44 | }, | 40 | }, |
45 | set_auth_state: function(au,inp) { /* authorized, in progress */ | 41 | set_auth_state: function(au,inp) { /* authorized, in progress */ |
46 | this.cmd_auth_unauth.disabled = !au; | 42 | this.cmd_auth_unauth.disabled = !au; |
47 | this.b_auth.hidden = au || inp; | 43 | this.b_auth.hidden = au || inp; |
48 | this.b_auth_done.hidden = !inp; | 44 | this.b_auth_done.hidden = !inp; |
49 | this.menu_auth_done.hidden = !inp; | 45 | this.menu_auth_done.hidden = !inp; |
50 | this.cmd_auth_done.setAttribute('disabled',!inp); | 46 | this.cmd_auth_done.setAttribute('disabled',!inp); |
51 | this.auth_info.disabled = !au; | 47 | this.auth_info.disabled = !au; |
52 | if(au) { | 48 | if(au) { |
53 | this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ | 49 | this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ |
54 | }else{ | 50 | }else{ |
55 | this.auth_info.value = this.no_auth_info_label; | 51 | this.auth_info.value = this.no_auth_info_label; |
56 | } | 52 | } |
57 | }, | 53 | }, |
58 | on_cmd_auth: function() { | 54 | on_cmd_auth: function() { |
59 | var _this = this; | 55 | var _this = this; |
60 | this.flickr.authorize_0( | 56 | this.flickr.authorize_0( |
61 | function() { | 57 | function() { |
62 | _this.set_auth_state(_this.flickr.token,true); | 58 | _this.set_auth_state(_this.flickr.token,true); |
63 | }, function(x,s,c,m) { | 59 | }, function(x,s,c,m) { |
64 | _this.flickr_failure(x,s,c,m); | 60 | _this.flickr_failure(x,s,c,m); |
65 | } | 61 | } |
66 | ); | 62 | ); |
67 | }, | 63 | }, |
68 | on_cmd_auth_done: function() { | 64 | on_cmd_auth_done: function() { |
69 | this.set_auth_state(this.flickr.token,false); | 65 | this.set_auth_state(this.flickr.token,false); |
70 | var _this = this; | 66 | var _this = this; |
71 | this.flickr.authorize_1( | 67 | this.flickr.authorize_1( |
72 | function() { | 68 | function() { |
73 | _this.flickr.save_token(); | 69 | _this.flickr.save_token(); |
74 | _this.refresh_stuff(); | 70 | _this.refresh_stuff(); |
75 | _this.set_auth_state(_this.flickr.token,false); | 71 | _this.set_auth_state(_this.flickr.token,false); |
76 | _this.auth_info.value = | 72 | _this.auth_info.value = |
77 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; | 73 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; |
78 | }, function(x,s,c,m) { | 74 | }, function(x,s,c,m) { |
79 | _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ | 75 | _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ |
80 | _this.flickr_failure(x,s,c,m); | 76 | _this.flickr_failure(x,s,c,m); |
81 | } | 77 | } |
82 | ); | 78 | ); |
83 | }, | 79 | }, |
84 | on_cmd_auth_unauth: function() { | 80 | on_cmd_auth_unauth: function() { |
85 | this.flickr.reset_token(); | 81 | this.flickr.reset_token(); |
86 | this.set_auth_state(false,false); | 82 | this.set_auth_state(false,false); |
87 | }, | 83 | }, |
88 | 84 | ||
89 | refresh_sets: function() { this.photosets.refresh_sets(); }, | 85 | refresh_sets: function() { this.photosets.refresh_sets(); }, |
90 | refresh_stuff: function() { | 86 | refresh_stuff: function() { |
91 | this.refresh_sets(); | 87 | this.refresh_sets(); |
92 | this.refresh_user_tags(); | 88 | this.refresh_user_tags(); |
93 | }, | 89 | }, |
94 | 90 | ||
95 | /* photoset treeview */ | 91 | /* photoset treeview */ |
96 | photoset: { | 92 | photoset: { |
97 | photos: new Array(), | 93 | photos: new Array(), |
98 | fireflix: null, | 94 | fireflix: null, |
99 | init: function(f) { | 95 | init: function(f) { |
100 | this.fireflix = f; | 96 | this.fireflix = f; |
101 | }, | 97 | }, |
102 | rowCount: 0, | 98 | rowCount: 0, |
103 | getCellText: function(r,c) { | 99 | getCellText: function(r,c) { |
104 | var p = this.photos[r]; | 100 | var p = this.photos[r]; |
105 | if(c.id=='sp_title') return p.title; | 101 | if(c.id=='sp_title') return p.title; |
106 | if(c.id=='sp_taken') return p.datetaken; | 102 | if(c.id=='sp_taken') return p.datetaken; |
107 | if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ | 103 | if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ |
108 | return c.id; | 104 | return c.id; |
109 | }, | 105 | }, |
110 | setTree: function(t) { this.tree = t }, | 106 | setTree: function(t) { this.tree = t }, |
111 | isContainer: function(r) { return false; }, | 107 | isContainer: function(r) { return false; }, |
112 | isSeparator: function(r) { return false; }, | 108 | isSeparator: function(r) { return false; }, |
113 | isSorted: function(r) { return false; }, | 109 | isSorted: function(r) { return false; }, |
114 | getLevel: function(r) { return 0; }, | 110 | getLevel: function(r) { return 0; }, |
115 | getImageSrc: function(r,c) { return null }, | 111 | getImageSrc: function(r,c) { return null }, |
116 | getRowProperties: function(r,p) {}, | 112 | getRowProperties: function(r,p) {}, |
117 | getCellProperties: function(cid,cel,p) {}, | 113 | getCellProperties: function(cid,cel,p) {}, |
118 | getColumnProperties: function(cid,cel,p) { }, | 114 | getColumnProperties: function(cid,cel,p) { }, |
119 | cycleHeader: function(cid,e) { }, | 115 | cycleHeader: function(cid,e) { }, |
120 | getParentIndex: function(r) { return -1; }, | 116 | getParentIndex: function(r) { return -1; }, |
121 | drop: function(r,o) { }, | 117 | drop: function(r,o) { }, |
122 | canDropBeforeAfter: function(r,b) { return false }, | 118 | canDropBeforeAfter: function(r,b) { return false }, |
123 | 119 | ||
124 | importXPR: function(xp) { | 120 | importXPR: function(xp) { |
125 | this.tree.beginUpdateBatch(); | 121 | this.tree.beginUpdateBatch(); |
126 | this.photos = new Array(); | 122 | this.photos = new Array(); |
127 | var n; while(n=xp.iterateNext()) { | 123 | var n; while(n=xp.iterateNext()) { |
128 | this.photos.push(new Photo(n)); | 124 | this.photos.push(new Photo(n)); |
129 | } | 125 | } |
130 | this.rowCount = this.photos.length; | 126 | this.rowCount = this.photos.length; |
131 | this.tree.endUpdateBatch(); | 127 | this.tree.endUpdateBatch(); |
132 | }, | 128 | }, |
133 | load_photos: function(psid) { | 129 | load_photos: function(psid) { |
134 | var _this = this; | 130 | var _this = this; |
135 | this.fireflix.flickr.api_call( | 131 | this.fireflix.flickr.api_call( |
136 | { | 132 | { |
137 | method: 'flickr.photosets.getPhotos', | 133 | method: 'flickr.photosets.getPhotos', |
138 | auth_token: 'default', | 134 | auth_token: 'default', |
139 | photoset_id: psid, | 135 | photoset_id: psid, |
140 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' | 136 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' |
141 | }, function(xr) { | 137 | }, function(xr) { |
142 | var x = xr.responseXML; | 138 | var x = xr.responseXML; |
143 | var xp = x.evaluate( | 139 | var xp = x.evaluate( |
144 | '/rsp/photoset/photo', x, null, | 140 | '/rsp/photoset/photo', x, null, |
145 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 141 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
146 | _this.importXPR(xp); | 142 | _this.importXPR(xp); |
147 | }, function(x,s,c,m) { | 143 | }, function(x,s,c,m) { |
148 | _this.fireflix.flickr_failure(x,s,c,m); | 144 | _this.fireflix.flickr_failure(x,s,c,m); |
149 | } | 145 | } |
150 | ); | 146 | ); |
151 | }, | 147 | }, |
152 | on_select: function() { | 148 | on_select: function() { |
153 | if(this.selection.count==1) { | 149 | if(this.selection.count==1) { |
154 | var p = this.photos[this.selection.currentIndex]; | 150 | var p = this.photos[this.selection.currentIndex]; |
155 | document.getElementById('set_photo').src = | 151 | document.getElementById('set_photo').src = |
156 | this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); | 152 | this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); |
157 | document.getElementById('set_photo').hidden = false; | 153 | document.getElementById('set_photo').hidden = false; |
158 | }else{ | 154 | }else{ |
159 | document.getElementById('set_photo').hidden = true; | 155 | document.getElementById('set_photo').hidden = true; |
160 | } | 156 | } |
161 | } | 157 | } |
162 | }, | 158 | }, |
163 | 159 | ||
164 | /* photosets treeview */ | 160 | /* photosets treeview */ |
165 | photosets: { | 161 | photosets: { |
166 | sets: new Array(), | 162 | sets: new Array(), |
167 | fireflix: null, | 163 | fireflix: null, |
168 | init: function(f) { | 164 | init: function(f) { |
169 | this.fireflix = f; | 165 | this.fireflix = f; |
170 | }, | 166 | }, |
171 | rowCount: 0, | 167 | rowCount: 0, |
172 | getCellText: function(r,c) { | 168 | getCellText: function(r,c) { |
173 | var s = this.sets[r]; | 169 | var s = this.sets[r]; |
174 | if(c.id=='sl_name') return s.title; | 170 | if(c.id=='sl_name') return s.title; |
175 | if(c.id=='sl_photos') return s.photos; | 171 | if(c.id=='sl_photos') return s.photos; |
176 | return c.id; | 172 | return c.id; |
177 | }, | 173 | }, |
178 | setTree: function(t) { this.tree = t }, | 174 | setTree: function(t) { this.tree = t }, |
179 | isContainer: function(r) { return false; }, | 175 | isContainer: function(r) { return false; }, |
180 | isSeparator: function(r) { return false; }, | 176 | isSeparator: function(r) { return false; }, |
181 | isSorted: function() { return false; }, | 177 | isSorted: function() { return false; }, |
182 | getLevel: function(r) { return 0; }, | 178 | getLevel: function(r) { return 0; }, |
183 | getImageSrc: function(r,c) { return null }, | 179 | getImageSrc: function(r,c) { return null }, |
184 | getRowProperties: function(r,p) {}, | 180 | getRowProperties: function(r,p) {}, |
185 | getCellProperties: function(cid,cel,p) { }, | 181 | getCellProperties: function(cid,cel,p) { }, |
186 | getColumnProperties: function(cid,cel,p) { }, | 182 | getColumnProperties: function(cid,cel,p) { }, |
187 | cycleHeader: function(cid,e) { }, | 183 | cycleHeader: function(cid,e) { }, |
188 | getParentIndex: function(r) { return -1; }, | 184 | getParentIndex: function(r) { return -1; }, |
189 | drop: function(r,o) { }, | 185 | drop: function(r,o) { }, |
190 | canDropBeforeAfter: function(r,b) { return false }, | 186 | canDropBeforeAfter: function(r,b) { return false }, |
191 | 187 | ||
192 | importXPR: function(xp) { | 188 | importXPR: function(xp) { |
193 | this.tree.beginUpdateBatch(); | 189 | this.tree.beginUpdateBatch(); |
194 | this.sets = new Array(); | 190 | this.sets = new Array(); |
195 | var n; while(n=xp.iterateNext()) { | 191 | var n; while(n=xp.iterateNext()) { |
196 | this.sets.push(new Photoset(n)); | 192 | this.sets.push(new Photoset(n)); |
197 | } | 193 | } |
198 | this.rowCount = this.sets.length; | 194 | this.rowCount = this.sets.length; |
199 | this.tree.endUpdateBatch(); | 195 | this.tree.endUpdateBatch(); |
200 | }, | 196 | }, |
201 | refresh_sets: function() { | 197 | refresh_sets: function() { |
202 | var _this = this; | 198 | var _this = this; |
203 | this.fireflix.flickr.api_call( | 199 | this.fireflix.flickr.api_call( |
204 | { | 200 | { |
205 | method: 'flickr.photosets.getList', | 201 | method: 'flickr.photosets.getList', |
206 | auth_token: 'default' | 202 | auth_token: 'default' |
207 | }, function(xr) { | 203 | }, function(xr) { |
208 | var x = xr.responseXML; | 204 | var x = xr.responseXML; |
209 | var xp = x.evaluate( | 205 | var xp = x.evaluate( |
210 | '/rsp/photosets/photoset', x, null, | 206 | '/rsp/photosets/photoset', x, null, |
211 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 207 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
212 | _this.importXPR(xp); | 208 | _this.importXPR(xp); |
213 | }, function(x,s,c,m) { | 209 | }, function(x,s,c,m) { |
214 | _this.fireflix.flickr_failure(x,s,c,m); | 210 | _this.fireflix.flickr_failure(x,s,c,m); |
215 | } | 211 | } |
216 | ); | 212 | ); |
217 | }, | 213 | }, |
218 | on_select: function() { | 214 | on_select: function() { |
219 | if(this.selection.count==1) { | 215 | if(this.selection.count==1) { |
220 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); | 216 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); |
221 | var s = this.sets[this.selection.currentIndex]; | 217 | var s = this.sets[this.selection.currentIndex]; |
222 | this.fireflix.photoset.load_photos(s.id); | 218 | this.fireflix.photoset.load_photos(s.id); |
223 | }else{ | 219 | }else{ |
224 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); | 220 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); |
225 | } | 221 | } |
226 | } | 222 | } |
227 | }, | 223 | }, |
228 | 224 | ||
229 | refresh_user_tags: function() { | 225 | refresh_user_tags: function() { |
230 | var lb = document.getElementById('tagslist'); | 226 | var lb = document.getElementById('tagslist'); |
231 | var _this = this; | 227 | var _this = this; |
232 | this.flickr.api_call( | 228 | this.flickr.api_call( |
233 | { | 229 | { |
234 | method: 'flickr.tags.getListUser', | 230 | method: 'flickr.tags.getListUser', |
235 | auth_token: 'default', | 231 | auth_token: 'default', |
236 | }, function(xr) { | 232 | }, function(xr) { |
237 | var x = xr.responseXML; | 233 | var x = xr.responseXML; |
238 | var xp = x.evaluate( | 234 | var xp = x.evaluate( |
239 | '/rsp/who/tags/tag', x, null, | 235 | '/rsp/who/tags/tag', x, null, |
240 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 236 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
241 | // TODO: clear list | 237 | // TODO: clear list |
242 | var n; while(n=xp.iterateNext()) { | 238 | var n; while(n=xp.iterateNext()) { |
243 | lb.appendItem(n.firstChild.nodeValue); | 239 | lb.appendItem(n.firstChild.nodeValue); |
244 | } | 240 | } |
245 | }, function(x,s,c,m) { | 241 | }, function(x,s,c,m) { |
246 | _this.flickr_failure(x,s,c,m); | 242 | _this.flickr_failure(x,s,c,m); |
247 | } | 243 | } |
248 | ); | 244 | ); |
249 | }, | 245 | }, |
250 | 246 | ||
251 | uploadObserver: { | 247 | uploadObserver: { |
252 | fireflix: null, | 248 | fireflix: null, |
253 | init: function(f) { | 249 | init: function(f) { |
254 | this.fireflix = f; | 250 | this.fireflix = f; |
255 | }, | 251 | }, |
256 | getSupportedFlavours: function() { | 252 | getSupportedFlavours: function() { |
257 | var rv = new FlavourSet(); | 253 | var rv = new FlavourSet(); |
258 | rv.appendFlavour('application/x-moz-file','nsIFile'); | 254 | rv.appendFlavour('application/x-moz-file','nsIFile'); |
259 | rv.appendFlavour('application/x-moz-url'); | 255 | rv.appendFlavour('application/x-moz-url'); |
260 | rv.appendFlavour('text/uri-list'); | 256 | rv.appendFlavour('text/uri-list'); |
261 | rv.appendFlavour('text/unicode'); | 257 | rv.appendFlavour('text/unicode'); |
262 | return rv; | 258 | return rv; |
263 | }, | 259 | }, |
264 | canHandleMultipleItems: true, | 260 | canHandleMultipleItems: true, |
265 | onDragOver: function(ev,fl,sess) { | 261 | onDragOver: function(ev,fl,sess) { |
266 | return true; | 262 | return true; |
267 | }, | 263 | }, |
268 | onDrop: function(ev,dd,s) { | 264 | onDrop: function(ev,dd,s) { |
269 | var ldf = null; | 265 | var ldf = null; |
270 | for(var i in dd.dataList) { | 266 | for(var i in dd.dataList) { |
271 | var di = dd.dataList[i]; | 267 | var di = dd.dataList[i]; |
272 | var dif = di.first; | 268 | var dif = di.first; |
273 | if( | 269 | if( |
274 | ldf==null | 270 | ldf==null |
275 | || ldf.flavour.contentType!=dif.flavour.contentType | 271 | || ldf.flavour.contentType!=dif.flavour.contentType |
276 | || ldf.contentLength!=dif.contentLength | 272 | || ldf.contentLength!=dif.contentLength |
277 | || ldf.data!=dif.data ) | 273 | || ldf.data!=dif.data ) |
278 | this.drop_item(ev,di,s); | 274 | this.drop_item(ev,di,s); |
279 | ldf = dif; | 275 | ldf = dif; |
280 | } | 276 | } |
281 | }, | 277 | }, |
282 | drop_item: function(ev,di,s) { | 278 | drop_item: function(ev,di,s) { |
283 | var d = di.first; | 279 | var d = di.first; |
284 | switch(d.flavour.contentType) { | 280 | switch(d.flavour.contentType) { |
285 | case 'text/unicode': | 281 | case 'text/unicode': |
286 | this.drop_urilist(ev,d.data,s); | 282 | this.drop_urilist(ev,d.data,s); |
287 | break; | 283 | break; |
288 | case 'application/x-moz-file': | 284 | case 'application/x-moz-file': |
289 | this.fireflix.uploads.add(d.data.path); | 285 | this.fireflix.uploads.add(d.data.path); |
290 | document.getElementById('fireflix_tabs').selectedTab | 286 | document.getElementById('fireflix_tabs').selectedTab |
291 | = document.getElementById('tab_upload'); | 287 | = document.getElementById('tab_upload'); |
292 | break; | 288 | break; |
293 | case 'text/uri-list': | 289 | case 'text/uri-list': |
294 | // is it ascii or could it be utf8? | 290 | // is it ascii or could it be utf8? |
295 | this.drop_urilist(ev,splitascii(d.data),s); | 291 | this.drop_urilist(ev,splitascii(d.data),s); |
296 | break; | 292 | break; |
297 | default: alert(d.flavour.contentType+':'+d.data); break; | 293 | default: alert(d.flavour.contentType+':'+d.data); break; |
298 | }; | 294 | }; |
299 | }, | 295 | }, |
300 | drop_urilist: function(ev,ul,s) { | 296 | drop_urilist: function(ev,ul,s) { |
301 | // TODO: check for being a file? | 297 | // TODO: check for being a file? |
302 | var us = decodeURIComponent(ul).split(/[\r\n]/); | 298 | var us = decodeURIComponent(ul).split(/[\r\n]/); |
303 | for(var ui in us) | 299 | for(var ui in us) |
304 | if(/\S/.test(us[ui])) | 300 | if(/\S/.test(us[ui])) |
305 | this.fireflix.uploads.add(us[ui]); | 301 | this.fireflix.uploads.add(us[ui]); |
306 | document.getElementById('fireflix_tabs').selectedTab | 302 | document.getElementById('fireflix_tabs').selectedTab |
307 | = document.getElementById('tab_upload'); | 303 | = document.getElementById('tab_upload'); |
308 | } | 304 | } |
309 | }, | 305 | }, |
310 | 306 | ||
311 | uploads: { | 307 | uploads: { |
312 | fireflix: null, | 308 | fireflix: null, |
313 | init: function(f) { | 309 | init: function(f) { |
314 | this.fireflix=f; | 310 | this.fireflix=f; |
315 | this.upload_filename = document.getElementById('upload_filename'); | 311 | pull_elements(this,document,[ |
316 | this.upload_title = document.getElementById('upload_title'); | 312 | 'upload_filename','upload_title','upload_file_preview', |
317 | this.upload_file_preview = document.getElementById('upload_file_preview'); | 313 | 'upload_file_props','upload_progress','upload_tags' |
318 | this.upload_file_props = document.getElementById('upload_file_props'); | 314 | ]); |
319 | this.upload_progress = document.getElementById('upload_progress'); | ||
320 | this.upload_tags = document.getElementById('upload_tags'); | ||
321 | }, | 315 | }, |
322 | files: new Array(), | 316 | files: new Array(), |
323 | rowCount: 0, | 317 | rowCount: 0, |
324 | getCellText: function(r,c) { | 318 | getCellText: function(r,c) { |
325 | var f = this.files[r]; | 319 | var f = this.files[r]; |
326 | if(c.id=='up_file') return f.file; | 320 | if(c.id=='up_file') return f.file; |
327 | if(c.id=='up_title') return f.title; | 321 | if(c.id=='up_title') return f.title; |
328 | if(c.id=='up_status') return f.state; | 322 | if(c.id=='up_status') return f.state; |
329 | return c.id; | 323 | return c.id; |
330 | }, | 324 | }, |
331 | setTree: function(t) { this.tree = t }, | 325 | setTree: function(t) { this.tree = t }, |
332 | isContainer: function(r) { return false; }, | 326 | isContainer: function(r) { return false; }, |
333 | isSeparator: function(r) { return false; }, | 327 | isSeparator: function(r) { return false; }, |
334 | isSorted: function(r) { return false; }, | 328 | isSorted: function(r) { return false; }, |
335 | getLevel: function(r) { return 0; }, | 329 | getLevel: function(r) { return 0; }, |
336 | getImageSrc: function(r,c) { return null }, | 330 | getImageSrc: function(r,c) { return null }, |
337 | getRowProperties: function(r,p) { | 331 | getRowProperties: function(r,p) { |
338 | try { | 332 | try { |
339 | if(!Components) return; | 333 | if(!Components) return; |
340 | }catch(e) { return } | 334 | }catch(e) { return } |
341 | var f = this.files[r]; | 335 | var f = this.files[r]; |
342 | var as = Components.classes['@mozilla.org/atom-service;1']. | 336 | var as = Components.classes['@mozilla.org/atom-service;1']. |
343 | getService(Components.interfaces.nsIAtomService); | 337 | getService(Components.interfaces.nsIAtomService); |
344 | p.AppendElement(as.getAtom(f.state)); | 338 | p.AppendElement(as.getAtom(f.state)); |
345 | }, | 339 | }, |
346 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, | 340 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, |
347 | getColumnProperties: function(c,p) { }, | 341 | getColumnProperties: function(c,p) { }, |
348 | cycleHeader: function(cid,e) { }, | 342 | cycleHeader: function(cid,e) { }, |
349 | getParentIndex: function(r) { return -1; }, | 343 | getParentIndex: function(r) { return -1; }, |
350 | drop: function(r,o) { }, | 344 | drop: function(r,o) { }, |
351 | canDropBeforeAfter: function(r,b) { return false }, | 345 | canDropBeforeAfter: function(r,b) { return false }, |
352 | 346 | ||
353 | add: function(f) { | 347 | add: function(f) { |
354 | if(f.indexOf('file:/')==0) { | 348 | if(f.indexOf('file:/')==0) { |
355 | f = f.substr(5); | 349 | f = f.substr(5); |
356 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) | 350 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) |
357 | f = f.substr(1); | 351 | f = f.substr(1); |
358 | } | 352 | } |
359 | } | 353 | } |
360 | var t = f; | 354 | var t = f; |
361 | var ls = t.lastIndexOf('/'); | 355 | var ls = t.lastIndexOf('/'); |
362 | if(ls>0) t = t.substr(ls+1); | 356 | if(ls>0) t = t.substr(ls+1); |
363 | ls = t.lastIndexOf('\\'); | 357 | ls = t.lastIndexOf('\\'); |
364 | if(ls>0) t = t.substr(ls+1); | 358 | if(ls>0) t = t.substr(ls+1); |
365 | var ld = t.lastIndexOf('.'); | 359 | var ld = t.lastIndexOf('.'); |
366 | if(ld>0) t = t.substr(0,ld); | 360 | if(ld>0) t = t.substr(0,ld); |
367 | this.files.push( { | 361 | this.files.push( { |
368 | file: f, | 362 | file: f, |
369 | title: t, | 363 | title: t, |
370 | tags: '', | 364 | tags: '', |
371 | state: 'pending' | 365 | state: 'pending' |
372 | } ); | 366 | } ); |
373 | this.rowCount = this.files.length; | 367 | this.rowCount = this.files.length; |
374 | this.tree.rowCountChanged(this.rowCount-1,1); | 368 | this.tree.rowCountChanged(this.rowCount-1,1); |
375 | }, | 369 | }, |
376 | 370 | ||
377 | upload_worker: function() { | 371 | upload_worker: function() { |
378 | for(var f in this.files) { | 372 | for(var f in this.files) { |
379 | if(this.files[f].state=='pending') { | 373 | if(this.files[f].state=='pending') { |
380 | var ff = this.files[f]; | 374 | var ff = this.files[f]; |
381 | dump('upload '+ff.file+'\n'); | 375 | dump('upload '+ff.file+'\n'); |
382 | this.on_file_upload(ff); | 376 | this.on_file_upload(ff); |
383 | ff.state='uploading'; | 377 | ff.state='uploading'; |
384 | this.tree.invalidate(); | 378 | this.tree.invalidate(); |
385 | var _this = this; | 379 | var _this = this; |
386 | this.fireflix.flickr.upload_file( | 380 | this.fireflix.flickr.upload_file( |
387 | ff.file, { title: ff.title, tags: ff.tags }, | 381 | ff.file, { title: ff.title, tags: ff.tags }, |
388 | function(x,p) { | 382 | function(x,p) { |
389 | ff.photoid = p; | 383 | ff.photoid = p; |
390 | _this.batch_ids.push(p); | 384 | _this.batch_ids.push(p); |
391 | ff.state='completed'; | 385 | ff.state='completed'; |
392 | _this.tree.invalidate(); | 386 | _this.tree.invalidate(); |
393 | window.setTimeout(_this.upload_to,0,_this); | 387 | window.setTimeout(_this.upload_to,0,_this); |
394 | }, function(x,s,c,m) { | 388 | }, function(x,s,c,m) { |
395 | ff.state='failed'; | 389 | ff.state='failed'; |
396 | ff.flickr_errcode = c; | 390 | ff.flickr_errcode = c; |
397 | ff.flickr_errmsg = m; | 391 | ff.flickr_errmsg = m; |
398 | _this.tree.invalidate(); | 392 | _this.tree.invalidate(); |
399 | window.setTimeout(_this.upload_to,0,_this); | 393 | window.setTimeout(_this.upload_to,0,_this); |
400 | } | 394 | } |
401 | ); | 395 | ); |
402 | return; | 396 | return; |
403 | } | 397 | } |
404 | } | 398 | } |
405 | dump('uploading done\n'); | 399 | dump('uploading done\n'); |
406 | this.on_finish_upload(); | 400 | this.on_finish_upload(); |
407 | }, | 401 | }, |
408 | upload_to: function(_this) { _this.upload_worker(); }, | 402 | upload_to: function(_this) { _this.upload_worker(); }, |
409 | on_file_upload: function(f) { | 403 | on_file_upload: function(f) { |
410 | document.getElementById('cmd_uploads_upload').setAttribute('disabled','true'); | 404 | document.getElementById('cmd_uploads_upload').setAttribute('disabled','true'); |
411 | for(var fi in this.files) { | 405 | for(var fi in this.files) { |
412 | if(this.files[fi].file==f.file) { | 406 | if(this.files[fi].file==f.file) { |
413 | this.tree.ensureRowIsVisible(fi); | 407 | this.tree.ensureRowIsVisible(fi); |
414 | this.selection.rangedSelect(fi,fi,false); | 408 | this.selection.rangedSelect(fi,fi,false); |
415 | this.selection.currentIndex = fi; | 409 | this.selection.currentIndex = fi; |
416 | this.selToProps(); | 410 | this.selToProps(); |
417 | break; | 411 | break; |
418 | } | 412 | } |
419 | } | 413 | } |
420 | }, | 414 | }, |
421 | on_finish_upload: function() { | 415 | on_finish_upload: function() { |
422 | if(this.batch_ids.length) { | 416 | if(this.batch_ids.length) { |
423 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); | 417 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); |
424 | if(psn!=null) { | 418 | if(psn!=null) { |
425 | var pids = this.batch_ids.join(','); | 419 | var pids = this.batch_ids.join(','); |
426 | var ppid = this.batch_ids[0]; | 420 | var ppid = this.batch_ids[0]; |
427 | var _this = this; | 421 | var _this = this; |
428 | this.fireflix.flickr.api_call( | 422 | this.fireflix.flickr.api_call( |
429 | { | 423 | { |
430 | method: 'flickr.photosets.create', | 424 | method: 'flickr.photosets.create', |
431 | auth_token: 'default', | 425 | auth_token: 'default', |
432 | title: psn, | 426 | title: psn, |
433 | primary_photo_id: ppid | 427 | primary_photo_id: ppid |
434 | }, function(x) { | 428 | }, function(x) { |
435 | var npid = | 429 | var npid = |
436 | x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); | 430 | x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); |
437 | _this.fireflix.flickr.api_call( | 431 | _this.fireflix.flickr.api_call( |
438 | { | 432 | { |
439 | method: 'flickr.photosets.editPhotos', | 433 | method: 'flickr.photosets.editPhotos', |
440 | auth_token: 'default', | 434 | auth_token: 'default', |
441 | photoset_id: npid, | 435 | photoset_id: npid, |
442 | primary_photo_id: ppid, | 436 | primary_photo_id: ppid, |
443 | photo_ids: pids | 437 | photo_ids: pids |
444 | }, function(x) { | 438 | }, function(x) { |
445 | _this.fireflix.refresh_sets(); | 439 | _this.fireflix.refresh_sets(); |
446 | }, function(x,s,c,m) { | 440 | }, function(x,s,c,m) { |
447 | _this.fireflix.flickr_failure(x,s,c,m); | 441 | _this.fireflix.flickr_failure(x,s,c,m); |
448 | } | 442 | } |
449 | ); | 443 | ); |
450 | }, function(x,s,c,m) { | 444 | }, function(x,s,c,m) { |
451 | _this.fireflix.flickr_failure(x,s,c,m); | 445 | _this.fireflix.flickr_failure(x,s,c,m); |
452 | } | 446 | } |
453 | ); | 447 | ); |
454 | } | 448 | } |
455 | } | 449 | } |
456 | this.selection.clearSelection(); | 450 | this.selection.clearSelection(); |
457 | document.getElementById('cmd_uploads_upload').setAttribute('disabled','false'); | 451 | document.getElementById('cmd_uploads_upload').setAttribute('disabled','false'); |
458 | this.upload_progress.setAttribute('hidden','true'); | 452 | this.upload_progress.setAttribute('hidden','true'); |
459 | }, | 453 | }, |
460 | 454 | ||
461 | clear_list: function() { | 455 | clear_list: function() { |
462 | this.tree.beginUpdateBatch(); | 456 | this.tree.beginUpdateBatch(); |
463 | this.rowCount = 0; | 457 | this.rowCount = 0; |
464 | this.files = new Array(); | 458 | this.files = new Array(); |
465 | this.tree.endUpdateBatch(); | 459 | this.tree.endUpdateBatch(); |
466 | this.selToProps(); | 460 | this.selToProps(); |
467 | }, | 461 | }, |
468 | selectionChanged: function() { | 462 | selectionChanged: function() { |
469 | this.selToProps(); | 463 | this.selToProps(); |
470 | }, | 464 | }, |
471 | disableProps: function() { | 465 | disableProps: function() { |
472 | this.upload_filename.value=''; | 466 | this.upload_filename.value=''; |
473 | this.upload_filename.disabled = true; | 467 | this.upload_filename.disabled = true; |
474 | this.upload_title.value=''; | 468 | this.upload_title.value=''; |
475 | this.upload_title.disabled = true; | 469 | this.upload_title.disabled = true; |
476 | this.upload_file_preview.src = null; | 470 | this.upload_file_preview.src = null; |
477 | this.upload_file_props.hidden = true; | 471 | this.upload_file_props.hidden = true; |
478 | this.upload_tags.value=''; | 472 | this.upload_tags.value=''; |
479 | this.upload_tags.disabled = true; | 473 | this.upload_tags.disabled = true; |
480 | }, | 474 | }, |
481 | selToProps: function() { | 475 | selToProps: function() { |
482 | if(!this.selection.count) { | 476 | if(!this.selection.count) { |
483 | this.disableProps(); | 477 | this.disableProps(); |
484 | }else if(this.selection.count==1) { | 478 | }else if(this.selection.count==1) { |
485 | var f=this.files[this.selection.currentIndex]; | 479 | var f=this.files[this.selection.currentIndex]; |
486 | if(f==null || f.state!='pending') { | 480 | if(f==null || f.state!='pending') { |
487 | this.disableProps(); | 481 | this.disableProps(); |
488 | }else{ | 482 | }else{ |
489 | this.upload_filename.value = f.file; | 483 | this.upload_filename.value = f.file; |
490 | this.upload_filename.disabled = false; | 484 | this.upload_filename.disabled = false; |
491 | this.upload_title.value = f.title; | 485 | this.upload_title.value = f.title; |
492 | this.upload_title.disabled = false; | 486 | this.upload_title.disabled = false; |
493 | this.upload_file_preview.src = 'file:///'+f.file; | 487 | this.upload_file_preview.src = 'file:///'+f.file; |
494 | this.upload_file_props.hidden = false; | 488 | this.upload_file_props.hidden = false; |
495 | this.upload_tags.value = f.tags; | 489 | this.upload_tags.value = f.tags; |
496 | this.upload_tags.disabled = false; | 490 | this.upload_tags.disabled = false; |
497 | } | 491 | } |
498 | }else{ | 492 | }else{ |
499 | var ftitle = null; var onetitle = true; | 493 | var ftitle = null; var onetitle = true; |
500 | var ftags = null; var onetag = true; | 494 | var ftags = null; var onetag = true; |
501 | var fs = 0; | 495 | var fs = 0; |
502 | for(var ff in this.files) { | 496 | for(var ff in this.files) { |
503 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { | 497 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { |
504 | ++fs; | 498 | ++fs; |
505 | if(ftitle==null) { | 499 | if(ftitle==null) { |
506 | ftitle = this.files[ff].title; | 500 | ftitle = this.files[ff].title; |
507 | }else if(ftitle!=this.files[ff].title) { | 501 | }else if(ftitle!=this.files[ff].title) { |
508 | onetitle = false; | 502 | onetitle = false; |
509 | } | 503 | } |
510 | if(ftags==null) { | 504 | if(ftags==null) { |
511 | ftags = this.files[ff].tags; | 505 | ftags = this.files[ff].tags; |
512 | }else if(ftags!=this.files[ff].tags) { | 506 | }else if(ftags!=this.files[ff].tags) { |
513 | onetag = false; | 507 | onetag = false; |
514 | } | 508 | } |
515 | } | 509 | } |
516 | } | 510 | } |
517 | if(fs) { | 511 | if(fs) { |
518 | this.upload_filename.value=''; | 512 | this.upload_filename.value=''; |
519 | this.upload_filename.disabled = true; | 513 | this.upload_filename.disabled = true; |
520 | if(onetitle) | 514 | if(onetitle) |
521 | this.upload_title.value = ftitle; | 515 | this.upload_title.value = ftitle; |
522 | this.upload_title.disabled = false; | 516 | this.upload_title.disabled = false; |
523 | if(onetag) | 517 | if(onetag) |
524 | this.upload_tags.value = ftags; | 518 | this.upload_tags.value = ftags; |
525 | this.upload_tags.disabled = false; | 519 | this.upload_tags.disabled = false; |
526 | this.upload_file_preview.src = null; | 520 | this.upload_file_preview.src = null; |
527 | this.upload_file_props.hidden = false; | 521 | this.upload_file_props.hidden = false; |
528 | }else | 522 | }else |
529 | this.disableProps(); | 523 | this.disableProps(); |
530 | } | 524 | } |
531 | }, | 525 | }, |
532 | propsToSel: function(prop) { | 526 | propsToSel: function(prop) { |
533 | if(this.selection.count<=0) return; | 527 | if(this.selection.count<=0) return; |
534 | for(var ff in this.files) { | 528 | for(var ff in this.files) { |
535 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { | 529 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { |
536 | if(prop=='filename') | 530 | if(prop=='filename') |
537 | this.files[ff].file = this.upload_filename.value; | 531 | this.files[ff].file = this.upload_filename.value; |
538 | if(prop=='title') | 532 | if(prop=='title') |
539 | this.files[ff].title = this.upload_title.value; | 533 | this.files[ff].title = this.upload_title.value; |
540 | if(prop=='tags') | 534 | if(prop=='tags') |
541 | this.files[ff].tags = this.upload_tags.value; | 535 | this.files[ff].tags = this.upload_tags.value; |
542 | this.tree.invalidateRow(ff); | 536 | this.tree.invalidateRow(ff); |
543 | } | 537 | } |
544 | } | 538 | } |
545 | }, | 539 | }, |
546 | 540 | ||
547 | on_upload: function() { | 541 | on_upload: function() { |
548 | this.selToProps(); | 542 | this.selToProps(); |
549 | this.batch_ids = new Array(); | 543 | this.batch_ids = new Array(); |
550 | this.upload_progress.value=0; | 544 | this.upload_progress.value=0; |
551 | this.upload_progress.setAttribute('hidden','false'); | 545 | this.upload_progress.setAttribute('hidden','false'); |
552 | this.upload_worker(); | 546 | this.upload_worker(); |
553 | }, | 547 | }, |
554 | on_clear: function() { | 548 | on_clear: function() { |
555 | this.clear_list(); | 549 | this.clear_list(); |
556 | }, | 550 | }, |
557 | on_remove: function() { | 551 | on_remove: function() { |
558 | if(this.selection.count) { | 552 | if(this.selection.count) { |
559 | this.tree.beginUpdateBatch(); | 553 | this.tree.beginUpdateBatch(); |
560 | for(var i=this.files.length-1;i>=0;--i) { | 554 | for(var i=this.files.length-1;i>=0;--i) { |
561 | if(this.selection.isSelected(i)) { | 555 | if(this.selection.isSelected(i)) { |
562 | this.files.splice(i,1); | 556 | this.files.splice(i,1); |
563 | this.rowCount--; | 557 | this.rowCount--; |
564 | } | 558 | } |
565 | } | 559 | } |
566 | this.tree.endUpdateBatch(); | 560 | this.tree.endUpdateBatch(); |
567 | this.selection.clearSelection(); | 561 | this.selection.clearSelection(); |
568 | } | 562 | } |
569 | }, | 563 | }, |
570 | on_add: function() { | 564 | on_add: function() { |
571 | var ifp = Components.interfaces.nsIFilePicker; | 565 | var ifp = Components.interfaces.nsIFilePicker; |
572 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); | 566 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); |
573 | fp.init(window, "Select a File", ifp.modeOpenMultiple); | 567 | fp.init(window, "Select a File", ifp.modeOpenMultiple); |
574 | fp.appendFilters(ifp.filterImages); | 568 | fp.appendFilters(ifp.filterImages); |
575 | var rv = fp.show(); | 569 | var rv = fp.show(); |
576 | if(rv==ifp.returnOK) { | 570 | if(rv==ifp.returnOK) { |
577 | var ff = fp.files; | 571 | var ff = fp.files; |
578 | while(ff.hasMoreElements()) { | 572 | while(ff.hasMoreElements()) { |
579 | var f = ff.getNext(); | 573 | var f = ff.getNext(); |
580 | f.QueryInterface(Components.interfaces.nsIFile); | 574 | f.QueryInterface(Components.interfaces.nsIFile); |
581 | this.add(f.path); | 575 | this.add(f.path); |
582 | } | 576 | } |
583 | } | 577 | } |
584 | } | 578 | } |
585 | }, | 579 | }, |
586 | 580 | ||
587 | on_set_props: function() { | 581 | on_set_props: function() { |
588 | var pset = this.photosets.sets[this.photosets.selection.currentIndex]; | 582 | var pset = this.photosets.sets[this.photosets.selection.currentIndex]; |
589 | window.openDialog( | 583 | window.openDialog( |
590 | "chrome://fireflix/content/photoset-props.xul", | 584 | "chrome://fireflix/content/photoset-props.xul", |
591 | null, "dependent,modal,dialog,chrome", this, | 585 | null, "dependent,modal,dialog,chrome", this, |
592 | pset ); | 586 | pset ); |
593 | if(pset.dirty) { | 587 | if(pset.dirty) { |
594 | var _this = this; | 588 | var _this = this; |
595 | this.flickr.api_call( | 589 | this.flickr.api_call( |
596 | { | 590 | { |
597 | method: 'flickr.photosets.editMeta', | 591 | method: 'flickr.photosets.editMeta', |
598 | auth_token: 'default', | 592 | auth_token: 'default', |
599 | photoset_id: pset.id, | 593 | photoset_id: pset.id, |
600 | title: pset.title, | 594 | title: pset.title, |
601 | description: pset.description | 595 | description: pset.description |
602 | }, function(xr) { | 596 | }, function(xr) { |
603 | pset.dirty = false; | 597 | pset.dirty = false; |
604 | _this.flickr.api_call( | 598 | _this.flickr.api_call( |
605 | { | 599 | { |
606 | method: 'flickr.photosets.getPhotos', | 600 | method: 'flickr.photosets.getPhotos', |
607 | auth_token: 'default', | 601 | auth_token: 'default', |
608 | photoset_id: pset.id | 602 | photoset_id: pset.id |
609 | }, function(xr) { | 603 | }, function(xr) { |
610 | var x = xr.responseXML; | 604 | var x = xr.responseXML; |
611 | var xp = x.evaluate( | 605 | var xp = x.evaluate( |
612 | '/rsp/photoset/photo', x, null, | 606 | '/rsp/photoset/photo', x, null, |
613 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 607 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
614 | var phids = new Array(); | 608 | var phids = new Array(); |
615 | var priph = null; | 609 | var priph = null; |
616 | var n; while(n=xp.iterateNext()) { | 610 | var n; while(n=xp.iterateNext()) { |
617 | var pid = n.getAttribute('id'); | 611 | var pid = n.getAttribute('id'); |
618 | phids.push( pid ); | 612 | phids.push( pid ); |
619 | if(pid==pset.primary && n.getAttribute('isprimary')!='1') | 613 | if(pid==pset.primary && n.getAttribute('isprimary')!='1') |
620 | priph = pid; | 614 | priph = pid; |
621 | } | 615 | } |
622 | if(priph) { | 616 | if(priph) { |
623 | _this.flickr.api_call( | 617 | _this.flickr.api_call( |
624 | { | 618 | { |
625 | method: 'flickr.photosets.editPhotos', | 619 | method: 'flickr.photosets.editPhotos', |
626 | auth_token: 'default', | 620 | auth_token: 'default', |
627 | photoset_id: pset.id, | 621 | photoset_id: pset.id, |
628 | primary_photo_id: priph, | 622 | primary_photo_id: priph, |
629 | photo_ids: phids.join(',') | 623 | photo_ids: phids.join(',') |
630 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ | 624 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ |
631 | _this.flickr_failure(x,s,c,m); | 625 | _this.flickr_failure(x,s,c,m); |
632 | } | 626 | } |
633 | ); | 627 | ); |
634 | } | 628 | } |
635 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ | 629 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ |
636 | _this.flickr_failure(x,s,c,m); | 630 | _this.flickr_failure(x,s,c,m); |
637 | } | 631 | } |
638 | ); | 632 | ); |
639 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ | 633 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ |
640 | _this.flickr_failure(x,s,c,m); | 634 | _this.flickr_failure(x,s,c,m); |
641 | } | 635 | } |
642 | ); | 636 | ); |
643 | } | 637 | } |
644 | }, | 638 | }, |
645 | on_refresh_sets: function() { | 639 | on_refresh_sets: function() { |
646 | this.refresh_sets(); | 640 | this.refresh_sets(); |
647 | }, | 641 | }, |
648 | on_cmd_sets_html: function(csfx,ev) { | 642 | on_cmd_sets_html: function(csfx,ev) { |
649 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 643 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
650 | var rv = this.build_html(this.photoset.photos,uti,utl); | 644 | var rv = this.build_html(this.photoset.photos,uti,utl); |
651 | this.popup_content(rv); | 645 | this.popup_content(rv); |
652 | }, | 646 | }, |
653 | 647 | ||
654 | on_cmd_uploads_html: function(csfx,ev) { | 648 | on_cmd_uploads_html: function(csfx,ev) { |
655 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 649 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
656 | var pids = new Array(); | 650 | var pids = new Array(); |
657 | for(var f in this.uploads.files) { | 651 | for(var f in this.uploads.files) { |
658 | if(this.uploads.selection.isSelected(f)) | 652 | if(this.uploads.selection.isSelected(f)) |
659 | if(this.uploads.files[f].photoid) | 653 | if(this.uploads.files[f].photoid) |
660 | pids.push(this.uploads.files[f].photoid); | 654 | pids.push(this.uploads.files[f].photoid); |
661 | } | 655 | } |
662 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; | 656 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; |
663 | var _this = this; | 657 | var _this = this; |
664 | this.flickr.api_call( | 658 | this.flickr.api_call( |
665 | { | 659 | { |
666 | method: 'flickr.photos.search', | 660 | method: 'flickr.photos.search', |
667 | auth_token: 'default', | 661 | auth_token: 'default', |
668 | extras: 'original_format', | 662 | extras: 'original_format', |
669 | user_id: 'me', | 663 | user_id: 'me', |
670 | per_page: pp | 664 | per_page: pp |
671 | }, | 665 | }, |
672 | function(xr) { | 666 | function(xr) { |
673 | var x = xr.responseXML; | 667 | var x = xr.responseXML; |
674 | var rv = ''; | 668 | var rv = ''; |
675 | for(var pn in pids) { | 669 | for(var pn in pids) { |
676 | var p = pids[pn]; | 670 | var p = pids[pn]; |
677 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); | 671 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); |
678 | rv += _this.photo_html(pp,uti,utl)+'\n'; | 672 | rv += _this.photo_html(pp,uti,utl)+'\n'; |
679 | } | 673 | } |
680 | _this.popup_content(rv); | 674 | _this.popup_content(rv); |
681 | }, function(x,s,c,m) { | 675 | }, function(x,s,c,m) { |
682 | _this.flickr_failure(x,s,c,m); | 676 | _this.flickr_failure(x,s,c,m); |
683 | } | 677 | } |
684 | ); | 678 | ); |
685 | }, | 679 | }, |
686 | 680 | ||
687 | /* | 681 | /* |
688 | * | 682 | * |
689 | */ | 683 | */ |
690 | foundphotos: { | 684 | foundphotos: { |
691 | fireflix: null, | 685 | fireflix: null, |
692 | init: function(f) { | 686 | init: function(f) { |
693 | this.fireflix = f; | 687 | this.fireflix = f; |
694 | this.search_for = document.getElementById('search_for'); | 688 | pull_elements(this,document,[ |
695 | this.search_tags= document.getElementById('search_tags'); | 689 | 'search_for','search_tags','search_mine', |
696 | this.search_mine = document.getElementById('search_mine'); | 690 | 'searchresult_props','search_photo', |
691 | 'searchresult_title','searchresult_description' | ||
692 | ]); | ||
697 | document.getElementById('searchresults').view = this; | 693 | document.getElementById('searchresults').view = this; |
698 | this.searchresult_props = document.getElementById('searchresult_props'); | ||
699 | this.search_photo = document.getElementById('search_photo'); | ||
700 | this.searchresult_title = document.getElementById('searchresult_title'); | ||
701 | this.searchresult_description = document.getElementById('searchresult_description'); | ||
702 | }, | 694 | }, |
703 | photos: new Array(), | 695 | photos: new Array(), |
704 | rowCount: 0, | 696 | rowCount: 0, |
705 | getCellText: function(r,c) { | 697 | getCellText: function(r,c) { |
706 | var p = this.photos[r]; | 698 | var p = this.photos[r]; |
707 | if(c.id=='sr_title') return p.title; | 699 | if(c.id=='sr_title') return p.title; |
708 | return c.id; | 700 | return c.id; |
709 | }, | 701 | }, |
710 | setTree: function(t) { this.tree = t }, | 702 | setTree: function(t) { this.tree = t }, |
711 | isContainer: function(r) { return false }, | 703 | isContainer: function(r) { return false }, |
712 | isSeparator: function(r) { return false }, | 704 | isSeparator: function(r) { return false }, |
713 | isSorted: function(r) { return false }, | 705 | isSorted: function(r) { return false }, |
714 | getLevel: function(r) { return 0 }, | 706 | getLevel: function(r) { return 0 }, |
715 | getImageSrc: function(r,c) { return null }, | 707 | getImageSrc: function(r,c) { return null }, |
716 | getRowProperties: function(r,p) { }, | 708 | getRowProperties: function(r,p) { }, |
717 | getCellProperties: function(cid,cel,p) { }, | 709 | getCellProperties: function(cid,cel,p) { }, |
718 | getColumnProperties: function(cid,cel,p) { }, | 710 | getColumnProperties: function(cid,cel,p) { }, |
719 | cycleHeader: function(cid,e) { }, | 711 | cycleHeader: function(cid,e) { }, |
720 | getParentIndex: function(r) { return -1 }, | 712 | getParentIndex: function(r) { return -1 }, |
721 | drop: function(r,o) { }, | 713 | drop: function(r,o) { }, |
722 | canDropBeforeAfter: function(r,b) { return false }, | 714 | canDropBeforeAfter: function(r,b) { return false }, |
723 | 715 | ||
724 | importXPR: function(xp) { | 716 | importXPR: function(xp) { |
725 | this.selection.clearSelection(); | 717 | this.selection.clearSelection(); |
726 | this.selection.currentIndex = -1; | 718 | this.selection.currentIndex = -1; |
727 | this.searchresult_props.hidden = true; | 719 | this.searchresult_props.hidden = true; |
728 | this.tree.beginUpdateBatch(); | 720 | this.tree.beginUpdateBatch(); |
729 | this.photos = new Array(); | 721 | this.photos = new Array(); |
730 | var n; while(n=xp.iterateNext()) { | 722 | var n; while(n=xp.iterateNext()) { |
731 | this.photos.push(new Photo(n)); | 723 | this.photos.push(new Photo(n)); |
732 | } | 724 | } |
733 | this.rowCount = this.photos.length; | 725 | this.rowCount = this.photos.length; |
734 | this.tree.endUpdateBatch(); | 726 | this.tree.endUpdateBatch(); |
735 | }, | 727 | }, |
736 | search_photos: function() { | 728 | search_photos: function() { |
737 | var pars = { | 729 | var pars = { |
738 | method: 'flickr.photos.search', | 730 | method: 'flickr.photos.search', |
739 | auth_token: 'default', | 731 | auth_token: 'default', |
740 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' | 732 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' |
741 | }; | 733 | }; |
742 | if(this.search_mine.checked) | 734 | if(this.search_mine.checked) |
743 | pars.user_id='me'; | 735 | pars.user_id='me'; |
744 | if(this.search_tags.checked) { | 736 | if(this.search_tags.checked) { |
745 | pars.tags=this.search_for.value.split(/ +/).join(','); | 737 | pars.tags=this.search_for.value.split(/ +/).join(','); |
746 | }else{ | 738 | }else{ |
747 | pars.text=this.search_for.value; | 739 | pars.text=this.search_for.value; |
748 | } | 740 | } |
749 | var _this = this; | 741 | var _this = this; |
750 | this.fireflix.flickr.api_call( pars, | 742 | this.fireflix.flickr.api_call( pars, |
751 | function(xr) { | 743 | function(xr) { |
752 | var x = xr.responseXML; | 744 | var x = xr.responseXML; |
753 | var xp = x.evaluate( | 745 | var xp = x.evaluate( |
754 | '/rsp/photos/photo', x, null, | 746 | '/rsp/photos/photo', x, null, |
755 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 747 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
756 | _this.importXPR(xp); | 748 | _this.importXPR(xp); |
757 | _this.on_select(); | 749 | _this.on_select(); |
758 | }, function(x,s,c,m) { | 750 | }, function(x,s,c,m) { |
759 | _this.fireflix.flickr_failure(x,s,c,m); | 751 | _this.fireflix.flickr_failure(x,s,c,m); |
760 | } | 752 | } |
761 | ); | 753 | ); |
762 | }, | 754 | }, |
763 | on_select: function() { | 755 | on_select: function() { |
764 | if(this.selection.currentIndex<0) { | 756 | if(this.selection.currentIndex<0) { |
765 | this.searchresult_props.hidden = true; | 757 | this.searchresult_props.hidden = true; |
766 | }else{ | 758 | }else{ |
767 | var p = this.photos[this.selection.currentIndex]; | 759 | var p = this.photos[this.selection.currentIndex]; |
768 | if(!p) { | 760 | if(!p) { |
769 | this.searchresult_props.hidden = true; | 761 | this.searchresult_props.hidden = true; |
770 | }else{ | 762 | }else{ |
771 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); | 763 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); |
772 | this.searchresult_title.value = p.title; | 764 | this.searchresult_title.value = p.title; |
773 | this.searchresult_description.value = null; | 765 | this.searchresult_description.value = null; |
774 | if(p.description==null && p.description==undefined) { | 766 | if(p.description==null && p.description==undefined) { |
775 | var pid = p.id; | 767 | var pid = p.id; |
776 | var ci = this.selection.currentIndex; | 768 | var ci = this.selection.currentIndex; |
777 | var _this = this; | 769 | var _this = this; |
778 | this.fireflix.flickr.api_call( | 770 | this.fireflix.flickr.api_call( |
779 | { | 771 | { |
780 | method: 'flickr.photos.getInfo', | 772 | method: 'flickr.photos.getInfo', |
781 | auth_token: 'default', | 773 | auth_token: 'default', |
782 | photo_id: p.id, | 774 | photo_id: p.id, |
783 | secret: p.secret | 775 | secret: p.secret |
784 | }, function(xr) { | 776 | }, function(xr) { |
785 | var pp = _this.photos[ci]; | 777 | var pp = _this.photos[ci]; |
786 | if(ci==_this.selection.currentIndex && pp.id==pid) { | 778 | if(ci==_this.selection.currentIndex && pp.id==pid) { |
787 | var n = xp_node('/rsp/photo',xr.responseXML); | 779 | var n = xp_node('/rsp/photo',xr.responseXML); |
788 | pp.fromNode_(n); | 780 | pp.fromNode_(n); |
789 | _this.searchresult_description.value=pp.description?pp.description:null; | 781 | _this.searchresult_description.value=pp.description?pp.description:null; |
790 | } | 782 | } |
791 | }, function(x,s,c,m) { | 783 | }, function(x,s,c,m) { |
792 | _this.fireflix.flickr_failure(x,s,c,m); | 784 | _this.fireflix.flickr_failure(x,s,c,m); |
793 | } | 785 | } |
794 | ); | 786 | ); |
795 | this.searchresult_props.hidden = false; | 787 | this.searchresult_props.hidden = false; |
796 | }else{ | 788 | }else{ |
797 | this.searchresult_description.value=p.description?p.description:null; | 789 | this.searchresult_description.value=p.description?p.description:null; |
798 | } | 790 | } |
799 | } | 791 | } |
800 | } | 792 | } |
801 | }, | 793 | }, |
802 | on_cmd_open: function(ev) { | 794 | on_cmd_open: function(ev) { |
803 | if(this.selection.currentIndex<0) | 795 | if(this.selection.currentIndex<0) |
804 | return; | 796 | return; |
805 | var p = this.photos[this.selection.currentIndex]; | 797 | var p = this.photos[this.selection.currentIndex]; |
806 | if(!p.id) | 798 | if(!p.id) |
807 | return; | 799 | return; |
808 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); | 800 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); |
809 | } | 801 | } |
810 | }, | 802 | }, |
811 | 803 | ||
812 | photo_html: function(p,i,l) { | 804 | photo_html: function(p,i,l) { |
813 | // TODO: add alt/title when possible | 805 | // TODO: add alt/title when possible |
814 | var rv = | 806 | var rv = |
815 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + | 807 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + |
816 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ | 808 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ |
817 | '</a>'; | 809 | '</a>'; |
818 | return rv; | 810 | return rv; |
819 | }, | 811 | }, |
820 | build_html: function(photos,uti,utl) { | 812 | build_html: function(photos,uti,utl) { |
821 | var rv = ''; | 813 | var rv = ''; |
822 | for(var i in photos) { | 814 | for(var i in photos) { |
823 | var p = photos[i]; | 815 | var p = photos[i]; |
824 | rv += this.photo_html(p,utl,uti)+'\n'; | 816 | rv += this.photo_html(p,utl,uti)+'\n'; |
825 | } | 817 | } |
826 | return rv; | 818 | return rv; |
827 | }, | 819 | }, |
828 | 820 | ||
829 | popup_content: function(s) { | 821 | popup_content: function(s) { |
830 | window.openDialog( | 822 | window.openDialog( |
831 | "chrome://fireflix/content/generated-content.xul", | 823 | "chrome://fireflix/content/generated-content.xul", |
832 | null, "dialog,chrome", this, s ); | 824 | null, "dialog,chrome", this, s ); |
833 | }, | 825 | }, |
834 | copy_to_clipboard: function(s) { | 826 | copy_to_clipboard: function(s) { |
835 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] | 827 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] |
836 | .getService(Components.interfaces.nsIClipboardHelper); | 828 | .getService(Components.interfaces.nsIClipboardHelper); |
837 | ch.copyString(s); | 829 | ch.copyString(s); |
838 | }, | 830 | }, |
839 | openTab: function(l) { | 831 | openTab: function(l) { |
840 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( | 832 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( |
841 | Components.interfaces.nsIWindowMediator ); | 833 | Components.interfaces.nsIWindowMediator ); |
842 | var bw = wm.getMostRecentWindow('navigator:browser'); | 834 | var bw = wm.getMostRecentWindow('navigator:browser'); |
843 | var b = bw.getBrowser(); | 835 | var b = bw.getBrowser(); |
844 | var t = b.addTab(l); | 836 | var t = b.addTab(l); |
845 | b.selectedTab = t; | 837 | b.selectedTab = t; |
846 | }, | 838 | }, |
847 | 839 | ||
848 | build_menus: function() { | 840 | build_menus: function() { |
849 | this.append_html_menu( | 841 | this.append_html_menu( |
850 | document.getElementById('sets_html_menu'), | 842 | document.getElementById('sets_html_menu'), |
851 | 'stm_','m_bop','cmdset_sets','cmd_sets_html' | 843 | 'stm_','m_bop','cmdset_sets','cmd_sets_html' |
852 | ); | 844 | ); |
853 | this.append_html_menu( | 845 | this.append_html_menu( |
854 | document.getElementById('uploads_html_menu'), | 846 | document.getElementById('uploads_html_menu'), |
855 | 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' | 847 | 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' |
856 | ); | 848 | ); |
857 | return; | 849 | return; |
858 | }, | 850 | }, |
859 | append_html_menu: function(m,imgt,lnkt,csid,cpfx) { | 851 | append_html_menu: function(m,imgt,lnkt,csid,cpfx) { |
860 | var mp = m.appendChild(document.createElement('menupopup')); | 852 | var mp = m.appendChild(document.createElement('menupopup')); |
861 | var t; | 853 | var t; |
862 | t=mp.appendChild(document.createElement('menuitem')); | 854 | t=mp.appendChild(document.createElement('menuitem')); |
863 | t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); | 855 | t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); |
864 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); | 856 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); |
865 | mp.appendChild(document.createElement('menuseparator')); | 857 | mp.appendChild(document.createElement('menuseparator')); |
866 | var cs = document.getElementById(csid); | 858 | var cs = document.getElementById(csid); |
867 | for(var iti=0;iti<imgt.length;++iti) { | 859 | for(var iti=0;iti<imgt.length;++iti) { |
868 | t = mp.appendChild(document.createElement('menu')); | 860 | t = mp.appendChild(document.createElement('menu')); |
869 | t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); | 861 | t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); |
870 | var smp = t.appendChild(document.createElement('menupopup')); | 862 | var smp = t.appendChild(document.createElement('menupopup')); |
871 | t=smp.appendChild(document.createElement('menuitem')); | 863 | t=smp.appendChild(document.createElement('menuitem')); |
872 | t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); | 864 | t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); |
873 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); | 865 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); |
874 | smp.appendChild(document.createElement('menuseparator')); | 866 | smp.appendChild(document.createElement('menuseparator')); |
875 | for(var lti=0;lti<lnkt.length;++lti) { | 867 | for(var lti=0;lti<lnkt.length;++lti) { |
876 | var csfx = imgt.charAt(iti)+lnkt.charAt(lti); | 868 | var csfx = imgt.charAt(iti)+lnkt.charAt(lti); |
877 | t=smp.appendChild(document.createElement('menuitem')); | 869 | t=smp.appendChild(document.createElement('menuitem')); |
878 | t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); | 870 | t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); |
879 | t.setAttribute('command',cpfx+'_'+csfx); | 871 | t.setAttribute('command',cpfx+'_'+csfx); |
880 | t=cs.appendChild(document.createElement('command')); | 872 | t=cs.appendChild(document.createElement('command')); |
881 | t.setAttribute('id',cpfx+'_'+csfx); | 873 | t.setAttribute('id',cpfx+'_'+csfx); |
882 | t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); | 874 | t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); |
883 | } | 875 | } |
884 | } | 876 | } |
885 | return mp; | 877 | return mp; |
886 | }, | 878 | }, |
887 | 879 | ||
888 | flickr_failure: function(x,s,c,m) { | 880 | flickr_failure: function(x,s,c,m) { |
889 | if(c==98) { // Invalid auth token | 881 | if(c==98) { // Invalid auth token |
890 | this.flickr.reset_token(); | 882 | this.flickr.reset_token(); |
891 | this.set_auth_state(false,false); | 883 | this.set_auth_state(false,false); |
892 | return; | 884 | return; |
893 | } | 885 | } |
894 | // TODO: is that beauty? | 886 | // TODO: is that beauty? |
895 | alert('flickr api call failed\n'+c+' '+m); | 887 | alert('flickr api call failed\n'+c+' '+m); |
896 | } | 888 | } |
897 | 889 | ||
898 | }; | 890 | }; |
diff --git a/content/util.js b/content/util.js index 5af0978..c4af09e 100644 --- a/content/util.js +++ b/content/util.js | |||
@@ -1,61 +1,70 @@ | |||
1 | /* | 1 | /* |
2 | * convert unicode string to utf-8 representation. | 2 | * convert unicode string to utf-8 representation. |
3 | * needed for correct md5 hash calculation. | 3 | * needed for correct md5 hash calculation. |
4 | */ | 4 | */ |
5 | function toutf8(ucode) { | 5 | function toutf8(ucode) { |
6 | var rv = ''; | 6 | var rv = ''; |
7 | for(var i=0;i<ucode.length;++i) { | 7 | for(var i=0;i<ucode.length;++i) { |
8 | var cc = ucode.charCodeAt(i); | 8 | var cc = ucode.charCodeAt(i); |
9 | if(cc<=0x7F) | 9 | if(cc<=0x7F) |
10 | rv += ucode.charAt(i); | 10 | rv += ucode.charAt(i); |
11 | else if(cc<=0x7ff) | 11 | else if(cc<=0x7ff) |
12 | rv += String.fromCharCode( | 12 | rv += String.fromCharCode( |
13 | 0xc0|((cc>> 6)&0x1f), | 13 | 0xc0|((cc>> 6)&0x1f), |
14 | 0x80|( cc &0x3f) ); | 14 | 0x80|( cc &0x3f) ); |
15 | else if(cc<=0xffff) | 15 | else if(cc<=0xffff) |
16 | rv += String.fromCharCode( | 16 | rv += String.fromCharCode( |
17 | 0xe0|((cc>>12)&0x0f), | 17 | 0xe0|((cc>>12)&0x0f), |
18 | 0x80|((cc>> 6)&0x3f), | 18 | 0x80|((cc>> 6)&0x3f), |
19 | 0x80|( cc &0x3f) ); | 19 | 0x80|( cc &0x3f) ); |
20 | else if(cc<=0x1fffff) | 20 | else if(cc<=0x1fffff) |
21 | rv += String.fromCharCode( | 21 | rv += String.fromCharCode( |
22 | 0xf0|((cc>>18)&0x07), | 22 | 0xf0|((cc>>18)&0x07), |
23 | 0x80|((cc>>12)&0x3f), | 23 | 0x80|((cc>>12)&0x3f), |
24 | 0x80|((cc>> 6)&0x3f), | 24 | 0x80|((cc>> 6)&0x3f), |
25 | 0x80|( cc &0x3f) ); | 25 | 0x80|( cc &0x3f) ); |
26 | else if(cc<=0x03ffffff) | 26 | else if(cc<=0x03ffffff) |
27 | rv += String.fromCharCode( | 27 | rv += String.fromCharCode( |
28 | 0xf8|((cc>>24)&0x03), | 28 | 0xf8|((cc>>24)&0x03), |
29 | 0x80|((cc>>18)&0x3f), | 29 | 0x80|((cc>>18)&0x3f), |
30 | 0x80|((cc>>12)&0x3f), | 30 | 0x80|((cc>>12)&0x3f), |
31 | 0x80|((cc>> 6)&0x3f), | 31 | 0x80|((cc>> 6)&0x3f), |
32 | 0x80|( cc &0x3f) ); | 32 | 0x80|( cc &0x3f) ); |
33 | else if(cc<=0x7fffffff) | 33 | else if(cc<=0x7fffffff) |
34 | rv += String.fromCharCode( | 34 | rv += String.fromCharCode( |
35 | 0xfc|((cc>>30)&0x01), | 35 | 0xfc|((cc>>30)&0x01), |
36 | 0x80|((cc>>24)&0x3f), | 36 | 0x80|((cc>>24)&0x3f), |
37 | 0x80|((cc>>18)&0x3f), | 37 | 0x80|((cc>>18)&0x3f), |
38 | 0x80|((cc>>12)&0x3f), | 38 | 0x80|((cc>>12)&0x3f), |
39 | 0x80|((cc>> 6)&0x3f), | 39 | 0x80|((cc>> 6)&0x3f), |
40 | 0x80|( cc &0x3f) ); | 40 | 0x80|( cc &0x3f) ); |
41 | } | 41 | } |
42 | return rv; | 42 | return rv; |
43 | } | 43 | } |
44 | 44 | ||
45 | /* | 45 | /* |
46 | * extract xpath-specified string value | 46 | * extract xpath-specified string value |
47 | */ | 47 | */ |
48 | function xp_str(xp,x) { | 48 | function xp_str(xp,x) { |
49 | var rv = x.evaluate( | 49 | var rv = x.evaluate( |
50 | xp, x, null, XPathResult.STRING_TYPE, null ); | 50 | xp, x, null, XPathResult.STRING_TYPE, null ); |
51 | return rv.stringValue; | 51 | return rv.stringValue; |
52 | } | 52 | } |
53 | /* | 53 | /* |
54 | * extract xpath-specified node | 54 | * extract xpath-specified node |
55 | */ | 55 | */ |
56 | function xp_node(xp,x) { | 56 | function xp_node(xp,x) { |
57 | var rv = x.evaluate( | 57 | var rv = x.evaluate( |
58 | xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); | 58 | xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); |
59 | return rv.singleNodeValue; | 59 | return rv.singleNodeValue; |
60 | } | 60 | } |
61 | 61 | ||
62 | /* | ||
63 | * pull in elements into documents as a member variables | ||
64 | */ | ||
65 | function pull_elements(th,d,els) { | ||
66 | for(var e in els) { | ||
67 | var en=els[e]; | ||
68 | th[en] = d.getElementById(en); | ||
69 | } | ||
70 | } | ||