Make File.getResource expect full URLs

This change makes is easier to support different URL schemes
when overriding on other platforms.
This commit is contained in:
Sylvester Keil 2018-08-03 10:49:15 +02:00
parent 6fd25419a9
commit 07464d5c84
No known key found for this signature in database
GPG key ID: 878933BCEAB25A10
3 changed files with 19 additions and 9 deletions

View file

@ -47,7 +47,7 @@ Zotero.Date = new function(){
throw new Error("Unimplemented");
}
var json = JSON.parse(Zotero.File.getResource('schema/dateFormats.json'));
var json = JSON.parse(Zotero.File.getResource('resource://zotero/schema/dateFormats.json'));
var locale = Zotero.locale;
var english = locale.startsWith('en');
// If no exact match, try first two characters ('de')

View file

@ -339,15 +339,25 @@ Zotero.File = new function(){
return xmlhttp.responseText;
}
/*
* Returns the contents of the given local resource.
/**
* Return the contents of resource. Use this for loading
* resource/chrome URLs.
*
* @param {String} url - the resource url
* @return {String} the resource contents as a string
*/
this.getResource = function (res) {
return getContentsFromURL(`resource://zotero/${res}`);
this.getResource = function (url) {
return getContentsFromURL(url);
}
this.getResourceAsync = function (res) {
return getContentsFromURLAsync(`resource://zotero/${res}`);
/**
* Return a promise for the contents of resource.
*
* @param {String} url - the resource url
* @return {Promise<String>} the resource contents as a string
*/
this.getResourceAsync = function (url) {
return getContentsFromURLAsync(url);
}

View file

@ -574,7 +574,7 @@ Zotero.Schema = new function(){
var ModeType = Zotero.Utilities.capitalize(modeType);
var Mode = Zotero.Utilities.capitalize(mode);
var repotime = yield Zotero.File.getResourceAsync("schema/repotime.txt");
var repotime = yield Zotero.File.getResourceAsync("resource://zotero/schema/repotime.txt");
var date = Zotero.Date.sqlToDate(repotime.trim(), true);
repotime = Zotero.Date.toUnixTimestamp(date);
@ -1446,7 +1446,7 @@ Zotero.Schema = new function(){
throw ('Schema type not provided to _getSchemaSQL()');
}
return Zotero.File.getResourceAsync(`schema/${schema}.sql`);
return Zotero.File.getResourceAsync(`resource://zotero/schema/${schema}.sql`);
}