Move prviliged public methods to Utilities.Internal
Moving flattenArguments, setFontSize and getAncestorByTagName
This commit is contained in:
parent
caaaed0af1
commit
e9e6a8313d
3 changed files with 65 additions and 79 deletions
|
@ -1343,62 +1343,6 @@ Zotero.Utilities = {
|
|||
return strings.join(delimiter !== undefined ? delimiter : ", ");
|
||||
},
|
||||
|
||||
/*
|
||||
* Sets font size based on prefs -- intended for use on root element
|
||||
* (zotero-pane, note window, etc.)
|
||||
*/
|
||||
"setFontSize": function (rootElement) {
|
||||
var size = Zotero.Prefs.get('fontSize');
|
||||
rootElement.style.fontSize = size + 'em';
|
||||
if (size <= 1) {
|
||||
size = 'small';
|
||||
}
|
||||
else if (size <= 1.25) {
|
||||
size = 'medium';
|
||||
}
|
||||
else {
|
||||
size = 'large';
|
||||
}
|
||||
// Custom attribute -- allows for additional customizations in zotero.css
|
||||
rootElement.setAttribute('zoteroFontSize', size);
|
||||
},
|
||||
|
||||
/*
|
||||
* Flattens mixed arrays/values in a passed _arguments_ object and returns
|
||||
* an array of values -- allows for functions to accept both arrays of
|
||||
* values and/or an arbitrary number of individual values
|
||||
*/
|
||||
"flattenArguments": function (args){
|
||||
// Put passed scalar values into an array
|
||||
if (args === null || typeof args == 'string' || typeof args.length == 'undefined') {
|
||||
args = [args];
|
||||
}
|
||||
|
||||
var returns = [];
|
||||
for (var i=0; i<args.length; i++){
|
||||
var arg = args[i];
|
||||
if (!arg && arg !== 0) {
|
||||
continue;
|
||||
}
|
||||
if (Array.isArray(arg)) {
|
||||
returns.push(...arg);
|
||||
}
|
||||
else {
|
||||
returns.push(arg);
|
||||
}
|
||||
}
|
||||
return returns;
|
||||
},
|
||||
|
||||
"getAncestorByTagName": function (elem, tagName){
|
||||
while (elem.parentNode){
|
||||
elem = elem.parentNode;
|
||||
if (elem.localName == tagName) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Generate a random string of length 'len' (defaults to 8)
|
||||
|
|
|
@ -1340,7 +1340,63 @@ Zotero.Utilities.Internal = {
|
|||
newClass.prototype = Object.create(superClass.prototype);
|
||||
newClass.prototype.constructor = newClass;
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
* Flattens mixed arrays/values in a passed _arguments_ object and returns
|
||||
* an array of values -- allows for functions to accept both arrays of
|
||||
* values and/or an arbitrary number of individual values
|
||||
*/
|
||||
flattenArguments: function (args){
|
||||
// Put passed scalar values into an array
|
||||
if (args === null || typeof args == 'string' || typeof args.length == 'undefined') {
|
||||
args = [args];
|
||||
}
|
||||
|
||||
var returns = [];
|
||||
for (var i=0; i<args.length; i++){
|
||||
var arg = args[i];
|
||||
if (!arg && arg !== 0) {
|
||||
continue;
|
||||
}
|
||||
if (Array.isArray(arg)) {
|
||||
returns.push(...arg);
|
||||
}
|
||||
else {
|
||||
returns.push(arg);
|
||||
}
|
||||
}
|
||||
return returns;
|
||||
},
|
||||
|
||||
/*
|
||||
* Sets font size based on prefs -- intended for use on root element
|
||||
* (zotero-pane, note window, etc.)
|
||||
*/
|
||||
setFontSize: function (rootElement) {
|
||||
var size = Zotero.Prefs.get('fontSize');
|
||||
rootElement.style.fontSize = size + 'em';
|
||||
if (size <= 1) {
|
||||
size = 'small';
|
||||
}
|
||||
else if (size <= 1.25) {
|
||||
size = 'medium';
|
||||
}
|
||||
else {
|
||||
size = 'large';
|
||||
}
|
||||
// Custom attribute -- allows for additional customizations in zotero.css
|
||||
rootElement.setAttribute('zoteroFontSize', size);
|
||||
},
|
||||
|
||||
getAncestorByTagName: function (elem, tagName){
|
||||
while (elem.parentNode){
|
||||
elem = elem.parentNode;
|
||||
if (elem.localName == tagName) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
quitZotero: function(restart=false) {
|
||||
Zotero.debug("Zotero.Utilities.Internal.quitZotero() is deprecated -- use quit()");
|
||||
|
|
|
@ -1350,50 +1350,36 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
|
|||
return deferred.promise;
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {String} name
|
||||
* @param {String[]} [params=[]] - Strings to substitute for placeholders
|
||||
* @param {Number} [num] - Number (also appearing in `params`) to use when determining which plural
|
||||
* form of the string to use; localized strings should include all forms in the order specified
|
||||
* in https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals,
|
||||
* separated by semicolons
|
||||
*/
|
||||
this.getString = function (name, params, num) {
|
||||
return Zotero.Intl.getString(...arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* @alias Zotero.Utilities.Internal.defineProperty;
|
||||
*/
|
||||
this.defineProperty = (...args) => Zotero.Utilities.Internal.defineProperty(...args);
|
||||
|
||||
|
||||
this.extendClass = (...args) => Zotero.Utilities.Internal.extendClass(...args);
|
||||
|
||||
|
||||
this.getLocaleCollation = function () {
|
||||
return Zotero.Intl.collation;
|
||||
};
|
||||
return Zotero.Intl.collation;
|
||||
}
|
||||
|
||||
this.localeCompare = function (...args) {
|
||||
return Zotero.Intl.compare(...args);
|
||||
};
|
||||
}
|
||||
|
||||
function setFontSize(rootElement) {
|
||||
return Zotero.Utilities.setFontSize(rootElement);
|
||||
}
|
||||
|
||||
|
||||
function flattenArguments(args){
|
||||
return Zotero.Utilities.flattenArguments(args);
|
||||
return Zotero.Utilities.Internal.flattenArguments(args);
|
||||
}
|
||||
|
||||
|
||||
function getAncestorByTagName(elem, tagName){
|
||||
return Zotero.Utilities.getAncestorByTagName(elem, tagName);
|
||||
return Zotero.Utilities.Internal.getAncestorByTagName(elem, tagName);
|
||||
}
|
||||
|
||||
|
||||
function randomString(len, chars) {
|
||||
return Zotero.Utilities.randomString(len, chars);
|
||||
return Zotero.Utilities.Internal.randomString(len, chars);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue