summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js36
-rw-r--r--content/util.js9
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,56 +1,52 @@
function splitascii(s) {
var rv='';
for(var i=0;i<s.length;++i) {
var w = s.charCodeAt(i);
rv += String.fromCharCode(
w&0xff, (w>>8)&0xff );
}
return rv;
}
var fireflix = {
flickr: new Flickr(),
init: function() {
- this.cmd_auth_auth = document.getElementById('cmd_auth_auth');
- this.cmd_auth_done = document.getElementById('cmd_auth_done');
- this.cmd_auth_unauth = document.getElementById('cmd_auth_unauth');
- this.menu_auth_done = document.getElementById('menu_auth_done');
- this.b_auth = document.getElementById('b_auth');
- this.b_auth_done = document.getElementById('b_auth_done');
- this.auth_info = document.getElementById('auth_info');
- this.loc_strings = document.getElementById('loc_strings');
+ pull_elements(this,document,[
+ 'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth',
+ 'menu_auth_done','b_auth','b_auth_done','auth_info',
+ 'loc_strings','cmd_set_props'
+ ]);
this.build_menus();
- this.cmd_set_props = document.getElementById('cmd_set_props');
this.foundphotos.init(this);
this.photosets.init(this);
this.photoset.init(this);
this.uploads.init(this);
this.uploadObserver.init(this);
this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3';
this.flickr.api_shs = '9c33c9e2f0f0cfd5';
this.flickr.prefs_root = 'net.klever.kin.fireflix';
this.flickr.load_token();
document.getElementById('setslist').view = this.photosets;
document.getElementById('setphotos').view = this.photoset;
document.getElementById('uploadlist').view = this.uploads;
this.no_auth_info_label = this.auth_info.value;
this.set_auth_state(this.flickr.token,false);
if(this.flickr.token) {
this.refresh_stuff();
}else{
this.on_cmd_auth();
}
},
set_auth_state: function(au,inp) { /* authorized, in progress */
this.cmd_auth_unauth.disabled = !au;
this.b_auth.hidden = au || inp;
this.b_auth_done.hidden = !inp;
this.menu_auth_done.hidden = !inp;
this.cmd_auth_done.setAttribute('disabled',!inp);
this.auth_info.disabled = !au;
if(au) {
this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */
}else{
this.auth_info.value = this.no_auth_info_label;
}
@@ -283,70 +279,68 @@ var fireflix = {
var d = di.first;
switch(d.flavour.contentType) {
case 'text/unicode':
this.drop_urilist(ev,d.data,s);
break;
case 'application/x-moz-file':
this.fireflix.uploads.add(d.data.path);
document.getElementById('fireflix_tabs').selectedTab
= document.getElementById('tab_upload');
break;
case 'text/uri-list':
// is it ascii or could it be utf8?
this.drop_urilist(ev,splitascii(d.data),s);
break;
default: alert(d.flavour.contentType+':'+d.data); break;
};
},
drop_urilist: function(ev,ul,s) {
// TODO: check for being a file?
var us = decodeURIComponent(ul).split(/[\r\n]/);
for(var ui in us)
if(/\S/.test(us[ui]))
this.fireflix.uploads.add(us[ui]);
document.getElementById('fireflix_tabs').selectedTab
= document.getElementById('tab_upload');
}
},
uploads: {
fireflix: null,
init: function(f) {
this.fireflix=f;
- this.upload_filename = document.getElementById('upload_filename');
- this.upload_title = document.getElementById('upload_title');
- this.upload_file_preview = document.getElementById('upload_file_preview');
- this.upload_file_props = document.getElementById('upload_file_props');
- this.upload_progress = document.getElementById('upload_progress');
- this.upload_tags = document.getElementById('upload_tags');
+ pull_elements(this,document,[
+ 'upload_filename','upload_title','upload_file_preview',
+ 'upload_file_props','upload_progress','upload_tags'
+ ]);
},
files: new Array(),
rowCount: 0,
getCellText: function(r,c) {
var f = this.files[r];
if(c.id=='up_file') return f.file;
if(c.id=='up_title') return f.title;
if(c.id=='up_status') return f.state;
return c.id;
},
setTree: function(t) { this.tree = t },
isContainer: function(r) { return false; },
isSeparator: function(r) { return false; },
isSorted: function(r) { return false; },
getLevel: function(r) { return 0; },
getImageSrc: function(r,c) { return null },
getRowProperties: function(r,p) {
try {
if(!Components) return;
}catch(e) { return }
var f = this.files[r];
var as = Components.classes['@mozilla.org/atom-service;1'].
getService(Components.interfaces.nsIAtomService);
p.AppendElement(as.getAtom(f.state));
},
getCellProperties: function(r,c,p) { this.getRowProperties(r,p); },
getColumnProperties: function(c,p) { },
cycleHeader: function(cid,e) { },
getParentIndex: function(r) { return -1; },
drop: function(r,o) { },
canDropBeforeAfter: function(r,b) { return false },
@@ -662,72 +656,70 @@ var fireflix = {
var pp = this.uploads.rowCount*2; if(pp>500) pp = 500;
var _this = this;
this.flickr.api_call(
{
method: 'flickr.photos.search',
auth_token: 'default',
extras: 'original_format',
user_id: 'me',
per_page: pp
},
function(xr) {
var x = xr.responseXML;
var rv = '';
for(var pn in pids) {
var p = pids[pn];
var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x));
rv += _this.photo_html(pp,uti,utl)+'\n';
}
_this.popup_content(rv);
}, function(x,s,c,m) {
_this.flickr_failure(x,s,c,m);
}
);
},
/*
*
*/
foundphotos: {
fireflix: null,
init: function(f) {
this.fireflix = f;
- this.search_for = document.getElementById('search_for');
- this.search_tags= document.getElementById('search_tags');
- this.search_mine = document.getElementById('search_mine');
+ pull_elements(this,document,[
+ 'search_for','search_tags','search_mine',
+ 'searchresult_props','search_photo',
+ 'searchresult_title','searchresult_description'
+ ]);
document.getElementById('searchresults').view = this;
- this.searchresult_props = document.getElementById('searchresult_props');
- this.search_photo = document.getElementById('search_photo');
- this.searchresult_title = document.getElementById('searchresult_title');
- this.searchresult_description = document.getElementById('searchresult_description');
},
photos: new Array(),
rowCount: 0,
getCellText: function(r,c) {
var p = this.photos[r];
if(c.id=='sr_title') return p.title;
return c.id;
},
setTree: function(t) { this.tree = t },
isContainer: function(r) { return false },
isSeparator: function(r) { return false },
isSorted: function(r) { return false },
getLevel: function(r) { return 0 },
getImageSrc: function(r,c) { return null },
getRowProperties: function(r,p) { },
getCellProperties: function(cid,cel,p) { },
getColumnProperties: function(cid,cel,p) { },
cycleHeader: function(cid,e) { },
getParentIndex: function(r) { return -1 },
drop: function(r,o) { },
canDropBeforeAfter: function(r,b) { return false },
importXPR: function(xp) {
this.selection.clearSelection();
this.selection.currentIndex = -1;
this.searchresult_props.hidden = true;
this.tree.beginUpdateBatch();
this.photos = new Array();
var n; while(n=xp.iterateNext()) {
this.photos.push(new Photo(n));
}
this.rowCount = this.photos.length;
diff --git a/content/util.js b/content/util.js
index 5af0978..c4af09e 100644
--- a/content/util.js
+++ b/content/util.js
@@ -30,32 +30,41 @@ function toutf8(ucode) {
0x80|((cc>>12)&0x3f),
0x80|((cc>> 6)&0x3f),
0x80|( cc &0x3f) );
else if(cc<=0x7fffffff)
rv += String.fromCharCode(
0xfc|((cc>>30)&0x01),
0x80|((cc>>24)&0x3f),
0x80|((cc>>18)&0x3f),
0x80|((cc>>12)&0x3f),
0x80|((cc>> 6)&0x3f),
0x80|( cc &0x3f) );
}
return rv;
}
/*
* extract xpath-specified string value
*/
function xp_str(xp,x) {
var rv = x.evaluate(
xp, x, null, XPathResult.STRING_TYPE, null );
return rv.stringValue;
}
/*
* extract xpath-specified node
*/
function xp_node(xp,x) {
var rv = x.evaluate(
xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null );
return rv.singleNodeValue;
}
+/*
+ * pull in elements into documents as a member variables
+ */
+function pull_elements(th,d,els) {
+ for(var e in els) {
+ var en=els[e];
+ th[en] = d.getElementById(en);
+ }
+}