summaryrefslogtreecommitdiffabout
path: root/content/fireflix.js
authorMichael Krelin <hacker@klever.net>2006-09-29 23:02:49 (UTC)
committer Michael Krelin <hacker@klever.net>2006-09-29 23:02:49 (UTC)
commit74a277c2d7ac5416c3b55565e6d5e8e5a15b389d (patch) (unidiff)
tree755ac7da52079e87a29b68191e66d7e1d7c0a766 /content/fireflix.js
parent3cf3cf1000ce6b27ac622c75fc3d114874e2f3a8 (diff)
downloadfireflix-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
Diffstat (limited to 'content/fireflix.js') (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js36
1 files changed, 14 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,72 +1,68 @@
1function splitascii(s) { 1function 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
12var fireflix = { 12var 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() {
@@ -267,102 +263,100 @@ var fireflix = {
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,
@@ -646,104 +640,102 @@ var fireflix = {
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;