Merge branch '3.0'
This commit is contained in:
commit
575fd30e62
8 changed files with 132 additions and 73 deletions
|
@ -79,7 +79,7 @@ Zotero_TranslatorTesters = new function() {
|
|||
};
|
||||
} else {
|
||||
strcmp = function (a, b) {
|
||||
return a.localeCompare(b);
|
||||
return a.toLowerCase().localeCompare(b.toLowerCase());
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -213,12 +213,35 @@ Zotero_TranslatorTester._sanitizeItem = function(item, forSave) {
|
|||
item = JSON.parse(JSON.stringify(item));
|
||||
} catch(e) {};
|
||||
|
||||
// remove fields to be ignored
|
||||
const IGNORE_FIELDS = ["complete", "accessDate", "checkFields"];
|
||||
for(var j=0, n=IGNORE_FIELDS.length; j<n; j++) {
|
||||
delete item[IGNORE_FIELDS[j]];
|
||||
// remove fields that don't exist or aren't valid for this item type, and normalize base fields
|
||||
// to fields specific to this item
|
||||
var fieldID, itemFieldID,
|
||||
typeID = Zotero.ItemTypes.getID(item.itemType);
|
||||
const skipFields = ["note", "notes", "itemID", "attachments", "tags", "seeAlso",
|
||||
"itemType", "complete", "creators"];
|
||||
for(var field in item) {
|
||||
if(skipFields.indexOf(field) !== -1) continue;
|
||||
|
||||
if(!item[field] || !(fieldID = Zotero.ItemFields.getID(field))) {
|
||||
delete item[field];
|
||||
continue;
|
||||
}
|
||||
|
||||
if(itemFieldID = Zotero.ItemFields.getFieldIDFromTypeAndBase(typeID, fieldID)) {
|
||||
var value = item[field];
|
||||
delete item[field];
|
||||
item[Zotero.ItemFields.getName(itemFieldID)] = value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!Zotero.ItemFields.isValidForType(fieldID, typeID)) {
|
||||
delete item[field];
|
||||
}
|
||||
}
|
||||
|
||||
// remove fields to be ignored
|
||||
if("accessDate" in item) delete item.accessDate;
|
||||
|
||||
return item;
|
||||
};
|
||||
/**
|
||||
|
|
|
@ -130,7 +130,8 @@ Zotero.Connector_Types = new function() {
|
|||
// mimics itemFields.js
|
||||
if(!field || !itemType) return false;
|
||||
|
||||
return itemType[4]/* fields */.indexOf(field[0]/* id */) !== -1;
|
||||
/* fields */ /* id */
|
||||
return itemType[4].indexOf(field[0]) !== -1;
|
||||
};
|
||||
|
||||
this.getFieldIDFromTypeAndBase = function(typeIdOrName, fieldIdOrName) {
|
||||
|
|
|
@ -662,73 +662,47 @@ Zotero.Date = new function(){
|
|||
}
|
||||
|
||||
/**
|
||||
* Figure out the date order from the output of toLocaleDateString()
|
||||
* Get the order of the date components based on the current locale
|
||||
*
|
||||
* Returns a string with y, m, and d (e.g. 'ymd', 'mdy')
|
||||
*/
|
||||
function getLocaleDateOrder(){
|
||||
if (_localeDateOrder) {
|
||||
return _localeDateOrder;
|
||||
if (!_localeDateOrder) {
|
||||
switch (Zotero.locale.substr(-2)) {
|
||||
// middle-endian
|
||||
case 'US': // The United States
|
||||
case 'BZ': // Belize
|
||||
case 'FM': // The Federated States of Micronesia
|
||||
case 'PA': // Panama
|
||||
case 'PH': // The Philippines
|
||||
case 'PW': // Palau
|
||||
case 'ZW': // Zimbabwe
|
||||
_localeDateOrder = 'mdy';
|
||||
break;
|
||||
|
||||
// big-endian
|
||||
case 'fa': // Persian
|
||||
case 'AL': // Albania
|
||||
case 'CA': // Canada
|
||||
case 'CN': // China
|
||||
case 'HU': // Hungary
|
||||
case 'JP': // Japan
|
||||
case 'KE': // Kenya
|
||||
case 'KR': // Korea
|
||||
case 'LT': // Lithuania
|
||||
case 'LV': // Latvia
|
||||
case 'MN': // Mongolia
|
||||
case 'SE': // Sweden
|
||||
case 'TW': // Taiwan
|
||||
case 'ZA': // South Africa
|
||||
_localeDateOrder = 'ymd';
|
||||
break;
|
||||
|
||||
// little-endian
|
||||
default:
|
||||
_localeDateOrder = 'dmy';
|
||||
}
|
||||
}
|
||||
|
||||
var date = new Date("October 5, 2006");
|
||||
var parts = date.toLocaleDateString().match(/([0-9]+)[^0-9]+([0-9]+)[^0-9]+([0-9]+)/);
|
||||
|
||||
// The above only works on OS X and Linux,
|
||||
// where toLocaleDateString() produces "10/05/2006"
|
||||
if (!parts) {
|
||||
var country = Zotero.locale.substr(3);
|
||||
switch (country) {
|
||||
// I don't know where this country list came from, but these
|
||||
// are little-endian in Zotero.strToDate()
|
||||
case 'US': // The United States
|
||||
case 'FM': // The Federated States of Micronesia
|
||||
case 'PW': // Palau
|
||||
case 'PH': // The Philippines
|
||||
return 'mdy';
|
||||
break;
|
||||
|
||||
default:
|
||||
return 'dmy';
|
||||
}
|
||||
}
|
||||
|
||||
switch (parseInt(parts[1])){
|
||||
case 2006:
|
||||
var order = 'y';
|
||||
break;
|
||||
case 10:
|
||||
var order = 'm';
|
||||
break;
|
||||
case 5:
|
||||
var order = 'd';
|
||||
break;
|
||||
}
|
||||
switch (parseInt(parts[2])){
|
||||
case 2006:
|
||||
order += 'y';
|
||||
break;
|
||||
case 10:
|
||||
order += 'm';
|
||||
break;
|
||||
case 5:
|
||||
order += 'd';
|
||||
break;
|
||||
}
|
||||
switch (parseInt(parts[3])){
|
||||
case 2006:
|
||||
order += 'y';
|
||||
break;
|
||||
case 10:
|
||||
order += 'm';
|
||||
break;
|
||||
case 5:
|
||||
order += 'd';
|
||||
break;
|
||||
}
|
||||
|
||||
_localeDateOrder = order;
|
||||
|
||||
return order;
|
||||
return _localeDateOrder;
|
||||
}
|
||||
}
|
|
@ -469,6 +469,11 @@ Zotero.HTTP = new function() {
|
|||
* @return {browser} Hidden browser used for loading
|
||||
*/
|
||||
this.processDocuments = function(urls, processor, done, exception, dontDelete, cookieSandbox) {
|
||||
// (Approximately) how many seconds to wait if the document is left in the loading state and
|
||||
// pageshow is called before we call pageshow with an incomplete document
|
||||
const LOADING_STATE_TIMEOUT = 120;
|
||||
|
||||
var firedLoadEvent;
|
||||
/**
|
||||
* Removes event listener for the load event and deletes the hidden browser
|
||||
*/
|
||||
|
@ -484,6 +489,7 @@ Zotero.HTTP = new function() {
|
|||
var doLoad = function() {
|
||||
if(urls.length) {
|
||||
var url = urls.shift();
|
||||
firedLoadEvent = 0;
|
||||
try {
|
||||
Zotero.debug("loading "+url);
|
||||
hiddenBrowser.loadURI(url);
|
||||
|
@ -509,7 +515,13 @@ Zotero.HTTP = new function() {
|
|||
var onLoad = function() {
|
||||
var doc = hiddenBrowser.contentDocument,
|
||||
url = doc.location.href.toString();
|
||||
if(url == "about:blank" || doc.readyState === "loading") return;
|
||||
if(url == "about:blank") return;
|
||||
if(doc.readyState === "loading" && firedLoadEvent < 120) {
|
||||
// Try again in a second
|
||||
firedLoadEvent++;
|
||||
Zotero.setTimeout(onLoad, 1000);
|
||||
return;
|
||||
}
|
||||
if(url !== prevUrl) { // Just in case it fires too many times
|
||||
prevUrl = url;
|
||||
try {
|
||||
|
|
|
@ -761,6 +761,18 @@ Zotero.ItemTreeView.prototype.getCellText = function(row, column)
|
|||
case 'zotero-items-column-accessDate':
|
||||
if (val) {
|
||||
var order = Zotero.Date.getLocaleDateOrder();
|
||||
if (order == 'mdy') {
|
||||
order = 'mdy';
|
||||
var join = '/';
|
||||
}
|
||||
else if (order == 'dmy') {
|
||||
order = 'dmy';
|
||||
var join = '.';
|
||||
}
|
||||
else if (order == 'ymd') {
|
||||
order = 'YMD';
|
||||
var join = '-';
|
||||
}
|
||||
var date = Zotero.Date.sqlToDate(val, true);
|
||||
var parts = [];
|
||||
for (var i=0; i<3; i++) {
|
||||
|
@ -769,16 +781,28 @@ Zotero.ItemTreeView.prototype.getCellText = function(row, column)
|
|||
parts.push(date.getFullYear().toString().substr(2));
|
||||
break;
|
||||
|
||||
case 'Y':
|
||||
parts.push(date.getFullYear());
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
parts.push((date.getMonth() + 1));
|
||||
break;
|
||||
|
||||
|
||||
case 'M':
|
||||
parts.push(Zotero.Utilities.lpad((date.getMonth() + 1).toString(), '0', 2));
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
parts.push(date.getDate());
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
parts.push(Zotero.Utilities.lpad(date.getDate().toString(), '0', 2));
|
||||
break;
|
||||
}
|
||||
|
||||
val = parts.join('/');
|
||||
val = parts.join(join);
|
||||
val += ' ' + date.toLocaleTimeString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1296,6 +1296,7 @@ Zotero.Sync.Storage = new function () {
|
|||
Components.utils.reportError(msg + " in " + funcName);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
destFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0644);
|
||||
}
|
||||
|
@ -1419,6 +1420,20 @@ Zotero.Sync.Storage = new function () {
|
|||
}
|
||||
catch (e) {
|
||||
Zotero.debug(destFile.path);
|
||||
|
||||
// For advertising junk files, ignore a bug on Windows where
|
||||
// destFile.create() works but zipReader.extract() doesn't
|
||||
// when the path length is close to 255.
|
||||
if (destFile.leafName.match(/[a-zA-Z0-9]{130,}/)) {
|
||||
var msg = "Ignoring error extracting '" + destFile.path + "'";
|
||||
Zotero.debug(msg, 2);
|
||||
Zotero.debug(e, 2);
|
||||
Components.utils.reportError(msg + " in " + funcName);
|
||||
continue;
|
||||
}
|
||||
|
||||
zipReader.close();
|
||||
|
||||
Zotero.File.checkFileAccessError(e, destFile, 'create');
|
||||
}
|
||||
|
||||
|
|
|
@ -1421,7 +1421,13 @@ Zotero.Translate.Web.prototype._getTranslatorsGetPotentialTranslators = function
|
|||
* Bind sandbox to document being translated
|
||||
*/
|
||||
Zotero.Translate.Web.prototype._getSandboxLocation = function() {
|
||||
return ("defaultView" in this.document ? this.document.defaultView : this.document.location.toString());
|
||||
if(this._parentTranslator) {
|
||||
return this._parentTranslator._sandboxLocation;
|
||||
} else if("defaultView" in this.document) {
|
||||
return this.document.defaultView;
|
||||
} else {
|
||||
return this.document.location.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -310,6 +310,10 @@ Zotero.Translate.ItemSaver.prototype = {
|
|||
|| downloadAssociatedFiles;
|
||||
if(!shouldAttach) return;
|
||||
|
||||
if(attachment.document && "__wrappedDOMObject" in attachment.document) {
|
||||
attachment.document = attachment.document.__wrappedDOMObject;
|
||||
}
|
||||
|
||||
if(attachment.snapshot === false || !this._saveFiles) {
|
||||
// if snapshot is explicitly set to false, attach as link
|
||||
if(attachment.document) {
|
||||
|
|
Loading…
Reference in a new issue