summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2006-10-01 20:31:31 (UTC)
committer Michael Krelin <hacker@klever.net>2006-10-01 20:31:31 (UTC)
commitd9372f72e080857d52ef7e60b99d95b3b3cb6ad3 (patch) (side-by-side diff)
treeb54d61a4c39c6182da8a5c76e0e9b8c44958903e
parentfa83ec27570f4d397aefeaa11e1f74b49b8d9402 (diff)
downloadfireflix-d9372f72e080857d52ef7e60b99d95b3b3cb6ad3.zip
fireflix-d9372f72e080857d52ef7e60b99d95b3b3cb6ad3.tar.gz
fireflix-d9372f72e080857d52ef7e60b99d95b3b3cb6ad3.tar.bz2
scroll newly obtained search results to the top
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@174 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js1
1 files changed, 1 insertions, 0 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index 6681303..0f01d26 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -559,345 +559,346 @@ var fireflix = {
this.rowCount--;
}
}
this.tree.endUpdateBatch();
this.selection.clearSelection();
}
},
on_add: function() {
var ifp = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp);
fp.init(window, "Select a File", ifp.modeOpenMultiple);
fp.appendFilters(ifp.filterImages);
var rv = fp.show();
if(rv==ifp.returnOK) {
var ff = fp.files;
while(ff.hasMoreElements()) {
var f = ff.getNext();
f.QueryInterface(Components.interfaces.nsIFile);
this.add(f.path);
}
}
}
},
on_set_props: function() {
var pset = this.photosets.sets[this.photosets.selection.currentIndex];
window.openDialog(
"chrome://fireflix/content/photoset-props.xul",
null, "dependent,modal,dialog,chrome", this,
pset );
if(pset.dirty) {
var _this = this;
this.flickr.api_call(
{
method: 'flickr.photosets.editMeta',
auth_token: 'default',
photoset_id: pset.id,
title: pset.title,
description: pset.description
}, function(xr) {
pset.dirty = false;
_this.flickr.api_call(
{
method: 'flickr.photosets.getPhotos',
auth_token: 'default',
photoset_id: pset.id
}, function(xr) {
var x = xr.responseXML;
var xp = x.evaluate(
'/rsp/photoset/photo', x, null,
XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
var phids = new Array();
var priph = null;
var n; while(n=xp.iterateNext()) {
var pid = n.getAttribute('id');
phids.push( pid );
if(pid==pset.primary && n.getAttribute('isprimary')!='1')
priph = pid;
}
if(priph) {
_this.flickr.api_call(
{
method: 'flickr.photosets.editPhotos',
auth_token: 'default',
photoset_id: pset.id,
primary_photo_id: priph,
photo_ids: phids.join(',')
}, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */
_this.flickr_failure(x,s,c,m);
}
);
}
}, function(x,s,c,m) { /* flickr.photosets.getPhotos */
_this.flickr_failure(x,s,c,m);
}
);
}, function(x,s,c,m) { /* flickr.photosets.editMeta */
_this.flickr_failure(x,s,c,m);
}
);
}
},
on_refresh_sets: function() {
this.refresh_sets();
},
on_cmd_sets_html: function(csfx,ev) {
var uti = csfx.charAt(0); var utl = csfx.charAt(1);
var rv = this.build_html(this.photoset.photos,uti,utl);
this.popup_content(rv);
},
on_cmd_uploads_html: function(csfx,ev) {
var uti = csfx.charAt(0); var utl = csfx.charAt(1);
var pids = new Array();
for(var f in this.uploads.files) {
if(this.uploads.selection.isSelected(f))
if(this.uploads.files[f].photoid)
pids.push(this.uploads.files[f].photoid);
}
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;
pull_elements(this,document,[
'search_for','search_tags','search_mine',
'searchresult_props','search_photo',
'searchresult_title','searchresult_description'
]);
document.getElementById('searchresults').view = this;
},
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;
this.tree.endUpdateBatch();
},
search_photos: function() {
var pars = {
method: 'flickr.photos.search',
auth_token: 'default',
extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo'
};
if(this.search_mine.checked)
pars.user_id='me';
if(this.search_tags.checked) {
pars.tags=this.search_for.value.split(/ +/).join(',');
}else{
pars.text=this.search_for.value;
}
var _this = this;
this.fireflix.flickr.api_call( pars,
function(xr) {
var x = xr.responseXML;
var xp = x.evaluate(
'/rsp/photos/photo', x, null,
XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
_this.importXPR(xp);
+ _this.tree.ensureRowIsVisible(0);
_this.on_select();
}, function(x,s,c,m) {
_this.fireflix.flickr_failure(x,s,c,m);
}
);
},
render_description_frame: function(content) {
if(!content) {
this.searchresult_description.innerHTML = '';
}else{
this.searchresult_description.innerHTML = content?content:'';
/* of all linking elements flickr only allows a */
var as = this.searchresult_description.getElementsByTagName('a');
for(var a=0;a<as.length;++a)
as.item(a).setAttribute('target','_blank');
}
},
on_select: function() {
if(this.selection.currentIndex<0) {
this.searchresult_props.hidden = true;
}else{
var p = this.photos[this.selection.currentIndex];
if(!p) {
this.searchresult_props.hidden = true;
}else{
this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t');
this.searchresult_title.value = p.title;
this.render_description_frame(null);
if(p.description==null && p.description==undefined) {
var pid = p.id;
var ci = this.selection.currentIndex;
var _this = this;
this.fireflix.flickr.api_call(
{
method: 'flickr.photos.getInfo',
auth_token: 'default',
photo_id: p.id,
secret: p.secret
}, function(xr) {
var pp = _this.photos[ci];
if(ci==_this.selection.currentIndex && pp.id==pid) {
var n = xp_node('/rsp/photo',xr.responseXML);
pp.fromNode_(n);
_this.render_description_frame(pp.description);
}
}, function(x,s,c,m) {
_this.fireflix.flickr_failure(x,s,c,m);
}
);
this.searchresult_props.hidden = false;
}else{
this.render_description_frame(p.description);
}
}
}
},
on_cmd_open: function(ev) {
if(this.selection.currentIndex<0)
return;
var p = this.photos[this.selection.currentIndex];
if(!p.id)
return;
this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p'));
}
},
photo_html: function(p,i,l) {
// TODO: add alt/title when possible
var rv =
'<a href="'+this.flickr.make_photo_url(p,l)+'">' +
'<img src="'+this.flickr.make_photo_url(p,i)+'" />'+
'</a>';
return rv;
},
build_html: function(photos,uti,utl) {
var rv = '';
for(var i in photos) {
var p = photos[i];
rv += this.photo_html(p,utl,uti)+'\n';
}
return rv;
},
popup_content: function(s) {
window.openDialog(
"chrome://fireflix/content/generated-content.xul",
null, "dialog,chrome", this, s );
},
copy_to_clipboard: function(s) {
var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
.getService(Components.interfaces.nsIClipboardHelper);
ch.copyString(s);
},
openTab: function(l) {
var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(
Components.interfaces.nsIWindowMediator );
var bw = wm.getMostRecentWindow('navigator:browser');
var b = bw.getBrowser();
var t = b.addTab(l);
b.selectedTab = t;
},
build_menus: function() {
this.append_html_menu(
document.getElementById('sets_html_menu'),
'stm_','m_bop','cmdset_sets','cmd_sets_html'
);
this.append_html_menu(
document.getElementById('uploads_html_menu'),
'stm_','m_bop','cmdset_uploads','cmd_uploads_html'
);
return;
},
append_html_menu: function(m,imgt,lnkt,csid,cpfx) {
var mp = m.appendChild(document.createElement('menupopup'));
var t;
t=mp.appendChild(document.createElement('menuitem'));
t.setAttribute('label',this.loc_strings.getString('menutitle_Images'));
t.setAttribute('class','menuhead');t.setAttribute('disabled','true');
mp.appendChild(document.createElement('menuseparator'));
var cs = document.getElementById(csid);
for(var iti=0;iti<imgt.length;++iti) {
t = mp.appendChild(document.createElement('menu'));
t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti)));
var smp = t.appendChild(document.createElement('menupopup'));
t=smp.appendChild(document.createElement('menuitem'));
t.setAttribute('label',this.loc_strings.getString('menutitle_Links'));
t.setAttribute('class','menuhead');t.setAttribute('disabled','true');
smp.appendChild(document.createElement('menuseparator'));
for(var lti=0;lti<lnkt.length;++lti) {
var csfx = imgt.charAt(iti)+lnkt.charAt(lti);
t=smp.appendChild(document.createElement('menuitem'));
t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti)));
t.setAttribute('command',cpfx+'_'+csfx);
t=cs.appendChild(document.createElement('command'));
t.setAttribute('id',cpfx+'_'+csfx);
t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)");
}
}
return mp;
},
flickr_failure: function(x,s,c,m) {
if(c==98) { // Invalid auth token
this.flickr.reset_token();
this.set_auth_state(false,false);
return;
}
// TODO: is that beauty?
alert('flickr api call failed\n'+c+' '+m);
}
};