- Fixes #1855, TypeError: Converting circular structure to JSON in handler 0 for itemSaving
- Rename translate_webkit.js to translate_generic.js, since it's also going to get used for server side translation
This commit is contained in:
parent
8640bbf37b
commit
599f50455e
|
@ -38,19 +38,6 @@ Zotero.Translate.ItemSaver.prototype = {
|
||||||
* Saves items to Standalone or the server
|
* Saves items to Standalone or the server
|
||||||
*/
|
*/
|
||||||
"saveItems":function(items, callback) {
|
"saveItems":function(items, callback) {
|
||||||
// don't save documents as documents, since we can't pass them around
|
|
||||||
var nItems = items.length;
|
|
||||||
for(var i=0; i<nItems.length; i++) {
|
|
||||||
var attachments = item[i].attachments;
|
|
||||||
var nAttachments = attachments.length;
|
|
||||||
for(var j=0; j<nAttachments.length; j++) {
|
|
||||||
if(attachments[j].document) {
|
|
||||||
attachments[j].url = attachments[j].document.location.href;
|
|
||||||
delete attachments[j].document;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var me = this;
|
var me = this;
|
||||||
// first try to save items via connector
|
// first try to save items via connector
|
||||||
Zotero.Connector.callMethod("saveItems", {"items":items}, function(success, status) {
|
Zotero.Connector.callMethod("saveItems", {"items":items}, function(success, status) {
|
||||||
|
|
|
@ -108,6 +108,18 @@ Zotero.Translate.Sandbox = {
|
||||||
// We use this within the connector to keep track of items as they are saved
|
// We use this within the connector to keep track of items as they are saved
|
||||||
if(!item.id) item.id = Zotero.Utilities.randomString();
|
if(!item.id) item.id = Zotero.Utilities.randomString();
|
||||||
|
|
||||||
|
// don't save documents as documents in connector, since we can't pass them around
|
||||||
|
if(Zotero.isConnector) {
|
||||||
|
var attachments = item.attachments;
|
||||||
|
var nAttachments = attachments.length;
|
||||||
|
for(var j=0; j<nAttachments; j++) {
|
||||||
|
if(attachments[j].document) {
|
||||||
|
attachments[j].url = attachments[j].document.location.href;
|
||||||
|
delete attachments[j].document;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(translate instanceof Zotero.Translate.Web) {
|
if(translate instanceof Zotero.Translate.Web) {
|
||||||
// For web translators, we queue saves
|
// For web translators, we queue saves
|
||||||
translate.saveQueue.push(item);
|
translate.saveQueue.push(item);
|
||||||
|
|
93
chrome/content/zotero/xpcom/translation/translate_generic.js
Normal file
93
chrome/content/zotero/xpcom/translation/translate_generic.js
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
***** BEGIN LICENSE BLOCK *****
|
||||||
|
|
||||||
|
Copyright © 2009 Center for History and New Media
|
||||||
|
George Mason University, Fairfax, Virginia, USA
|
||||||
|
http://zotero.org
|
||||||
|
|
||||||
|
This file is part of Zotero.
|
||||||
|
|
||||||
|
Zotero is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Zotero is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
***** END LICENSE BLOCK *****
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class Manages the translator sandbox
|
||||||
|
* @param {Zotero.Translate} translate
|
||||||
|
* @param {String|window} sandboxLocation
|
||||||
|
*/
|
||||||
|
Zotero.Translate.SandboxManager = function(sandboxLocation) {
|
||||||
|
this.sandbox = {"Zotero":{}};
|
||||||
|
}
|
||||||
|
|
||||||
|
Zotero.Translate.SandboxManager.prototype = {
|
||||||
|
/**
|
||||||
|
* Evaluates code in the sandbox
|
||||||
|
* @param {String} code Code to evaluate
|
||||||
|
* @param {String[]} functions Functions to import into the sandbox (rather than leaving
|
||||||
|
* as inner functions)
|
||||||
|
*/
|
||||||
|
"eval":function(code, functions) {
|
||||||
|
// delete functions to import
|
||||||
|
for(var i in functions) {
|
||||||
|
delete this.sandbox[functions[i]];
|
||||||
|
}
|
||||||
|
|
||||||
|
// eval in sandbox scope
|
||||||
|
with(this.sandbox) {
|
||||||
|
eval(code);
|
||||||
|
}
|
||||||
|
// import inner functions (what a mess)
|
||||||
|
for(var i in functions) {
|
||||||
|
try {
|
||||||
|
this.sandbox[functions[i]] = eval(functions[i]);
|
||||||
|
} catch(e) {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports an object into the sandbox
|
||||||
|
*
|
||||||
|
* @param {Object} object Object to be imported (under Zotero)
|
||||||
|
* @param {Boolean} passTranslateAsFirstArgument Whether the translate instance should be passed
|
||||||
|
* as the first argument to the function.
|
||||||
|
*/
|
||||||
|
"importObject":function(object, passAsFirstArgument, attachTo) {
|
||||||
|
if(!attachTo) attachTo = this.sandbox.Zotero;
|
||||||
|
|
||||||
|
for(var key in (object.__exposedProps__ ? object.__exposedProps__ : object)) {
|
||||||
|
if(Function.prototype[key]) continue;
|
||||||
|
if(typeof object[key] === "function" || typeof object[key] === "object") {
|
||||||
|
// magic closures
|
||||||
|
attachTo[key] = new function() {
|
||||||
|
var fn = object[key];
|
||||||
|
return function() {
|
||||||
|
var args = (passAsFirstArgument ? [passAsFirstArgument] : []);
|
||||||
|
for(var i=0; i<arguments.length; i++) {
|
||||||
|
args.push(arguments[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fn.apply(object, args);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// attach members
|
||||||
|
this.importObject(object[key], passAsFirstArgument ? passAsFirstArgument : null, attachTo[key]);
|
||||||
|
} else {
|
||||||
|
attachTo[key] = object[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user