diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 9b4e2f2a55..4990674489 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -2672,7 +2672,7 @@ Zotero.Attachments = new function(){ this._getFileNameFromURL = function(url, contentType) { - url = Zotero.Utilities.parseURL(url); + url = Zotero.Utilities.Internal.parseURL(url); var fileBaseName = url.fileBaseName; var fileExt = Zotero.MIME.getPrimaryExtension(contentType, url.fileExtension); diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index 438713baff..762130336f 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -31,7 +31,7 @@ Zotero.Collection = function(params = {}) { this._childCollections = new Set(); this._childItems = new Set(); - Zotero.Utilities.assignProps(this, params, ['name', 'libraryID', 'parentID', 'parentKey']); + Zotero.Utilities.Internal.assignProps(this, params, ['name', 'libraryID', 'parentID', 'parentKey']); } Zotero.extendClass(Zotero.DataObject, Zotero.Collection); diff --git a/chrome/content/zotero/xpcom/data/feed.js b/chrome/content/zotero/xpcom/data/feed.js index d8ee28c16f..ce01d7b8df 100644 --- a/chrome/content/zotero/xpcom/data/feed.js +++ b/chrome/content/zotero/xpcom/data/feed.js @@ -60,7 +60,7 @@ Zotero.Feed = function(params = {}) { get: function() { return this._get('_libraryFilesEditable'); } }); - Zotero.Utilities.assignProps(this, params, + Zotero.Utilities.Internal.assignProps(this, params, ['name', 'url', 'refreshInterval', 'cleanupReadAfter', 'cleanupUnreadAfter']); // Return a proxy so that we can disable the object once it's deleted diff --git a/chrome/content/zotero/xpcom/data/feedItem.js b/chrome/content/zotero/xpcom/data/feedItem.js index 4400586884..affff08a8e 100644 --- a/chrome/content/zotero/xpcom/data/feedItem.js +++ b/chrome/content/zotero/xpcom/data/feedItem.js @@ -33,7 +33,7 @@ Zotero.FeedItem = function(itemTypeOrID, params = {}) { this._feedItemReadTime = null; this._feedItemTranslatedTime = null; - Zotero.Utilities.assignProps(this, params, ['guid']); + Zotero.Utilities.Internal.assignProps(this, params, ['guid']); }; Zotero.extendClass(Zotero.Item, Zotero.FeedItem); diff --git a/chrome/content/zotero/xpcom/data/group.js b/chrome/content/zotero/xpcom/data/group.js index 3b9d8d44d7..98b250fad0 100644 --- a/chrome/content/zotero/xpcom/data/group.js +++ b/chrome/content/zotero/xpcom/data/group.js @@ -29,7 +29,7 @@ Zotero.Group = function (params = {}) { params.libraryType = 'group'; Zotero.Group._super.call(this, params); - Zotero.Utilities.assignProps(this, params, ['groupID', 'name', 'description', + Zotero.Utilities.Internal.assignProps(this, params, ['groupID', 'name', 'description', 'version']); // Return a proxy so that we can disable the object once it's deleted diff --git a/chrome/content/zotero/xpcom/data/library.js b/chrome/content/zotero/xpcom/data/library.js index 70c67242af..8d210b4055 100644 --- a/chrome/content/zotero/xpcom/data/library.js +++ b/chrome/content/zotero/xpcom/data/library.js @@ -38,7 +38,7 @@ Zotero.Library = function(params = {}) { this._hasSearches = null; this._storageDownloadNeeded = false; - Zotero.Utilities.assignProps( + Zotero.Utilities.Internal.assignProps( this, params, [ diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index 6414148c03..73d139af8f 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -36,7 +36,7 @@ Zotero.Search = function(params = {}) { this._conditions = {}; this._hasPrimaryConditions = false; - Zotero.Utilities.assignProps(this, params, ['name', 'libraryID']); + Zotero.Utilities.Internal.assignProps(this, params, ['name', 'libraryID']); } Zotero.extendClass(Zotero.DataObject, Zotero.Search); diff --git a/chrome/content/zotero/xpcom/feedReader.js b/chrome/content/zotero/xpcom/feedReader.js index 2326d7e385..ff877d804b 100644 --- a/chrome/content/zotero/xpcom/feedReader.js +++ b/chrome/content/zotero/xpcom/feedReader.js @@ -521,7 +521,7 @@ Zotero.FeedReader._getFeedItem = function (feedEntry, feedInfo) { Zotero.FeedReader._getRichText = function (feedText, field) { let domDiv = Zotero.Utilities.Internal.getDOMDocument().createElement("div"); let domFragment = feedText.createDocumentFragment(domDiv); - return Zotero.Utilities.dom2text(domFragment, field); + return Zotero.Utilities.trimInternal(domFragment.textContent); }; /* diff --git a/chrome/content/zotero/xpcom/progressWindow.js b/chrome/content/zotero/xpcom/progressWindow.js index 8805295ff8..5797725948 100644 --- a/chrome/content/zotero/xpcom/progressWindow.js +++ b/chrome/content/zotero/xpcom/progressWindow.js @@ -434,7 +434,7 @@ Zotero.ProgressWindow = function(options = {}) { var attachment = item.attachments[i]; _attachmentsMap.set(attachment, new self.ItemProgress( - Zotero.Utilities.determineAttachmentIcon(attachment), + Zotero.Utilities.Internal.determineAttachmentIcon(attachment), attachment.title, itemProgress)); } } @@ -449,7 +449,7 @@ Zotero.ProgressWindow = function(options = {}) { } else { itemProgress.setProgress(progress); if(progress === 100) { - itemProgress.setIcon(Zotero.Utilities.determineAttachmentIcon(attachment)); + itemProgress.setIcon(Zotero.Utilities.Internal.determineAttachmentIcon(attachment)); } } } diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index b7eb1e6b50..fca0502b9d 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -26,10 +26,26 @@ ***** END LICENSE BLOCK ***** */ +(function() { +if (typeof module != 'undefined') { + require('./xregexp-all'); +} + +function movedToUtilitiesInternal(fnName) { + return function () { + if (Zotero.Utilities && Zotero.Utilitie.Internal) { + Zotero.debug(`Zotero.Utilities.${fnName}() is deprecated -- use Zotero.Utilities.Internal.${fnName}() instead`); + return Zotero.Utilities.Internal[fnName].apply(Zotero.Utilities.Internal, arguments); + } else { + throw new Error(`Zotero.Utilities.${fnName}() is only available in the zotero-client codebase`) + } + } +} + /** * @class Functions for text manipulation and other miscellaneous purposes */ -Zotero.Utilities = { +var Utilities = { /** * Returns a function which will execute `fn` with provided arguments after `delay` milliseconds and not more * than once, if called multiple times. See @@ -116,11 +132,11 @@ Zotero.Utilities = { * @param {String} string Uppercase author name * @return {String} Title-cased author name */ - "capitalizeName": function (string) { + capitalizeName: function (string) { if (typeof string === "string" && string.toUpperCase() === string) { - string = Zotero.Utilities.XRegExp.replace( + string = Utilities.XRegExp.replace( string.toLowerCase(), - Zotero.Utilities.XRegExp('(^|[^\\pL])\\pL', 'g'), + Utilities.XRegExp('(^|[^\\pL])\\pL', 'g'), m => m.toUpperCase() ); } @@ -135,7 +151,7 @@ Zotero.Utilities = { * @param {Boolean} useComma Whether the creator string is in inverted (Last, First) format * @return {Object} firstName, lastName, and creatorType */ - "cleanAuthor":function(author, type, useComma) { + cleanAuthor: function(author, type, useComma) { var allCaps = 'A-Z' + '\u0400-\u042f'; //cyrilic @@ -168,7 +184,7 @@ Zotero.Utilities = { spaceIndex = author.lastIndexOf(" ", spaceIndex-1); var lastName = author.substring(spaceIndex + 1); var firstName = author.substring(0, spaceIndex); - } while (!Zotero.Utilities.XRegExp('\\pL').test(lastName[0]) && spaceIndex > 0) + } while (!Utilities.XRegExp('\\pL').test(lastName[0]) && spaceIndex > 0) } if(firstName && allCapsRe.test(firstName) && @@ -205,7 +221,7 @@ Zotero.Utilities = { * Removes leading and trailing whitespace from a string * @type String */ - "trim":function(/**String*/ s) { + trim: function(/**String*/ s) { if (typeof(s) != "string") { throw new Error("trim: argument must be a string"); } @@ -218,7 +234,7 @@ Zotero.Utilities = { * Cleans whitespace off a string and replaces multiple spaces with one * @type String */ - "trimInternal":function(/**String*/ s) { + trimInternal: function(/**String*/ s) { if (typeof(s) != "string") { throw new Error("trimInternal: argument must be a string"); } @@ -231,7 +247,7 @@ Zotero.Utilities = { * Cleans any non-word non-parenthesis characters off the ends of a string * @type String */ - "superCleanString":function(/**String*/ x) { + superCleanString: function(/**String*/ x) { if(typeof(x) != "string") { throw new Error("superCleanString: argument must be a string"); } @@ -281,7 +297,7 @@ Zotero.Utilities = { * Eliminates HTML tags, replacing <br>s with newlines * @type String */ - "cleanTags":function(/**String*/ x) { + cleanTags: function(/**String*/ x) { if(typeof(x) != "string") { throw new Error("cleanTags: argument must be a string"); } @@ -295,7 +311,7 @@ Zotero.Utilities = { * Strip info:doi prefix and any suffixes from a DOI * @type String */ - "cleanDOI":function(/**String**/ x) { + cleanDOI: function(/**String**/ x) { if(typeof(x) != "string") { throw new Error("cleanDOI: argument must be a string"); } @@ -311,7 +327,7 @@ Zotero.Utilities = { * @param {Boolean} [dontValidate=false] Do not validate check digit * @return {String|Boolean} Valid ISBN or false */ - "cleanISBN":function(isbnStr, dontValidate) { + cleanISBN: function(isbnStr, dontValidate) { isbnStr = isbnStr.toUpperCase() .replace(/[\x2D\xAD\u2010-\u2015\u2043\u2212]+/g, ''); // Ignore dashes var isbnRE = /\b(?:97[89]\s*(?:\d\s*){9}\d|(?:\d\s*){9}[\dX])\b/g, @@ -355,9 +371,9 @@ Zotero.Utilities = { * cleanISBN * @return {String} ISBN-13 */ - "toISBN13": function(isbnStr) { + toISBN13: function(isbnStr) { var isbn; - if (!(isbn = Zotero.Utilities.cleanISBN(isbnStr, true))) { + if (!(isbn = Utilities.cleanISBN(isbnStr, true))) { throw new Error('ISBN not found in "' + isbnStr + '"'); } @@ -382,7 +398,7 @@ Zotero.Utilities = { * Clean and validate ISSN. * Return issn if valid, otherwise return false */ - "cleanISSN":function(/**String*/ issnStr) { + cleanISSN: function(/**String*/ issnStr) { issnStr = issnStr.toUpperCase() .replace(/[\x2D\xAD\u2010-\u2015\u2043\u2212]+/g, ''); // Ignore dashes var issnRE = /\b(?:\d\s*){7}[\dX]\b/g, @@ -417,8 +433,8 @@ Zotero.Utilities = { * are replaced with P tags, while single newlines are replaced with BR tags. * @type String */ - "text2html":function (/**String**/ str, /**Boolean**/ singleNewlineIsParagraph) { - str = Zotero.Utilities.htmlSpecialChars(str); + text2html: function (/**String**/ str, /**Boolean**/ singleNewlineIsParagraph) { + str = Utilities.htmlSpecialChars(str); // \n =>
if (singleNewlineIsParagraph) {
@@ -447,7 +463,7 @@ Zotero.Utilities = {
* @param {String} str
* @return {String}
*/
- "htmlSpecialChars":function(str) {
+ htmlSpecialChars: function(str) {
if (str && typeof str != 'string') {
Zotero.debug('#htmlSpecialChars: non-string arguments are deprecated. Update your code',
1, undefined, true);
@@ -489,7 +505,7 @@ Zotero.Utilities = {
// Create a node and use the textContent property to do unescaping where
// possible, because this approach preserves line endings in the HTML
if(node === undefined) {
- node = Zotero.Utilities.Internal.getDOMDocument().createElement("div");
+ node = Utilities.Internal.getDOMDocument().createElement("div");
}
node.innerHTML = str;
@@ -506,27 +522,13 @@ Zotero.Utilities = {
};
},
- /**
- * Converts text inside a DOM object to plain text preserving text formatting
- * appropriate for given field
- *
- * @param {DOMNode} rootNode Node containing all the text that needs to be extracted
- * @param {String} targetField Zotero item field that the text is meant for
- *
- * @return {String} Zotero formatted string
- */
- "dom2text": function(rootNode, targetField) {
- // TODO: actually do this
- return Zotero.Utilities.trimInternal(rootNode.textContent);
- },
-
/**
* Wrap URLs and DOIs in links in plain text
*
* Ignore URLs preceded by '>', just in case there are already links
* @type String
*/
- "autoLink":function (/**String**/ str) {
+ autoLink: function (/**String**/ str) {
// "http://www.google.com."
// "http://www.google.com. "
// "