Merge branch '3.0'

Conflicts:
	chrome/content/zotero/recognizePDF.js
	chrome/content/zotero/xpcom/cite.js
This commit is contained in:
Simon Kornblith 2012-12-19 23:16:56 -05:00
commit 45e28cf769
9 changed files with 59 additions and 35 deletions

View file

@ -806,7 +806,8 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
// if there's already a scrapable page in the browser window, and it's
// still there, ensure it is actually part of the page, then return
if(this.page.translators && this.page.translators.length && this.page.document.location) {
if(this.page.document.defaultView && !this.page.document.defaultView.closed) {
if(this.page.document.defaultView && !this.page.document.defaultView.closed
&& this.page.document.location.href != translate.document.location.href) {
// if it is still there, switch translation to take place on
if(!translators.length || this.page.translators[0].priority <= translators[0].priority) return;
} else {

View file

@ -47,11 +47,21 @@ Zotero_Ingester_Interface_SelectItems.init = function() {
var listbox = document.getElementById("zotero-selectitems-links");
for(var i in this.io.dataIn) { // we could use a tree for this if we wanted to
var item = this.io.dataIn[i];
var title, checked = false;
if(item && typeof(item) == "object" && item.title !== undefined) {
title = item.title;
checked = !!item.checked;
} else {
title = item;
}
var itemNode = document.createElement("listitem");
itemNode.setAttribute("type", "checkbox");
itemNode.setAttribute("value", i);
itemNode.setAttribute("label", this.io.dataIn[i]);
itemNode.setAttribute("checked", false);
itemNode.setAttribute("label", title);
itemNode.setAttribute("checked", checked);
listbox.appendChild(itemNode);
}
}

View file

@ -310,7 +310,7 @@ Zotero_RecognizePDF.Recognizer.prototype.recognize = function(file, libraryID, c
Zotero.debug(allText);
var m = Zotero.Utilities.cleanDOI(lines.slice(0,80).join('\n'));
if(m) {
this._DOI = m[0];
this._DOI = m;
} else { // dont look for ISBNs if we found a DOI
var isbns = this._findISBNs(allText);
if(isbns.length > 0) {

View file

@ -422,7 +422,11 @@ Zotero_TranslatorTester.prototype.runTest = function(test, doc, testDoneCallback
var newItems = {};
var haveItems = false;
for(var i in items) {
newItems[i] = items[i];
if(items[i] && typeof(items[i]) == "object" && items[i].title !== undefined) {
newItems[i] = items[i].title;
} else {
newItems[i] = items[i];
}
haveItems = true;
// only save one item if "items":"multiple" (as opposed to an array of items)
@ -546,7 +550,11 @@ Zotero_TranslatorTester.prototype.newTest = function(doc, testReadyCallback) {
var newItems = {};
for(var i in items) {
newItems[i] = items[i];
if(items[i] && typeof(items[i]) == "object" && items[i].title !== undefined) {
newItems[i] = items[i].title;
} else {
newItems[i] = items[i];
}
break;
}

View file

@ -633,7 +633,7 @@ var wpdDOMSaver = {
// FONT_FACE_RULE = 5,
// PAGE_RULE = 6
processCSSRecursively: function (aCSS) {
if (aCSS.disabled) return "";
if (!aCSS || aCSS.disabled) return "";
var content = "";
var medium = aCSS.media.mediaText;
if (medium != "" && medium.indexOf("screen") < 0 && medium.indexOf("all") < 0) {
@ -966,8 +966,9 @@ var wpdDOMSaver = {
if (this.option["format"]) {
var myStyleSheets = aDocument.styleSheets;
// get all style sheets to "CSSText"
for (var i = 0; i < myStyleSheets.length; i++)
CSSText += this.processCSSRecursively(myStyleSheets[i]);
for (var i = 0; i < myStyleSheets.length; i++) {
CSSText += this.processCSSRecursively(myStyleSheets[i]);
}
if (CSSText) {
// don't forget to convert the CSS String to the document charset..
// (necessary for e.g. font-family)

View file

@ -219,9 +219,9 @@ Zotero.Server.Connector.SavePage.prototype = {
* @param {Object} data POST data or GET query string
* @param {Function} sendResponseCallback function to send HTTP response
*/
"init":function(data, sendResponseCallback) {
"init":function(url, data, sendResponseCallback) {
this.sendResponse = sendResponseCallback;
Zotero.Server.Connector.Detect.prototype.init.apply(this, [data, sendResponseCallback])
Zotero.Server.Connector.Detect.prototype.init.apply(this, [url, data, sendResponseCallback])
},
/**

View file

@ -1042,7 +1042,7 @@ Zotero.Translate.Base.prototype = {
this._currentState = "translate";
if(!this.translator || !this.translator.length) {
throw new Error("Failed: no translator specified");
this.complete(false, new Error("No translator specified"));
}
this._libraryID = libraryID;
@ -2094,8 +2094,8 @@ Zotero.Translate.Search.prototype.setTranslator = function(translator) {
*/
Zotero.Translate.Search.prototype.complete = function(returnValue, error) {
if(this._currentState == "translate" && (!this.newItems || !this.newItems.length)) {
Zotero.debug("Translate: Could not find a result using "+this.translator[0].label+": \n"
+this._generateErrorString(error), 3);
Zotero.debug("Translate: Could not find a result using "+this.translator[0].label, 3);
if(error) Zotero.debug(this._generateErrorString(error), 3);
if(this.translator.length > 1) {
this.translator.shift();
this.translate(this._libraryID, this._saveAttachments);

View file

@ -277,7 +277,10 @@ Zotero.Utilities = {
* Return isbn if valid, otherwise return false
*/
"cleanISBN":function(/**String*/ isbn) {
isbn = isbn.replace(/[^x\d]+/ig, '').toUpperCase();
isbn = isbn.replace(/[^0-9a-z]+/ig, '').toUpperCase() //we only want to ignore punctuation, spaces
.match(/(?:97[89][0-9]{10}|[0-9]{9}[0-9X])/); //13 digit or 10 digit
if(!isbn) return false;
isbn = isbn[0];
if(isbn.length == 10) {
// Verify ISBN-10 checksum
@ -292,17 +295,11 @@ Zotero.Utilities = {
return (sum % 11 == 0) ? isbn : false;
}
isbn = isbn.replace(/X/g, ''); //get rid of Xs
if(isbn.length == 13) {
// ISBN-13 should start with 978 or 979 i.e. GS1 for book publishing industry
var prefix = isbn.slice(0,3);
if (prefix != "978" && prefix != "979") return false;
// Verify checksum
var sum = 0;
for (var i = 0; i < 12; i+=2) sum += isbn[i]*1; //to make sure it's int
for (i = 1; i < 12; i+=2) sum += isbn[i]*3;
for (var i = 1; i < 12; i+=2) sum += isbn[i]*3;
sum += isbn[12]*1; //add the check digit
return (sum % 10 == 0 )? isbn : false;
@ -1112,11 +1109,11 @@ Zotero.Utilities = {
*/
"varDump":function(arr,level,maxLevel,parentObjects,path) {
var dumped_text = "";
if (!level){
if (level === undefined){
level = 0;
}
if (!maxLevel) {
if (maxLevel === undefined) {
maxLevel = 4;
}
@ -1139,7 +1136,12 @@ Zotero.Utilities = {
}
for (var item in arr) {
var value = arr[item];
try {
var value = arr[item];
} catch(e) {
dumped_text += level_padding + "'" + item + "' => <<Access Denied>>\n";
continue;
}
if (typeof(value) == 'object') { // If it is an array
//check for recursion
@ -1159,9 +1161,13 @@ Zotero.Utilities = {
dumped_text += level_padding + "'" + item + "' => " + openBrace;
//only recurse if there's anything in the object, purely cosmetical
for(var i in value) {
dumped_text += "\n" + Zotero.Utilities.varDump(value,level+1,maxLevel,parentObjects.concat([value]),path.concat([item])) + level_padding;
break;
try {
for(var i in value) {
dumped_text += "\n" + Zotero.Utilities.varDump(value,level+1,maxLevel,parentObjects.concat([value]),path.concat([item])) + level_padding;
break;
}
} catch(e) {
dumped_text += "<<Error processing object:\n" + e + ">>\n";
}
dumped_text += closeBrace + "\n";
}

View file

@ -231,15 +231,13 @@ Zotero.Utilities.Translate.prototype.processDocuments = function(urls, processor
}
if(Zotero.isFx) {
var translate = this._translate;
if(translate.document) {
var protocol = translate.document.location.protocol,
host = translate.document.location.host;
} else {
if(typeof translate._sandboxLocation === "object") {
var protocol = translate._sandboxLocation.location.protocol,
host = translate._sandboxLocation.location.host;
} else {
var url = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newURI(typeof translate._sandboxLocation === "object" ?
translate._sandboxLocation.location : translate._sandboxLocation, null, null),
.newURI(translate._sandboxLocation, null, null),
protocol = url.scheme+":",
host = url.host;
}