Add bookmarklet support

This commit is contained in:
Simon Kornblith 2011-08-30 06:46:47 +00:00
parent 16a3d3f1ed
commit 8ec4377d3e
3 changed files with 21 additions and 6 deletions

View file

@ -83,7 +83,9 @@ Zotero.ItemTypes = new function() {
this.getImageSrc = function(idOrName) {
if(!Zotero.Connector_Types["itemTypes"][idOrName]) return false;
if(Zotero.isFx) {
if(Zotero.isBookmarklet) {
return ZOTERO_CONFIG.BOOKMARKLET_URL+"icons/"+Zotero.Connector_Types["itemTypes"][idOrName].icon;
} else if(Zotero.isFx) {
return "chrome://zotero/skin/"+Zotero.Connector_Types["itemTypes"][idOrName].icon;
} else if(Zotero.isChrome) {
return chrome.extension.getURL("images/"+Zotero.Connector_Types["itemTypes"][idOrName].icon);

View file

@ -70,6 +70,9 @@ Zotero.Server = new function() {
if(!Zotero.isServer) {
response += "X-Zotero-Version: "+Zotero.version+"\r\n";
response += "X-Zotero-Connector-API-Version: "+CONNECTOR_API_VERSION+"\r\n";
response += "Access-Control-Allow-Origin: "+ZOTERO_CONFIG.BOOKMARKLET_URL+"iframe.html\r\n";
response += "Access-Control-Allow-Methods: POST, GET, OPTIONS\r\n";
response += "Access-Control-Allow-Headers: Content-Type,X-Zotero-Connector-API-Version,X-Zotero-Version\r\n";
}
if(body) {

View file

@ -49,9 +49,20 @@ Zotero.Server.Connector.GetTranslators.prototype = {
*/
"init":function(data, sendResponseCallback) {
// Translator data
if(data.url) {
var me = this;
Zotero.Translators.getWebTranslatorsForLocation(data.url, function(data) {
sendResponseCallback(200, "application/json",
JSON.stringify(me._serializeTranslators(data[0])));
});
} else {
var responseData = this._serializeTranslators(Zotero.Translators.getAll());
sendResponseCallback(200, "application/json", JSON.stringify(responseData));
}
},
"_serializeTranslators":function(translators) {
var responseData = [];
var translators = Zotero.Translators.getAll();
for each(var translator in translators) {
let serializableTranslator = {};
for each(var key in ["translatorID", "translatorType", "label", "creator", "target",
@ -61,8 +72,7 @@ Zotero.Server.Connector.GetTranslators.prototype = {
}
responseData.push(serializableTranslator);
}
sendResponseCallback(200, "application/json", JSON.stringify(responseData));
return responseData;
}
}
@ -260,7 +270,7 @@ Zotero.Server.Connector.SavePage.prototype = {
translate.setHandler("done", function(obj, item) {
me._translate.cookieSandbox.destroy();
Zotero.Browser.deleteHiddenBrowser(me._browser);
if(jsonItems.length) {
if(jsonItems.length || me.selectedItems === false) {
me._sendResponse(201, "application/json", JSON.stringify({"items":jsonItems}));
} else {
me._sendResponse(500);