fx-compat: Correct create[XUL]Element[NS]() calls

This fixes the dictionary manager and various other places where a XUL
element was being created with createElement(), and also simplifies a lot
of createElementNS(HTML_NS, ...) calls.

This might cause some minor regressions but everything tested has
worked. Not touching preferences (#2659) or bindings.
This commit is contained in:
Abe Jellinek 2022-06-29 10:16:49 -04:00
parent 8b7d959781
commit f81b4b071f
26 changed files with 103 additions and 110 deletions

View file

@ -124,7 +124,7 @@ var Scaffold = new function () {
var primaryTypes = ['book', 'bookSection', 'conferencePaper', 'journalArticle', 'magazineArticle', 'newspaperArticle']; var primaryTypes = ['book', 'bookSection', 'conferencePaper', 'journalArticle', 'magazineArticle', 'newspaperArticle'];
for (let type of types) { for (let type of types) {
if (primaryTypes.includes(type)) continue; if (primaryTypes.includes(type)) continue;
var menuitem = document.createElement('menuitem'); var menuitem = document.createXULElement('menuitem');
menuitem.setAttribute('label', type); menuitem.setAttribute('label', type);
menuitem.addEventListener('command', () => { menuitem.addEventListener('command', () => {
Scaffold.addTemplate('templateNewItem', type); Scaffold.addTemplate('templateNewItem', type);

View file

@ -223,7 +223,7 @@ var CollectionTree = class CollectionTree extends LibraryTree {
const treeRow = this.getRow(index); const treeRow = this.getRow(index);
// Div creation and content // Div creation and content
let div = oldDiv || document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); let div = oldDiv || document.createElement('div');
div.innerHTML = ""; div.innerHTML = "";
// Classes // Classes
@ -245,13 +245,13 @@ var CollectionTree = class CollectionTree extends LibraryTree {
div.style.paddingInlineStart = (CHILD_INDENT * depth) + 'px'; div.style.paddingInlineStart = (CHILD_INDENT * depth) + 'px';
// Create a single-cell for the row (for the single-column layout) // Create a single-cell for the row (for the single-column layout)
let cell = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); let cell = document.createElement('span');
cell.className = "cell label primary"; cell.className = "cell label primary";
// Twisty/spacer // Twisty/spacer
let twisty; let twisty;
if (this.isContainerEmpty(index)) { if (this.isContainerEmpty(index)) {
twisty = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); twisty = document.createElement('span');
if (Zotero.isMac && treeRow.isHeader()) { if (Zotero.isMac && treeRow.isHeader()) {
twisty.classList.add("spacer-header"); twisty.classList.add("spacer-header");
} }
@ -275,14 +275,14 @@ var CollectionTree = class CollectionTree extends LibraryTree {
icon.classList.add('cell-icon'); icon.classList.add('cell-icon');
// Label // Label
let label = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); let label = document.createElement('span');
label.innerText = treeRow.getName(); label.innerText = treeRow.getName();
label.className = 'cell-text'; label.className = 'cell-text';
// Editing input // Editing input
div.classList.toggle('editing', treeRow == this._editing); div.classList.toggle('editing', treeRow == this._editing);
if (treeRow == this._editing) { if (treeRow == this._editing) {
label = document.createElementNS("http://www.w3.org/1999/xhtml", 'input'); label = document.createElement('input');
label.className = 'cell-text'; label.className = 'cell-text';
label.setAttribute("size", 5); label.setAttribute("size", 5);
label.value = treeRow.editingName; label.value = treeRow.editingName;
@ -2116,12 +2116,12 @@ var CollectionTree = class CollectionTree extends LibraryTree {
iconClsName = iconClsName || "IconTreesource" + collectionType; iconClsName = iconClsName || "IconTreesource" + collectionType;
if (collectionType == 'Separator') { if (collectionType == 'Separator') {
return document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); return document.createElement('span');
} }
var icon = getDOMIcon(iconClsName); var icon = getDOMIcon(iconClsName);
if (!icon) { if (!icon) {
return document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); return document.createElement('span');
} }
return icon; return icon;
} }

View file

@ -211,7 +211,7 @@ module.exports.getDOMElement = function (icon) {
Zotero.debug(`Attempting to get non-existant icon ${icon}`); Zotero.debug(`Attempting to get non-existant icon ${icon}`);
return ""; return "";
} }
let div = document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); let div = document.createElement('div');
div.innerHTML = renderToStaticMarkup(React.createElement(module.exports[icon])); div.innerHTML = renderToStaticMarkup(React.createElement(module.exports[icon]));
domElementCache[icon] = div.firstChild; domElementCache[icon] = div.firstChild;
return domElementCache[icon].cloneNode(true); return domElementCache[icon].cloneNode(true);

View file

@ -41,7 +41,7 @@ function getImageByStatus(status) {
else if (status === Zotero.ProgressQueue.ROW_SUCCEEDED) { else if (status === Zotero.ProgressQueue.ROW_SUCCEEDED) {
return getDOMElement('IconTick'); return getDOMElement('IconTick');
} }
return document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); return document.createElement('span');
} }
const ProgressQueueTable = ({ onActivate = noop, progressQueue }) => { const ProgressQueueTable = ({ onActivate = noop, progressQueue }) => {
@ -59,7 +59,7 @@ const ProgressQueueTable = ({ onActivate = noop, progressQueue }) => {
div.innerHTML = ""; div.innerHTML = "";
} }
else { else {
div = document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); div = document.createElement('div');
div.className = "row"; div.className = "row";
} }
@ -67,7 +67,7 @@ const ProgressQueueTable = ({ onActivate = noop, progressQueue }) => {
for (let column of columns) { for (let column of columns) {
if (column.dataKey === 'success') { if (column.dataKey === 'success') {
let span = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); let span = document.createElement('span');
span.className = `cell icon ${column.className}`; span.className = `cell icon ${column.className}`;
span.appendChild(getImageByStatus(row.status)); span.appendChild(getImageByStatus(row.status));
div.appendChild(span); div.appendChild(span);

View file

@ -1009,7 +1009,7 @@ class VirtualizedTable extends React.Component {
xulElem.setAttribute('tooltip', 'html-tooltip'); xulElem.setAttribute('tooltip', 'html-tooltip');
} }
if (document.querySelector('tooltip#html-tooltip')) return; if (document.querySelector('tooltip#html-tooltip')) return;
let tooltip = document.createElement('tooltip'); let tooltip = document.createXULElement('tooltip');
tooltip.id = 'html-tooltip'; tooltip.id = 'html-tooltip';
tooltip.addEventListener('popupshowing', function(e) { tooltip.addEventListener('popupshowing', function(e) {
let tooltipTitleNode = document.tooltipNode.closest('div *[title], iframe *[title], browser *[title]'); let tooltipTitleNode = document.tooltipNode.closest('div *[title], iframe *[title], browser *[title]');
@ -1019,7 +1019,13 @@ class VirtualizedTable extends React.Component {
} }
e.preventDefault(); e.preventDefault();
}); });
document.documentElement.appendChild(tooltip);
let popupset = document.querySelector('popupset');
if (!popupset) {
popupset = document.createXULElement('popupset');
document.documentElement.appendChild(popupset);
}
popupset.appendChild(tooltip);
} }
_setAlternatingRows() { _setAlternatingRows() {
@ -1246,7 +1252,7 @@ class VirtualizedTable extends React.Component {
} }
_getRenderedTextHeight() { _getRenderedTextHeight() {
let div = document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); let div = document.createElement('div');
div.style.visibility = "hidden"; div.style.visibility = "hidden";
div.textContent = "Zotero"; div.textContent = "Zotero";
document.documentElement.appendChild(div); document.documentElement.appendChild(div);
@ -1419,7 +1425,7 @@ var Columns = class {
this._columnStyleMap[column.dataKey] = ruleIndex; this._columnStyleMap[column.dataKey] = ruleIndex;
} }
} else { } else {
this._stylesheet = document.createElementNS("http://www.w3.org/1999/xhtml", 'style'); this._stylesheet = document.createElement('style');
this._stylesheet.className = stylesheetClass; this._stylesheet.className = stylesheetClass;
document.children[0].appendChild(this._stylesheet); document.children[0].appendChild(this._stylesheet);
this._columnStyleMap = {}; this._columnStyleMap = {};
@ -1579,14 +1585,14 @@ var Columns = class {
}; };
function renderCell(index, data, column) { function renderCell(index, data, column) {
let span = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); let span = document.createElement('span');
span.className = `cell ${column.className}`; span.className = `cell ${column.className}`;
span.innerText = data; span.innerText = data;
return span; return span;
} }
function renderCheckboxCell(index, data, column) { function renderCheckboxCell(index, data, column) {
let span = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); let span = document.createElement('span');
span.className = `cell checkbox ${column.className}`; span.className = `cell checkbox ${column.className}`;
span.setAttribute('role', 'checkbox'); span.setAttribute('role', 'checkbox');
span.setAttribute('aria-checked', data); span.setAttribute('aria-checked', data);
@ -1604,7 +1610,7 @@ function makeRowRenderer(getRowData) {
div.innerHTML = ""; div.innerHTML = "";
} }
else { else {
div = document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); div = document.createElement('div');
div.className = "row"; div.className = "row";
} }

View file

@ -68,7 +68,7 @@ module.exports = class {
*/ */
initialize() { initialize() {
const { targetElement } = this; const { targetElement } = this;
this.innerElem = document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); this.innerElem = document.createElement('div');
this.innerElem.className = "windowed-list"; this.innerElem.className = "windowed-list";
targetElement.appendChild(this.innerElem); targetElement.appendChild(this.innerElem);

View file

@ -345,7 +345,7 @@ Zotero.TagSelector = class TagSelectorContainer extends React.PureComponent {
} }
getFontInfo() { getFontInfo() {
var elem = document.createElementNS("http://www.w3.org/1999/xhtml", "div"); var elem = document.createElement("div");
elem.className = 'tag-selector-item'; elem.className = 'tag-selector-item';
elem.style.position = 'absolute'; elem.style.position = 'absolute';
elem.style.opacity = 0; elem.style.opacity = 0;
@ -381,7 +381,7 @@ Zotero.TagSelector = class TagSelectorContainer extends React.PureComponent {
*/ */
getTextWidth(text, font) { getTextWidth(text, font) {
// re-use canvas object for better performance // re-use canvas object for better performance
var canvas = this.canvas || (this.canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas")); var canvas = this.canvas || (this.canvas = document.createElement("canvas"));
var context = canvas.getContext("2d"); var context = canvas.getContext("2d");
context.font = font; context.font = font;
// Add a little more to make sure we don't crop // Add a little more to make sure we don't crop

View file

@ -30,8 +30,6 @@ var ReactDOM = require('react-dom');
var NotesList = require('components/itemPane/notesList').default; var NotesList = require('components/itemPane/notesList').default;
var ZoteroContextPane = new function () { var ZoteroContextPane = new function () {
const HTML_NS = 'http://www.w3.org/1999/xhtml';
var _tabCover; var _tabCover;
var _contextPane; var _contextPane;
var _contextPaneInner; var _contextPaneInner;
@ -489,7 +487,7 @@ var ZoteroContextPane = new function () {
var listBox = document.createXULElement('vbox'); var listBox = document.createXULElement('vbox');
listBox.style.display = 'flex'; listBox.style.display = 'flex';
listBox.setAttribute('flex', '1'); listBox.setAttribute('flex', '1');
var listInner = document.createElementNS(HTML_NS, 'div'); var listInner = document.createElement('div');
listInner.className = 'notes-list-container'; listInner.className = 'notes-list-container';
// Otherwise it can be focused with tab // Otherwise it can be focused with tab
listInner.tabIndex = -1; listInner.tabIndex = -1;
@ -742,11 +740,11 @@ var ZoteroContextPane = new function () {
node.querySelector('.zotero-context-pane-editor-parent-line').innerHTML = ''; node.querySelector('.zotero-context-pane-editor-parent-line').innerHTML = '';
var parentItem = item.parentItem; var parentItem = item.parentItem;
if (parentItem) { if (parentItem) {
var container = document.createElementNS(HTML_NS, 'div'); var container = document.createElement('div');
var img = document.createElementNS(HTML_NS, 'img'); var img = document.createElement('img');
img.src = Zotero.ItemTypes.getImageSrc(parentItem.itemType); img.src = Zotero.ItemTypes.getImageSrc(parentItem.itemType);
img.className = 'parent-item-type'; img.className = 'parent-item-type';
var title = document.createElementNS(HTML_NS, 'div'); var title = document.createElement('div');
title.append(parentItem.getDisplayTitle()); title.append(parentItem.getDisplayTitle());
title.className = 'parent-title'; title.className = 'parent-title';
container.append(img, title); container.append(img, title);

View file

@ -27,8 +27,6 @@
// eslint-disable-next-line camelcase, no-unused-vars // eslint-disable-next-line camelcase, no-unused-vars
var Zotero_Dictionary_Manager = new function () { var Zotero_Dictionary_Manager = new function () {
const HTML_NS = 'http://www.w3.org/1999/xhtml';
var installed; var installed;
var updateMap; var updateMap;
@ -72,10 +70,10 @@ var Zotero_Dictionary_Manager = new function () {
var listbox = document.getElementById('dictionaries'); var listbox = document.getElementById('dictionaries');
for (let d of list) { for (let d of list) {
let name = d.name; let name = d.name;
let li = document.createElement('richlistitem'); let li = document.createXULElement('richlistitem');
let div = document.createElementNS(HTML_NS, 'div'); let div = document.createElement('div');
let checkbox = document.createElementNS(HTML_NS, 'input'); let checkbox = document.createElement('input');
checkbox.type = 'checkbox'; checkbox.type = 'checkbox';
checkbox.id = d.locale; checkbox.id = d.locale;
// Store properties on element // Store properties on element
@ -91,7 +89,7 @@ var Zotero_Dictionary_Manager = new function () {
} }
checkbox.setAttribute('tabindex', -1); checkbox.setAttribute('tabindex', -1);
let label = document.createElementNS(HTML_NS, 'label'); let label = document.createElement('label');
label.setAttribute('for', d.locale); label.setAttribute('for', d.locale);
// Add " (update available)" // Add " (update available)"
if (updateMap.has(d.id)) { if (updateMap.has(d.id)) {

View file

@ -79,7 +79,7 @@ window.addEventListener(
); );
function createContentAreaContextMenuItem(name) { function createContentAreaContextMenuItem(name) {
let item = document.createElement('menuitem'); let item = document.createXULElement('menuitem');
item.id = 'context-' + name.toLowerCase(); item.id = 'context-' + name.toLowerCase();
item.setAttribute('label', Zotero.Intl.strings[name + 'Cmd.label']); item.setAttribute('label', Zotero.Intl.strings[name + 'Cmd.label']);
item.setAttribute('accesskey', Zotero.Intl.strings[name + 'Cmd.accesskey']); item.setAttribute('accesskey', Zotero.Intl.strings[name + 'Cmd.accesskey']);
@ -88,18 +88,18 @@ function createContentAreaContextMenuItem(name) {
} }
function createContentAreaContextMenu() { function createContentAreaContextMenu() {
let menupopup = document.createElement('menupopup'); let menupopup = document.createXULElement('menupopup');
menupopup.id = 'contentAreaContextMenu'; menupopup.id = 'contentAreaContextMenu';
menupopup.appendChild(createContentAreaContextMenuItem('undo')); menupopup.appendChild(createContentAreaContextMenuItem('undo'));
let undoSep = document.createElement('menuseparator'); let undoSep = document.createXULElement('menuseparator');
undoSep.id = 'context-sep-undo'; undoSep.id = 'context-sep-undo';
menupopup.appendChild(undoSep); menupopup.appendChild(undoSep);
menupopup.appendChild(createContentAreaContextMenuItem('cut')); menupopup.appendChild(createContentAreaContextMenuItem('cut'));
menupopup.appendChild(createContentAreaContextMenuItem('copy')); menupopup.appendChild(createContentAreaContextMenuItem('copy'));
menupopup.appendChild(createContentAreaContextMenuItem('paste')); menupopup.appendChild(createContentAreaContextMenuItem('paste'));
menupopup.appendChild(createContentAreaContextMenuItem('delete')); menupopup.appendChild(createContentAreaContextMenuItem('delete'));
let pasteSep = document.createElement('menuseparator'); let pasteSep = document.createXULElement('menuseparator');
pasteSep.id = 'context-sep-paste'; pasteSep.id = 'context-sep-paste';
menupopup.appendChild(pasteSep); menupopup.appendChild(pasteSep);
menupopup.appendChild(createContentAreaContextMenuItem('selectAll')); menupopup.appendChild(createContentAreaContextMenuItem('selectAll'));

View file

@ -2331,8 +2331,6 @@
// don't overlap. // don't overlap.
if (!this._updateRetracted) { if (!this._updateRetracted) {
this._updateRetracted = Zotero.serial(async function (item) { this._updateRetracted = Zotero.serial(async function (item) {
var htmlNS = 'http://www.w3.org/1999/xhtml';
var show = Zotero.Retractions.isRetracted(item); var show = Zotero.Retractions.isRetracted(item);
if (!show) { if (!show) {
this._id('retraction-box').hidden = true; this._id('retraction-box').hidden = true;
@ -2363,8 +2361,8 @@
elem.hidden = false; elem.hidden = false;
elem.textContent = ''; elem.textContent = '';
for (let reason of data.reasons) { for (let reason of data.reasons) {
let dt = document.createElementNS(htmlNS, 'dt'); let dt = document.createElement('dt');
let dd = document.createElementNS(htmlNS, 'dd'); let dd = document.createElement('dd');
dt.textContent = reason; dt.textContent = reason;
dd.textContent = Zotero.Retractions.getReasonDescription(reason); dd.textContent = Zotero.Retractions.getReasonDescription(reason);
@ -2385,7 +2383,7 @@
if (data.doi || data.pmid) { if (data.doi || data.pmid) {
let div = this._id('retraction-notice'); let div = this._id('retraction-notice');
div.textContent = ''; div.textContent = '';
let a = document.createElementNS(htmlNS, 'a'); let a = document.createElement('a');
a.textContent = Zotero.getString('retraction.notice'); a.textContent = Zotero.getString('retraction.notice');
if (data.doi) { if (data.doi) {
a.href = 'https://doi.org/' + data.doi; a.href = 'https://doi.org/' + data.doi;
@ -2405,13 +2403,13 @@
div.hidden = false; div.hidden = false;
div.textContent = ''; div.textContent = '';
let p = document.createElementNS(htmlNS, 'p'); let p = document.createElement('p');
p.textContent = Zotero.getString('retraction.details'); p.textContent = Zotero.getString('retraction.details');
let ul = document.createElementNS(htmlNS, 'ul'); let ul = document.createElement('ul');
for (let url of data.urls) { for (let url of data.urls) {
let li = document.createElementNS(htmlNS, 'li'); let li = document.createElement('li');
let a = document.createElementNS(htmlNS, 'a'); let a = document.createElement('a');
url = url.replace(/^http:/, 'https:'); url = url.replace(/^http:/, 'https:');
a.href = url; a.href = url;
a.textContent = url; a.textContent = url;
@ -2438,7 +2436,7 @@
creditElem.appendChild(document.createTextNode(part.text)); creditElem.appendChild(document.createTextNode(part.text));
} }
else if (part.type == 'link') { else if (part.type == 'link') {
let a = document.createElementNS(htmlNS, 'a'); let a = document.createElement('a');
a.href = part.attributes.href; a.href = part.attributes.href;
a.textContent = part.text; a.textContent = part.text;
creditElem.appendChild(a); creditElem.appendChild(a);

View file

@ -286,7 +286,7 @@
var label = this.createValueElement(name, tabindex); var label = this.createValueElement(name, tabindex);
if (this.editable) { if (this.editable) {
var remove = document.createElement("label"); var remove = document.createXULElement("label");
remove.setAttribute('value', '-'); remove.setAttribute('value', '-');
remove.setAttribute('class', 'zotero-clicky zotero-clicky-minus'); remove.setAttribute('class', 'zotero-clicky zotero-clicky-minus');
remove.setAttribute('tabindex', -1); remove.setAttribute('tabindex', -1);
@ -371,7 +371,7 @@
createValueElement(valueText, tabindex) { createValueElement(valueText, tabindex) {
var valueElement = document.createElement("label"); var valueElement = document.createXULElement("label");
valueElement.setAttribute('fieldname', 'tag'); valueElement.setAttribute('fieldname', 'tag');
valueElement.setAttribute('flex', 1); valueElement.setAttribute('flex', 1);
valueElement.className = 'zotero-box-label'; valueElement.className = 'zotero-box-label';

View file

@ -256,8 +256,7 @@ var Zotero_Import_Wizard = {
catch (e) { catch (e) {
if (e.message == 'Encrypted Mendeley database') { if (e.message == 'Encrypted Mendeley database') {
let url = 'https://www.zotero.org/support/kb/mendeley_import'; let url = 'https://www.zotero.org/support/kb/mendeley_import';
let HTML_NS = 'http://www.w3.org/1999/xhtml' let elem = document.createElement('div');
let elem = document.createElementNS(HTML_NS, 'div');
elem.innerHTML = `The selected Mendeley database cannot be read, likely because it ` elem.innerHTML = `The selected Mendeley database cannot be read, likely because it `
+ `is encrypted. See <a href="${url}" class="text-link">How do I import a ` + `is encrypted. See <a href="${url}" class="text-link">How do I import a `
+ `Mendeley library into Zotero?</a> for more information.` + `Mendeley library into Zotero?</a> for more information.`

View file

@ -117,7 +117,7 @@ var Zotero_Citation_Dialog = new function () {
var locator = locators[value]; var locator = locators[value];
var locatorLabel = Zotero.getString('citation.locator.'+locator.replace(/\s/g,'')); var locatorLabel = Zotero.getString('citation.locator.'+locator.replace(/\s/g,''));
// add to list of labels // add to list of labels
var child = document.createElement("menuitem"); var child = document.createXULElement("menuitem");
child.setAttribute("value", value); child.setAttribute("value", value);
child.setAttribute("label", locatorLabel); child.setAttribute("label", locatorLabel);
label_list.appendChild(child); label_list.appendChild(child);

View file

@ -122,7 +122,7 @@ var Zotero_QuickFormat = new function () {
var locatorLabel = Zotero.getString('citation.locator.'+locator.replace(/\s/g,'')); var locatorLabel = Zotero.getString('citation.locator.'+locator.replace(/\s/g,''));
// add to list of labels // add to list of labels
var child = document.createElement("menuitem"); var child = document.createXULElement("menuitem");
child.setAttribute("value", locator); child.setAttribute("value", locator);
child.setAttribute("label", locatorLabel); child.setAttribute("label", locatorLabel);
labelList.appendChild(child); labelList.appendChild(child);
@ -620,7 +620,7 @@ var Zotero_QuickFormat = new function () {
var publicationTitle = item.getField("publicationTitle", false, true); var publicationTitle = item.getField("publicationTitle", false, true);
if(publicationTitle) { if(publicationTitle) {
var label = document.createElement("label"); var label = document.createXULElement("label");
label.setAttribute("value", publicationTitle); label.setAttribute("value", publicationTitle);
label.setAttribute("crop", "end"); label.setAttribute("crop", "end");
label.style.fontStyle = "italic"; label.style.fontStyle = "italic";
@ -652,7 +652,7 @@ var Zotero_QuickFormat = new function () {
if(i != 0) str += ", "; if(i != 0) str += ", ";
if(typeof node === "object") { if(typeof node === "object") {
var label = document.createElement("label"); var label = document.createXULElement("label");
label.setAttribute("value", str); label.setAttribute("value", str);
label.setAttribute("crop", "end"); label.setAttribute("crop", "end");
infoHbox.appendChild(label); infoHbox.appendChild(label);
@ -666,7 +666,7 @@ var Zotero_QuickFormat = new function () {
if(nodes.length && (!str.length || str[str.length-1] !== ".")) str += "."; if(nodes.length && (!str.length || str[str.length-1] !== ".")) str += ".";
} }
var label = document.createElement("label"); var label = document.createXULElement("label");
label.setAttribute("value", str); label.setAttribute("value", str);
label.setAttribute("crop", "end"); label.setAttribute("crop", "end");
label.setAttribute("flex", "1"); label.setAttribute("flex", "1");
@ -677,13 +677,13 @@ var Zotero_QuickFormat = new function () {
* Creates an item to be added to the item list * Creates an item to be added to the item list
*/ */
function _buildListItem(item) { function _buildListItem(item) {
var titleNode = document.createElement("label"); var titleNode = document.createXULElement("label");
titleNode.setAttribute("class", "citation-dialog title"); titleNode.setAttribute("class", "citation-dialog title");
titleNode.setAttribute("flex", "1"); titleNode.setAttribute("flex", "1");
titleNode.setAttribute("crop", "end"); titleNode.setAttribute("crop", "end");
titleNode.setAttribute("value", item.getDisplayTitle()); titleNode.setAttribute("value", item.getDisplayTitle());
var infoNode = document.createElement("hbox"); var infoNode = document.createXULElement("hbox");
infoNode.setAttribute("class", "citation-dialog info"); infoNode.setAttribute("class", "citation-dialog info");
_buildItemDescription(item, infoNode); _buildItemDescription(item, infoNode);
@ -703,7 +703,7 @@ var Zotero_QuickFormat = new function () {
* Creates a list separator to be added to the item list * Creates a list separator to be added to the item list
*/ */
function _buildListSeparator(labelText, loading) { function _buildListSeparator(labelText, loading) {
var titleNode = document.createElement("label"); var titleNode = document.createXULElement("label");
titleNode.setAttribute("class", "citation-dialog separator-title"); titleNode.setAttribute("class", "citation-dialog separator-title");
titleNode.setAttribute("flex", "1"); titleNode.setAttribute("flex", "1");
titleNode.setAttribute("crop", "end"); titleNode.setAttribute("crop", "end");

View file

@ -41,7 +41,6 @@ const CHILD_INDENT = 12;
const COLORED_TAGS_RE = new RegExp("^[0-" + Zotero.Tags.MAX_COLORED_TAGS + "]{1}$"); const COLORED_TAGS_RE = new RegExp("^[0-" + Zotero.Tags.MAX_COLORED_TAGS + "]{1}$");
const COLUMN_PREFS_FILEPATH = OS.Path.join(Zotero.Profile.dir, "treePrefs.json"); const COLUMN_PREFS_FILEPATH = OS.Path.join(Zotero.Profile.dir, "treePrefs.json");
const EMOJI_RE = /\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F/gu; const EMOJI_RE = /\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F/gu;
const HTML_NS = "http://www.w3.org/1999/xhtml";
const ATTACHMENT_STATE_LOAD_DELAY = 150; //ms const ATTACHMENT_STATE_LOAD_DELAY = 150; //ms
var ItemTree = class ItemTree extends LibraryTree { var ItemTree = class ItemTree extends LibraryTree {
@ -132,7 +131,7 @@ var ItemTree = class ItemTree extends LibraryTree {
this._itemTreeLoadingDeferred.resolve(); this._itemTreeLoadingDeferred.resolve();
// Create an element where we can create drag images to be displayed next to the cursor while dragging // Create an element where we can create drag images to be displayed next to the cursor while dragging
// since for multiple item drags we need to display all the elements // since for multiple item drags we need to display all the elements
let elem = this._dragImageContainer = document.createElementNS(HTML_NS, "div"); let elem = this._dragImageContainer = document.createElement("div");
elem.style.width = "100%"; elem.style.width = "100%";
elem.style.height = "2000px"; elem.style.height = "2000px";
elem.style.position = "absolute"; elem.style.position = "absolute";
@ -2621,7 +2620,7 @@ var ItemTree = class ItemTree extends LibraryTree {
if (this._titleMarkup.hasOwnProperty(token)) { if (this._titleMarkup.hasOwnProperty(token)) {
let markup = this._titleMarkup[token]; let markup = this._titleMarkup[token];
if (markup.beginsTag) { if (markup.beginsTag) {
let node = document.createElementNS(HTML_NS, markup.beginsTag); let node = document.createElement(markup.beginsTag);
if (markup.style) { if (markup.style) {
Object.assign(node.style, markup.style); Object.assign(node.style, markup.style);
} }
@ -2663,14 +2662,14 @@ var ItemTree = class ItemTree extends LibraryTree {
} }
_renderPrimaryCell(index, data, column) { _renderPrimaryCell(index, data, column) {
let span = document.createElementNS(HTML_NS, 'span'); let span = document.createElement('span');
span.className = `cell ${column.className}`; span.className = `cell ${column.className}`;
span.classList.add('primary'); span.classList.add('primary');
// Add twisty, icon, tag swatches and retraction indicator // Add twisty, icon, tag swatches and retraction indicator
let twisty; let twisty;
if (this.isContainerEmpty(index)) { if (this.isContainerEmpty(index)) {
twisty = document.createElementNS(HTML_NS, 'span'); twisty = document.createElement('span');
twisty.classList.add("spacer-twisty"); twisty.classList.add("spacer-twisty");
} }
else { else {
@ -2716,7 +2715,7 @@ var ItemTree = class ItemTree extends LibraryTree {
Zotero.debug(e, 1); Zotero.debug(e, 1);
} }
let textSpan = document.createElementNS(HTML_NS, 'span'); let textSpan = document.createElement('span');
let textWithFullStop = this._renderItemTitle(data, textSpan); let textWithFullStop = this._renderItemTitle(data, textSpan);
if (!textWithFullStop.match(/\.$/)) { if (!textWithFullStop.match(/\.$/)) {
textWithFullStop += '.'; textWithFullStop += '.';
@ -2735,7 +2734,7 @@ var ItemTree = class ItemTree extends LibraryTree {
} }
_renderHasAttachmentCell(index, data, column) { _renderHasAttachmentCell(index, data, column) {
let span = document.createElementNS(HTML_NS, 'span'); let span = document.createElement('span');
span.className = `cell ${column.className}`; span.className = `cell ${column.className}`;
if (this.collectionTreeRow.isTrash()) return span; if (this.collectionTreeRow.isTrash()) return span;
@ -2865,7 +2864,7 @@ var ItemTree = class ItemTree extends LibraryTree {
div.innerHTML = ""; div.innerHTML = "";
} }
else { else {
div = document.createElementNS(HTML_NS, 'div'); div = document.createElement('div');
div.className = "row"; div.className = "row";
} }
@ -2878,7 +2877,7 @@ var ItemTree = class ItemTree extends LibraryTree {
if (this._dropRow == index) { if (this._dropRow == index) {
let span; let span;
if (Zotero.DragDrop.currentOrientation != 0) { if (Zotero.DragDrop.currentOrientation != 0) {
span = document.createElementNS(HTML_NS, 'span'); span = document.createElement('span');
span.className = Zotero.DragDrop.currentOrientation < 0 ? "drop-before" : "drop-after"; span.className = Zotero.DragDrop.currentOrientation < 0 ? "drop-before" : "drop-after";
div.appendChild(span); div.appendChild(span);
} else { } else {
@ -3252,13 +3251,12 @@ var ItemTree = class ItemTree extends LibraryTree {
if (this.collectionTreeRow && !this.rowCount) { if (this.collectionTreeRow && !this.rowCount) {
let doc = this._ownerDocument; let doc = this._ownerDocument;
let ns = 'http://www.w3.org/1999/xhtml';
let div; let div;
// My Library and no groups // My Library and no groups
if (this.collectionTreeRow.isLibrary() && !Zotero.Groups.getAll().length) { if (this.collectionTreeRow.isLibrary() && !Zotero.Groups.getAll().length) {
div = doc.createElementNS(ns, 'div'); div = doc.createElement('div');
let p = doc.createElementNS(ns, 'p'); let p = doc.createElement('p');
let html = Zotero.getString( let html = Zotero.getString(
'pane.items.intro.text1', 'pane.items.intro.text1',
[ [
@ -3271,7 +3269,7 @@ var ItemTree = class ItemTree extends LibraryTree {
p.innerHTML = html; p.innerHTML = html;
div.appendChild(p); div.appendChild(p);
p = doc.createElementNS(ns, 'p'); p = doc.createElement('p');
html = Zotero.getString( html = Zotero.getString(
'pane.items.intro.text2', 'pane.items.intro.text2',
[ [
@ -3290,7 +3288,7 @@ var ItemTree = class ItemTree extends LibraryTree {
p.innerHTML = html; p.innerHTML = html;
div.appendChild(p); div.appendChild(p);
p = doc.createElementNS(ns, 'p'); p = doc.createElement('p');
html = Zotero.getString('pane.items.intro.text3', [Zotero.clientName]); html = Zotero.getString('pane.items.intro.text3', [Zotero.clientName]);
// Encode special chars, which shouldn't exist // Encode special chars, which shouldn't exist
html = Zotero.Utilities.htmlSpecialChars(html); html = Zotero.Utilities.htmlSpecialChars(html);
@ -3323,17 +3321,17 @@ var ItemTree = class ItemTree extends LibraryTree {
} }
// My Publications // My Publications
else if (this.collectionTreeRow.isPublications()) { else if (this.collectionTreeRow.isPublications()) {
div = doc.createElementNS(ns, 'div'); div = doc.createElement('div');
div.className = 'publications'; div.className = 'publications';
let p = doc.createElementNS(ns, 'p'); let p = doc.createElement('p');
p.textContent = Zotero.getString('publications.intro.text1', window.ZOTERO_CONFIG.DOMAIN_NAME); p.textContent = Zotero.getString('publications.intro.text1', window.ZOTERO_CONFIG.DOMAIN_NAME);
div.appendChild(p); div.appendChild(p);
p = doc.createElementNS(ns, 'p'); p = doc.createElement('p');
p.textContent = Zotero.getString('publications.intro.text2'); p.textContent = Zotero.getString('publications.intro.text2');
div.appendChild(p); div.appendChild(p);
p = doc.createElementNS(ns, 'p'); p = doc.createElement('p');
let html = Zotero.getString('publications.intro.text3'); let html = Zotero.getString('publications.intro.text3');
// Convert <b> tags to placeholders // Convert <b> tags to placeholders
html = html.replace('<b>', ':b:').replace('</b>', ':/b:'); html = html.replace('<b>', ':b:').replace('</b>', ':/b:');
@ -3821,7 +3819,7 @@ var ItemTree = class ItemTree extends LibraryTree {
var icon = getDOMElement(iconClsName); var icon = getDOMElement(iconClsName);
if (!icon) { if (!icon) {
Zotero.debug('Could not find tree icon for "' + itemType + '"'); Zotero.debug('Could not find tree icon for "' + itemType + '"');
return document.createElementNS(HTML_NS, 'span'); return document.createElement('span');
} }
return icon; return icon;
} }
@ -3832,7 +3830,7 @@ var ItemTree = class ItemTree extends LibraryTree {
} }
_getTagSwatch(tag, color) { _getTagSwatch(tag, color) {
let span = document.createElementNS(HTML_NS, 'span'); let span = document.createElement('span');
span.className = 'tag-swatch'; span.className = 'tag-swatch';
// If only emoji, display directly // If only emoji, display directly
// //

View file

@ -280,21 +280,21 @@ var Zotero_Publications_Dialog = new function () {
var div = currentPage.getElementsByAttribute('class', 'license-description')[0]; var div = currentPage.getElementsByAttribute('class', 'license-description')[0];
} }
else { else {
let hbox = document.createElement('hbox'); let hbox = document.createXULElement('hbox');
hbox.align = "center"; hbox.align = "center";
groupbox.appendChild(hbox); groupbox.appendChild(hbox);
var icon = document.createElement('image'); var icon = document.createXULElement('image');
icon.className = 'license-icon'; icon.className = 'license-icon';
icon.setAttribute('style', 'width: 88px'); icon.setAttribute('style', 'width: 88px');
hbox.appendChild(icon); hbox.appendChild(icon);
let sep = document.createElement('separator'); let sep = document.createXULElement('separator');
sep.orient = 'vertical'; sep.orient = 'vertical';
sep.setAttribute('style', 'width: 10px'); sep.setAttribute('style', 'width: 10px');
hbox.appendChild(sep); hbox.appendChild(sep);
var div = document.createElementNS('http://www.w3.org/1999/xhtml', 'div'); var div = document.createElement('div');
div.className = 'license-description'; div.className = 'license-description';
div.setAttribute('style', 'width: 400px'); div.setAttribute('style', 'width: 400px');
hbox.appendChild(div); hbox.appendChild(div);

View file

@ -702,7 +702,7 @@ var Zotero_RTFScan = new function() {
div.innerHTML = ""; div.innerHTML = "";
} }
else { else {
div = document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); div = document.createElement('div');
div.className = "row"; div.className = "row";
} }
@ -721,15 +721,15 @@ var Zotero_RTFScan = new function() {
{ passive: true }); { passive: true });
} }
else { else {
twisty = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); twisty = document.createElement('span');
twisty.classList.add("spacer-twisty"); twisty.classList.add("spacer-twisty");
} }
let textSpan = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); let textSpan = document.createElement('span');
textSpan.className = "cell-text"; textSpan.className = "cell-text";
textSpan.innerText = row[column.dataKey] || ""; textSpan.innerText = row[column.dataKey] || "";
let span = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); let span = document.createElement('span');
span.className = `cell primary ${column.className}`; span.className = `cell primary ${column.className}`;
span.appendChild(twisty); span.appendChild(twisty);
span.appendChild(textSpan); span.appendChild(textSpan);
@ -737,7 +737,7 @@ var Zotero_RTFScan = new function() {
div.appendChild(span); div.appendChild(span);
} }
else if (column.dataKey == 'action') { else if (column.dataKey == 'action') {
let span = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); let span = document.createElement('span');
span.className = `cell action ${column.className}`; span.className = `cell action ${column.className}`;
if (row.parent) { if (row.parent) {
if (row.action) { if (row.action) {
@ -753,7 +753,7 @@ var Zotero_RTFScan = new function() {
div.appendChild(span); div.appendChild(span);
} }
else { else {
let span = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); let span = document.createElement('span');
span.className = `cell ${column.className}`; span.className = `cell ${column.className}`;
span.innerText = row[column.dataKey] || ""; span.innerText = row[column.dataKey] || "";
div.appendChild(span); div.appendChild(span);

View file

@ -128,7 +128,7 @@ var Zotero_Tag_Color_Chooser = new function() {
var msg = Zotero.getString('tagColorChooser.numberKeyInstructions'); var msg = Zotero.getString('tagColorChooser.numberKeyInstructions');
var matches = msg.match(/(.+)\$NUMBER(.+)/); var matches = msg.match(/(.+)\$NUMBER(.+)/);
var num = document.createElement('label'); var num = document.createXULElement('label');
num.id = 'number-key'; num.id = 'number-key';
num.setAttribute('value', parseInt(tagPosition.value) + 1); num.setAttribute('value', parseInt(tagPosition.value) + 1);

View file

@ -826,7 +826,7 @@ Zotero.Tags = new function() {
.getService(Components.interfaces.nsIAppShellService) .getService(Components.interfaces.nsIAppShellService)
.hiddenDOMWindow; .hiddenDOMWindow;
var doc = win.document; var doc = win.document;
var canvas = doc.createElementNS('http://www.w3.org/1999/xhtml', 'canvas'); var canvas = doc.createElement('canvas');
var width = extraImageWidth var width = extraImageWidth
+ (retracted + (retracted

View file

@ -475,7 +475,7 @@ class PDFRenderer {
return new Promise((resolve) => { return new Promise((resolve) => {
this._browser = Zotero.Browser.createHiddenBrowser(); this._browser = Zotero.Browser.createHiddenBrowser();
let doc = this._browser.ownerDocument; let doc = this._browser.ownerDocument;
let container = doc.createElement('hbox'); let container = doc.createXULElement('hbox');
container.style.position = 'fixed'; container.style.position = 'fixed';
container.style.zIndex = '-1'; container.style.zIndex = '-1';
container.append(this._browser); container.append(this._browser);

View file

@ -32,7 +32,6 @@ if (!Zotero.Sync) {
// Initialized as Zotero.Sync.Runner in zotero.js // Initialized as Zotero.Sync.Runner in zotero.js
Zotero.Sync.Runner_Module = function (options = {}) { Zotero.Sync.Runner_Module = function (options = {}) {
const stopOnError = false; const stopOnError = false;
const HTML_NS = 'http://www.w3.org/1999/xhtml';
Zotero.defineProperty(this, 'enabled', { Zotero.defineProperty(this, 'enabled', {
get: () => { get: () => {
@ -1692,7 +1691,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
if (_tooltipMessages.length) { if (_tooltipMessages.length) {
_currentTooltipMessages.textContent = ''; _currentTooltipMessages.textContent = '';
for (let message of _tooltipMessages) { for (let message of _tooltipMessages) {
let elem = _currentTooltipMessages.ownerDocument.createElementNS(HTML_NS, 'p'); let elem = _currentTooltipMessages.ownerDocument.createElement('p');
elem.textContent = message; elem.textContent = message;
_currentTooltipMessages.appendChild(elem); _currentTooltipMessages.appendChild(elem);
} }

View file

@ -1678,7 +1678,7 @@ Zotero.Utilities.Internal = {
var selectedIndex = 0; var selectedIndex = 0;
var i = 0; var i = 0;
for (let library of libraries) { for (let library of libraries) {
let menuitem = menulist.ownerDocument.createElement('menuitem'); let menuitem = menulist.ownerDocument.createXULElement('menuitem');
menuitem.value = library.libraryID; menuitem.value = library.libraryID;
menuitem.setAttribute('label', library.name); menuitem.setAttribute('label', library.name);
menupopup.appendChild(menuitem); menupopup.appendChild(menuitem);
@ -1694,14 +1694,13 @@ Zotero.Utilities.Internal = {
buildLibraryMenuHTML: function (select, libraries, selectedLibraryID) { buildLibraryMenuHTML: function (select, libraries, selectedLibraryID) {
var namespaceURI = 'http://www.w3.org/1999/xhtml';
while (select.hasChildNodes()) { while (select.hasChildNodes()) {
select.removeChild(select.firstChild); select.removeChild(select.firstChild);
} }
var selectedIndex = 0; var selectedIndex = 0;
var i = 0; var i = 0;
for (let library of libraries) { for (let library of libraries) {
let option = select.ownerDocument.createElementNS(namespaceURI, 'option'); let option = select.ownerDocument.createElement('option');
option.setAttribute('value', library.libraryID); option.setAttribute('value', library.libraryID);
option.setAttribute('data-editable', library.editable ? 'true' : 'false'); option.setAttribute('data-editable', library.editable ? 'true' : 'false');
option.setAttribute('data-filesEditable', library.filesEditable ? 'true' : 'false'); option.setAttribute('data-filesEditable', library.filesEditable ? 'true' : 'false');

View file

@ -1453,8 +1453,6 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
* @return void * @return void
*/ */
this.showZoteroPaneProgressMeter = function (msg, determinate, icon, modalOnly) { this.showZoteroPaneProgressMeter = function (msg, determinate, icon, modalOnly) {
const HTML_NS = "http://www.w3.org/1999/xhtml"
// If msg is undefined, keep any existing message. If false/null/"", clear. // If msg is undefined, keep any existing message. If false/null/"", clear.
// The message is also cleared when the meters are hidden. // The message is also cleared when the meters are hidden.
_progressMessage = msg = (msg === undefined ? _progressMessage : msg) || ""; _progressMessage = msg = (msg === undefined ? _progressMessage : msg) || "";
@ -1489,7 +1487,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
let id = 'zotero-pane-progressmeter'; let id = 'zotero-pane-progressmeter';
let progressMeter = doc.getElementById(id); let progressMeter = doc.getElementById(id);
if (!progressMeter) { if (!progressMeter) {
progressMeter = doc.createElementNS(HTML_NS, 'progress'); progressMeter = doc.createElement('progress');
progressMeter.id = id; progressMeter.id = id;
} }
if (determinate) { if (determinate) {
@ -1647,10 +1645,10 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
button.id = 'zotero-tb-search-menu-button'; button.id = 'zotero-tb-search-menu-button';
button.setAttribute('type', 'menu'); button.setAttribute('type', 'menu');
var menupopup = document.createElement('menupopup'); var menupopup = document.createXULElement('menupopup');
for (var i in modes) { for (var i in modes) {
var menuitem = document.createElement('menuitem'); var menuitem = document.createXULElement('menuitem');
menuitem.setAttribute('id', prefix + i); menuitem.setAttribute('id', prefix + i);
menuitem.setAttribute('label', modes[i].label); menuitem.setAttribute('label', modes[i].label);
menuitem.setAttribute('name', 'searchMode'); menuitem.setAttribute('name', 'searchMode');

View file

@ -3248,7 +3248,7 @@ var ZoteroPane = new function()
if (eligibleAttachments.length > 1) { if (eligibleAttachments.length > 1) {
show.add(m.createNoteFromAnnotationsMenu); show.add(m.createNoteFromAnnotationsMenu);
for (let attachment of attachmentsWithAnnotations) { for (let attachment of attachmentsWithAnnotations) {
let menuitem = document.createElement('menuitem'); let menuitem = document.createXULElement('menuitem');
menuitem.setAttribute('label', attachment.getDisplayTitle()); menuitem.setAttribute('label', attachment.getDisplayTitle());
menuitem.onclick = () => { menuitem.onclick = () => {
ZoteroPane.createNoteFromAnnotationsForAttachment(attachment); ZoteroPane.createNoteFromAnnotationsForAttachment(attachment);
@ -3626,7 +3626,7 @@ var ZoteroPane = new function()
if (typeof content == 'string') { if (typeof content == 'string') {
let contentParts = content.split("\n\n"); let contentParts = content.split("\n\n");
for (let part of contentParts) { for (let part of contentParts) {
let desc = document.createElement('description'); let desc = document.createXULElement('description');
desc.appendChild(document.createTextNode(part)); desc.appendChild(document.createTextNode(part));
elem.appendChild(desc); elem.appendChild(desc);
} }

View file

@ -191,14 +191,14 @@ ZoteroPluginInstaller.prototype = {
showPreferences: function(document) { showPreferences: function(document) {
this.prefPaneDoc = document; this.prefPaneDoc = document;
var isInstalled = this.isInstalled(), var isInstalled = this.isInstalled(),
groupbox = document.createElement("groupbox"); groupbox = document.createXULElement("groupbox");
groupbox.id = this._addon.EXTENSION_DIR; groupbox.id = this._addon.EXTENSION_DIR;
var caption = document.createElement("caption"); var caption = document.createXULElement("caption");
caption.setAttribute("label", this._addon.APP); caption.setAttribute("label", this._addon.APP);
groupbox.appendChild(caption); groupbox.appendChild(caption);
var description = document.createElement("description"); var description = document.createXULElement("description");
description.style.width = "45em"; description.style.width = "45em";
description.appendChild(document.createTextNode( description.appendChild(document.createTextNode(
isInstalled ? isInstalled ?
@ -206,9 +206,9 @@ ZoteroPluginInstaller.prototype = {
Zotero.getString('zotero.preferences.wordProcessors.notInstalled', this._addon.APP))); Zotero.getString('zotero.preferences.wordProcessors.notInstalled', this._addon.APP)));
groupbox.appendChild(description); groupbox.appendChild(description);
var hbox = document.createElement("hbox"); var hbox = document.createXULElement("hbox");
hbox.setAttribute("pack", "center"); hbox.setAttribute("pack", "center");
var button = document.createElement("button"), var button = document.createXULElement("button"),
addon = this._addon; addon = this._addon;
button.setAttribute("label", button.setAttribute("label",
(isInstalled ? (isInstalled ?