Deprecate setFontSize(), replace with new Zotero.UIProperties
This new XPCOM module handles font size and UI density and automatically keeps registered roots up to date when prefs change. Roots receive a UIPropertiesChanged event after their properties are updated.
This commit is contained in:
parent
d6e5da403c
commit
1dd3812e00
18 changed files with 116 additions and 49 deletions
|
@ -165,7 +165,7 @@ var Scaffold = new function () {
|
||||||
this.initTestsEditor();
|
this.initTestsEditor();
|
||||||
|
|
||||||
// Set font size from general pref
|
// Set font size from general pref
|
||||||
Zotero.setFontSize(document.getElementById('scaffold-pane'));
|
Zotero.UIProperties.registerRoot(document.getElementById('scaffold-pane'));
|
||||||
|
|
||||||
// Set font size of code editor
|
// Set font size of code editor
|
||||||
var size = Zotero.Prefs.get("scaffold.fontSize");
|
var size = Zotero.Prefs.get("scaffold.fontSize");
|
||||||
|
|
|
@ -45,7 +45,7 @@ var ZoteroAdvancedSearch = new function() {
|
||||||
|
|
||||||
// Set font size from pref
|
// Set font size from pref
|
||||||
var sbc = document.getElementById('zotero-search-box-container');
|
var sbc = document.getElementById('zotero-search-box-container');
|
||||||
Zotero.setFontSize(sbc);
|
Zotero.UIProperties.registerRoot(sbc);
|
||||||
|
|
||||||
_searchBox.onLibraryChange = this.onLibraryChange;
|
_searchBox.onLibraryChange = this.onLibraryChange;
|
||||||
var io = window.arguments[0];
|
var io = window.arguments[0];
|
||||||
|
|
|
@ -57,7 +57,7 @@ var Zotero_File_Interface_Bibliography = new function() {
|
||||||
// Affects bibliography.xhtml and integrationDocPrefs.xul
|
// Affects bibliography.xhtml and integrationDocPrefs.xul
|
||||||
var bibContainer = document.getElementById("zotero-bibliography-container");
|
var bibContainer = document.getElementById("zotero-bibliography-container");
|
||||||
if(bibContainer) {
|
if(bibContainer) {
|
||||||
Zotero.setFontSize(document.getElementById("zotero-bibliography-container"));
|
Zotero.UIProperties.registerRoot(document.getElementById("zotero-bibliography-container"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(window.arguments && window.arguments.length) {
|
if(window.arguments && window.arguments.length) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ function toggleAccept(enabled) {
|
||||||
function doLoad() {
|
function doLoad() {
|
||||||
// Set font size from pref
|
// Set font size from pref
|
||||||
let sbc = document.getElementById('zotero-create-parent-container');
|
let sbc = document.getElementById('zotero-create-parent-container');
|
||||||
Zotero.setFontSize(sbc);
|
Zotero.UIProperties.registerRoot(sbc);
|
||||||
|
|
||||||
io = window.arguments[0];
|
io = window.arguments[0];
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ var Zotero_File_Interface_Export = new function() {
|
||||||
this.init = function () {
|
this.init = function () {
|
||||||
// Set font size from pref
|
// Set font size from pref
|
||||||
var sbc = document.getElementById('zotero-export-options-container');
|
var sbc = document.getElementById('zotero-export-options-container');
|
||||||
Zotero.setFontSize(sbc);
|
Zotero.UIProperties.registerRoot(sbc);
|
||||||
|
|
||||||
var addedOptions = new Object();
|
var addedOptions = new Object();
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ Zotero.HardConfirmationDialog = {
|
||||||
|
|
||||||
this.io = window.arguments[0];
|
this.io = window.arguments[0];
|
||||||
|
|
||||||
Zotero.setFontSize(document.documentElement);
|
Zotero.UIProperties.registerRoot(document.documentElement);
|
||||||
var dialog = document.getElementById('commonDialog');
|
var dialog = document.getElementById('commonDialog');
|
||||||
var vbox = document.getElementById('infoContainer');
|
var vbox = document.getElementById('infoContainer');
|
||||||
var sep = vbox.firstChild;
|
var sep = vbox.firstChild;
|
||||||
|
|
|
@ -44,7 +44,7 @@ Zotero_Ingester_Interface_SelectItems.init = function () {
|
||||||
|
|
||||||
// Set font size from pref
|
// Set font size from pref
|
||||||
var sbc = document.getElementById('zotero-select-items-container');
|
var sbc = document.getElementById('zotero-select-items-container');
|
||||||
Zotero.setFontSize(sbc);
|
Zotero.UIProperties.registerRoot(sbc);
|
||||||
|
|
||||||
this.io = window.arguments[0];
|
this.io = window.arguments[0];
|
||||||
var listbox = document.getElementById("zotero-selectitems-links");
|
var listbox = document.getElementById("zotero-selectitems-links");
|
||||||
|
|
|
@ -48,7 +48,7 @@ var Zotero_Merge_Window = new function () {
|
||||||
_wizard.addEventListener('wizardfinish', this.onFinish.bind(this));
|
_wizard.addEventListener('wizardfinish', this.onFinish.bind(this));
|
||||||
|
|
||||||
// Set font size from pref
|
// Set font size from pref
|
||||||
Zotero.setFontSize(_wizardPage);
|
Zotero.UIProperties.registerRoot(_wizardPage);
|
||||||
|
|
||||||
_wizard.getButton('cancel').setAttribute('label', Zotero.getString('sync.cancel'));
|
_wizard.getButton('cancel').setAttribute('label', Zotero.getString('sync.cancel'));
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ async function onLoad() {
|
||||||
noteEditor.viewMode = 'window';
|
noteEditor.viewMode = 'window';
|
||||||
|
|
||||||
// Set font size from pref
|
// Set font size from pref
|
||||||
Zotero.setFontSize(noteEditor);
|
Zotero.UIProperties.registerRoot(noteEditor);
|
||||||
|
|
||||||
if (itemID) {
|
if (itemID) {
|
||||||
var ref = await Zotero.Items.getAsync(itemID);
|
var ref = await Zotero.Items.getAsync(itemID);
|
||||||
|
|
|
@ -33,7 +33,7 @@ function doLoad()
|
||||||
{
|
{
|
||||||
// Set font size from pref
|
// Set font size from pref
|
||||||
var sbc = document.getElementById('zotero-search-box-container');
|
var sbc = document.getElementById('zotero-search-box-container');
|
||||||
Zotero.setFontSize(sbc);
|
Zotero.UIProperties.registerRoot(sbc);
|
||||||
|
|
||||||
io = window.arguments[0];
|
io = window.arguments[0];
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ const isAddEditItemsDialog = !!document.querySelector('#zotero-add-citation-dial
|
||||||
var doLoad = async function () {
|
var doLoad = async function () {
|
||||||
// Set font size from pref
|
// Set font size from pref
|
||||||
var sbc = document.getElementById('zotero-select-items-container');
|
var sbc = document.getElementById('zotero-select-items-container');
|
||||||
Zotero.setFontSize(sbc);
|
Zotero.UIProperties.registerRoot(sbc);
|
||||||
|
|
||||||
io = window.arguments[0];
|
io = window.arguments[0];
|
||||||
if(io.wrappedJSObject) io = io.wrappedJSObject;
|
if(io.wrappedJSObject) io = io.wrappedJSObject;
|
||||||
|
|
|
@ -37,7 +37,7 @@ var Zotero_Tag_Color_Chooser = new function() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Set font size from pref
|
// Set font size from pref
|
||||||
Zotero.setFontSize(document.getElementById("tag-color-chooser-container"));
|
Zotero.UIProperties.registerRoot(document.getElementById("tag-color-chooser-container"));
|
||||||
|
|
||||||
if (window.arguments && window.arguments.length) {
|
if (window.arguments && window.arguments.length) {
|
||||||
_io = window.arguments[0];
|
_io = window.arguments[0];
|
||||||
|
|
|
@ -268,13 +268,11 @@ Zotero.Prefs = new function() {
|
||||||
Zotero.Schema.stopRepositoryTimer();
|
Zotero.Schema.stopRepositoryTimer();
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
["fontSize", function (val) {
|
["fontSize", function () {
|
||||||
Zotero.setFontSize(
|
Zotero.UIProperties.setAll();
|
||||||
Zotero.getActiveZoteroPane().document.getElementById('zotero-pane')
|
}],
|
||||||
);
|
["uiDensity", function () {
|
||||||
Zotero.setFontSize(Zotero.getActiveZoteroPane().document.getElementById('zotero-context-pane'));
|
Zotero.UIProperties.setAll();
|
||||||
Zotero.getActiveZoteroPane().collectionsView && Zotero.getActiveZoteroPane().collectionsView.updateFontSize();
|
|
||||||
Zotero.getActiveZoteroPane().itemsView && Zotero.getActiveZoteroPane().itemsView.updateFontSize();
|
|
||||||
}],
|
}],
|
||||||
["recursiveCollections", function() {
|
["recursiveCollections", function() {
|
||||||
Zotero.getActiveZoteroPane().itemsView.refreshAndMaintainSelection();
|
Zotero.getActiveZoteroPane().itemsView.refreshAndMaintainSelection();
|
||||||
|
|
|
@ -84,7 +84,7 @@ Zotero.ProgressQueueDialog = function (progressQueue) {
|
||||||
|
|
||||||
function _onWindowLoaded() {
|
function _onWindowLoaded() {
|
||||||
var rootElement = _progressWindow.document.getElementById('zotero-progress-box');
|
var rootElement = _progressWindow.document.getElementById('zotero-progress-box');
|
||||||
Zotero.setFontSize(rootElement);
|
Zotero.UIProperties.registerRoot(rootElement);
|
||||||
|
|
||||||
_progressIndicator = _progressWindow.document.getElementById('progress-indicator');
|
_progressIndicator = _progressWindow.document.getElementById('progress-indicator');
|
||||||
_progressWindow.document.getElementById('cancel-button')
|
_progressWindow.document.getElementById('cancel-button')
|
||||||
|
|
85
chrome/content/zotero/xpcom/uiProperties.js
Normal file
85
chrome/content/zotero/xpcom/uiProperties.js
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
***** BEGIN LICENSE BLOCK *****
|
||||||
|
|
||||||
|
Copyright © 2023 Corporation for Digital Scholarship
|
||||||
|
Vienna, Virginia, USA
|
||||||
|
https://www.zotero.org
|
||||||
|
|
||||||
|
This file is part of Zotero.
|
||||||
|
|
||||||
|
Zotero is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Zotero is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
***** END LICENSE BLOCK *****
|
||||||
|
*/
|
||||||
|
|
||||||
|
Zotero.UIProperties = new class {
|
||||||
|
_roots = new Set();
|
||||||
|
|
||||||
|
registerRoot(root) {
|
||||||
|
if (root.nodeType !== Node.ELEMENT_NODE) {
|
||||||
|
throw new Error('Root must be an element');
|
||||||
|
}
|
||||||
|
|
||||||
|
this._roots.add(new WeakRef(root));
|
||||||
|
this.set(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
setAll() {
|
||||||
|
for (let rootRef of this._roots) {
|
||||||
|
let root = rootRef.deref();
|
||||||
|
if (!root) {
|
||||||
|
this._roots.delete(rootRef);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
this.set(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set(root) {
|
||||||
|
this._setFontSize(root);
|
||||||
|
this._setUIDensity(root);
|
||||||
|
root.dispatchEvent(new Event('UIPropertiesChanged', { bubbles: false }));
|
||||||
|
}
|
||||||
|
|
||||||
|
_setFontSize(root) {
|
||||||
|
let size = Zotero.Prefs.get('fontSize');
|
||||||
|
root.style.fontSize = root.style['--zotero-font-size'] = size + 'em';
|
||||||
|
if (size <= 1) {
|
||||||
|
size = 'small';
|
||||||
|
}
|
||||||
|
else if (size <= 1.15) {
|
||||||
|
size = 'medium';
|
||||||
|
}
|
||||||
|
else if (size <= 1.3) {
|
||||||
|
size = 'large';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
size = 'x-large';
|
||||||
|
}
|
||||||
|
// Custom attribute -- allows for additional customizations in zotero.css
|
||||||
|
root.setAttribute('zoteroFontSize', size);
|
||||||
|
if (Zotero.rtl) {
|
||||||
|
root.setAttribute('dir', 'rtl');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
root.removeAttribute('dir');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_setUIDensity(root) {
|
||||||
|
let density = Zotero.Prefs.get('uiDensity');
|
||||||
|
root.style.setProperty('--zotero-ui-density', density);
|
||||||
|
root.setAttribute('zoteroUIDensity', density);
|
||||||
|
}
|
||||||
|
};
|
|
@ -1876,30 +1876,9 @@ Zotero.Utilities.Internal = {
|
||||||
return returns;
|
return returns;
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
|
||||||
* Sets font size based on prefs -- intended for use on root element
|
|
||||||
* (zotero-pane, note window, etc.)
|
|
||||||
*/
|
|
||||||
setFontSize: function (rootElement) {
|
setFontSize: function (rootElement) {
|
||||||
var size = Zotero.Prefs.get('fontSize');
|
Zotero.debug("setFontSize() is deprecated -- use Zotero.UIProperties");
|
||||||
rootElement.style.fontSize = rootElement.style['--zotero-font-size'] = size + 'em';
|
Zotero.UIProperties.set(rootElement);
|
||||||
if (size <= 1) {
|
|
||||||
size = 'small';
|
|
||||||
}
|
|
||||||
else if (size <= 1.15) {
|
|
||||||
size = 'medium';
|
|
||||||
}
|
|
||||||
else if (size <= 1.3) {
|
|
||||||
size = 'large';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
size = 'x-large';
|
|
||||||
}
|
|
||||||
// Custom attribute -- allows for additional customizations in zotero.css
|
|
||||||
rootElement.setAttribute('zoteroFontSize', size);
|
|
||||||
if (Zotero.rtl) {
|
|
||||||
rootElement.setAttribute('dir', 'rtl');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getAncestorByTagName: function (elem, tagName){
|
getAncestorByTagName: function (elem, tagName){
|
||||||
|
|
|
@ -103,8 +103,12 @@ var ZoteroPane = new function()
|
||||||
_loaded = true;
|
_loaded = true;
|
||||||
|
|
||||||
var zp = document.getElementById('zotero-pane');
|
var zp = document.getElementById('zotero-pane');
|
||||||
Zotero.setFontSize(zp);
|
Zotero.UIProperties.registerRoot(zp);
|
||||||
Zotero.setFontSize(document.getElementById('zotero-context-pane'));
|
zp.addEventListener('UIPropertiesChanged', () => {
|
||||||
|
this.collectionsView?.updateFontSize();
|
||||||
|
this.itemsView?.updateFontSize();
|
||||||
|
});
|
||||||
|
Zotero.UIProperties.registerRoot(document.getElementById('zotero-context-pane'));
|
||||||
ZoteroPane_Local.updateLayout();
|
ZoteroPane_Local.updateLayout();
|
||||||
ZoteroPane_Local.updateToolbarPosition();
|
ZoteroPane_Local.updateToolbarPosition();
|
||||||
this.updateWindow();
|
this.updateWindow();
|
||||||
|
|
|
@ -63,6 +63,7 @@ const xpcomFilesAll = [
|
||||||
'translation/translate_firefox',
|
'translation/translate_firefox',
|
||||||
'isbn',
|
'isbn',
|
||||||
'preferencePanes',
|
'preferencePanes',
|
||||||
|
'uiProperties',
|
||||||
];
|
];
|
||||||
|
|
||||||
/** XPCOM files to be loaded only for local translation and DB access **/
|
/** XPCOM files to be loaded only for local translation and DB access **/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue