From f81b4b071f337728edc3deedda3a5534a676cab3 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Wed, 29 Jun 2022 10:16:49 -0400 Subject: [PATCH] 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. --- chrome/content/scaffold/scaffold.js | 2 +- chrome/content/zotero/collectionTree.jsx | 14 +++---- chrome/content/zotero/components/icons.jsx | 2 +- .../zotero/components/progressQueueTable.jsx | 6 +-- .../zotero/components/virtualized-table.jsx | 20 ++++++---- .../zotero/components/windowed-list.js | 2 +- .../containers/tagSelectorContainer.jsx | 4 +- chrome/content/zotero/contextPane.js | 10 ++--- chrome/content/zotero/dictionaryManager.js | 10 ++--- chrome/content/zotero/editContextMenu.js | 8 ++-- chrome/content/zotero/elements/itemBox.js | 18 ++++----- chrome/content/zotero/elements/tagsBox.js | 4 +- chrome/content/zotero/import/importWizard.js | 3 +- .../zotero/integration/addCitationDialog.js | 2 +- .../content/zotero/integration/quickFormat.js | 14 +++---- chrome/content/zotero/itemTree.jsx | 38 +++++++++---------- chrome/content/zotero/publicationsDialog.js | 8 ++-- chrome/content/zotero/rtfScan.jsx | 12 +++--- chrome/content/zotero/tagColorChooser.js | 2 +- chrome/content/zotero/xpcom/data/tags.js | 2 +- .../content/zotero/xpcom/pdfWorker/manager.js | 2 +- .../content/zotero/xpcom/sync/syncRunner.js | 3 +- .../zotero/xpcom/utilities_internal.js | 5 +-- chrome/content/zotero/xpcom/zotero.js | 8 ++-- chrome/content/zotero/zoteroPane.js | 4 +- resource/word-processor-plugin-installer.js | 10 ++--- 26 files changed, 103 insertions(+), 110 deletions(-) diff --git a/chrome/content/scaffold/scaffold.js b/chrome/content/scaffold/scaffold.js index 6d1949696f..114e983c5e 100644 --- a/chrome/content/scaffold/scaffold.js +++ b/chrome/content/scaffold/scaffold.js @@ -124,7 +124,7 @@ var Scaffold = new function () { var primaryTypes = ['book', 'bookSection', 'conferencePaper', 'journalArticle', 'magazineArticle', 'newspaperArticle']; for (let type of types) { if (primaryTypes.includes(type)) continue; - var menuitem = document.createElement('menuitem'); + var menuitem = document.createXULElement('menuitem'); menuitem.setAttribute('label', type); menuitem.addEventListener('command', () => { Scaffold.addTemplate('templateNewItem', type); diff --git a/chrome/content/zotero/collectionTree.jsx b/chrome/content/zotero/collectionTree.jsx index c5e2f21f91..07899b69a2 100644 --- a/chrome/content/zotero/collectionTree.jsx +++ b/chrome/content/zotero/collectionTree.jsx @@ -223,7 +223,7 @@ var CollectionTree = class CollectionTree extends LibraryTree { const treeRow = this.getRow(index); // Div creation and content - let div = oldDiv || document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); + let div = oldDiv || document.createElement('div'); div.innerHTML = ""; // Classes @@ -245,13 +245,13 @@ var CollectionTree = class CollectionTree extends LibraryTree { div.style.paddingInlineStart = (CHILD_INDENT * depth) + 'px'; // 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"; // Twisty/spacer let twisty; if (this.isContainerEmpty(index)) { - twisty = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); + twisty = document.createElement('span'); if (Zotero.isMac && treeRow.isHeader()) { twisty.classList.add("spacer-header"); } @@ -275,14 +275,14 @@ var CollectionTree = class CollectionTree extends LibraryTree { icon.classList.add('cell-icon'); // Label - let label = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); + let label = document.createElement('span'); label.innerText = treeRow.getName(); label.className = 'cell-text'; // Editing input div.classList.toggle('editing', 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.setAttribute("size", 5); label.value = treeRow.editingName; @@ -2116,12 +2116,12 @@ var CollectionTree = class CollectionTree extends LibraryTree { iconClsName = iconClsName || "IconTreesource" + collectionType; if (collectionType == 'Separator') { - return document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); + return document.createElement('span'); } var icon = getDOMIcon(iconClsName); if (!icon) { - return document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); + return document.createElement('span'); } return icon; } diff --git a/chrome/content/zotero/components/icons.jsx b/chrome/content/zotero/components/icons.jsx index b22412e9d8..f95490ac12 100644 --- a/chrome/content/zotero/components/icons.jsx +++ b/chrome/content/zotero/components/icons.jsx @@ -211,7 +211,7 @@ module.exports.getDOMElement = function (icon) { Zotero.debug(`Attempting to get non-existant icon ${icon}`); 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])); domElementCache[icon] = div.firstChild; return domElementCache[icon].cloneNode(true); diff --git a/chrome/content/zotero/components/progressQueueTable.jsx b/chrome/content/zotero/components/progressQueueTable.jsx index 4406080979..58011f87bb 100644 --- a/chrome/content/zotero/components/progressQueueTable.jsx +++ b/chrome/content/zotero/components/progressQueueTable.jsx @@ -41,7 +41,7 @@ function getImageByStatus(status) { else if (status === Zotero.ProgressQueue.ROW_SUCCEEDED) { return getDOMElement('IconTick'); } - return document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); + return document.createElement('span'); } const ProgressQueueTable = ({ onActivate = noop, progressQueue }) => { @@ -59,7 +59,7 @@ const ProgressQueueTable = ({ onActivate = noop, progressQueue }) => { div.innerHTML = ""; } else { - div = document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); + div = document.createElement('div'); div.className = "row"; } @@ -67,7 +67,7 @@ const ProgressQueueTable = ({ onActivate = noop, progressQueue }) => { for (let column of columns) { 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.appendChild(getImageByStatus(row.status)); div.appendChild(span); diff --git a/chrome/content/zotero/components/virtualized-table.jsx b/chrome/content/zotero/components/virtualized-table.jsx index 9fbe64bad8..e09f2f9152 100644 --- a/chrome/content/zotero/components/virtualized-table.jsx +++ b/chrome/content/zotero/components/virtualized-table.jsx @@ -1009,7 +1009,7 @@ class VirtualizedTable extends React.Component { xulElem.setAttribute('tooltip', 'html-tooltip'); } if (document.querySelector('tooltip#html-tooltip')) return; - let tooltip = document.createElement('tooltip'); + let tooltip = document.createXULElement('tooltip'); tooltip.id = 'html-tooltip'; tooltip.addEventListener('popupshowing', function(e) { let tooltipTitleNode = document.tooltipNode.closest('div *[title], iframe *[title], browser *[title]'); @@ -1019,7 +1019,13 @@ class VirtualizedTable extends React.Component { } 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() { @@ -1246,7 +1252,7 @@ class VirtualizedTable extends React.Component { } _getRenderedTextHeight() { - let div = document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); + let div = document.createElement('div'); div.style.visibility = "hidden"; div.textContent = "Zotero"; document.documentElement.appendChild(div); @@ -1419,7 +1425,7 @@ var Columns = class { this._columnStyleMap[column.dataKey] = ruleIndex; } } else { - this._stylesheet = document.createElementNS("http://www.w3.org/1999/xhtml", 'style'); + this._stylesheet = document.createElement('style'); this._stylesheet.className = stylesheetClass; document.children[0].appendChild(this._stylesheet); this._columnStyleMap = {}; @@ -1579,14 +1585,14 @@ var Columns = class { }; 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.innerText = data; return span; } 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.setAttribute('role', 'checkbox'); span.setAttribute('aria-checked', data); @@ -1604,7 +1610,7 @@ function makeRowRenderer(getRowData) { div.innerHTML = ""; } else { - div = document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); + div = document.createElement('div'); div.className = "row"; } diff --git a/chrome/content/zotero/components/windowed-list.js b/chrome/content/zotero/components/windowed-list.js index 28ed3d78c1..11e3c9a4d5 100644 --- a/chrome/content/zotero/components/windowed-list.js +++ b/chrome/content/zotero/components/windowed-list.js @@ -68,7 +68,7 @@ module.exports = class { */ initialize() { const { targetElement } = this; - this.innerElem = document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); + this.innerElem = document.createElement('div'); this.innerElem.className = "windowed-list"; targetElement.appendChild(this.innerElem); diff --git a/chrome/content/zotero/containers/tagSelectorContainer.jsx b/chrome/content/zotero/containers/tagSelectorContainer.jsx index 68ea5ca6f1..dc2b3f2dbb 100644 --- a/chrome/content/zotero/containers/tagSelectorContainer.jsx +++ b/chrome/content/zotero/containers/tagSelectorContainer.jsx @@ -345,7 +345,7 @@ Zotero.TagSelector = class TagSelectorContainer extends React.PureComponent { } getFontInfo() { - var elem = document.createElementNS("http://www.w3.org/1999/xhtml", "div"); + var elem = document.createElement("div"); elem.className = 'tag-selector-item'; elem.style.position = 'absolute'; elem.style.opacity = 0; @@ -381,7 +381,7 @@ Zotero.TagSelector = class TagSelectorContainer extends React.PureComponent { */ getTextWidth(text, font) { // 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"); context.font = font; // Add a little more to make sure we don't crop diff --git a/chrome/content/zotero/contextPane.js b/chrome/content/zotero/contextPane.js index 91c8300d04..e8b53bfc22 100644 --- a/chrome/content/zotero/contextPane.js +++ b/chrome/content/zotero/contextPane.js @@ -30,8 +30,6 @@ var ReactDOM = require('react-dom'); var NotesList = require('components/itemPane/notesList').default; var ZoteroContextPane = new function () { - const HTML_NS = 'http://www.w3.org/1999/xhtml'; - var _tabCover; var _contextPane; var _contextPaneInner; @@ -489,7 +487,7 @@ var ZoteroContextPane = new function () { var listBox = document.createXULElement('vbox'); listBox.style.display = 'flex'; listBox.setAttribute('flex', '1'); - var listInner = document.createElementNS(HTML_NS, 'div'); + var listInner = document.createElement('div'); listInner.className = 'notes-list-container'; // Otherwise it can be focused with tab listInner.tabIndex = -1; @@ -742,11 +740,11 @@ var ZoteroContextPane = new function () { node.querySelector('.zotero-context-pane-editor-parent-line').innerHTML = ''; var parentItem = item.parentItem; if (parentItem) { - var container = document.createElementNS(HTML_NS, 'div'); - var img = document.createElementNS(HTML_NS, 'img'); + var container = document.createElement('div'); + var img = document.createElement('img'); img.src = Zotero.ItemTypes.getImageSrc(parentItem.itemType); img.className = 'parent-item-type'; - var title = document.createElementNS(HTML_NS, 'div'); + var title = document.createElement('div'); title.append(parentItem.getDisplayTitle()); title.className = 'parent-title'; container.append(img, title); diff --git a/chrome/content/zotero/dictionaryManager.js b/chrome/content/zotero/dictionaryManager.js index 050b54b2a4..d570eaad64 100644 --- a/chrome/content/zotero/dictionaryManager.js +++ b/chrome/content/zotero/dictionaryManager.js @@ -27,8 +27,6 @@ // eslint-disable-next-line camelcase, no-unused-vars var Zotero_Dictionary_Manager = new function () { - const HTML_NS = 'http://www.w3.org/1999/xhtml'; - var installed; var updateMap; @@ -72,10 +70,10 @@ var Zotero_Dictionary_Manager = new function () { var listbox = document.getElementById('dictionaries'); for (let d of list) { let name = d.name; - let li = document.createElement('richlistitem'); - let div = document.createElementNS(HTML_NS, 'div'); + let li = document.createXULElement('richlistitem'); + let div = document.createElement('div'); - let checkbox = document.createElementNS(HTML_NS, 'input'); + let checkbox = document.createElement('input'); checkbox.type = 'checkbox'; checkbox.id = d.locale; // Store properties on element @@ -91,7 +89,7 @@ var Zotero_Dictionary_Manager = new function () { } checkbox.setAttribute('tabindex', -1); - let label = document.createElementNS(HTML_NS, 'label'); + let label = document.createElement('label'); label.setAttribute('for', d.locale); // Add " (update available)" if (updateMap.has(d.id)) { diff --git a/chrome/content/zotero/editContextMenu.js b/chrome/content/zotero/editContextMenu.js index f586bc346e..4691fc01fd 100644 --- a/chrome/content/zotero/editContextMenu.js +++ b/chrome/content/zotero/editContextMenu.js @@ -79,7 +79,7 @@ window.addEventListener( ); function createContentAreaContextMenuItem(name) { - let item = document.createElement('menuitem'); + let item = document.createXULElement('menuitem'); item.id = 'context-' + name.toLowerCase(); item.setAttribute('label', Zotero.Intl.strings[name + 'Cmd.label']); item.setAttribute('accesskey', Zotero.Intl.strings[name + 'Cmd.accesskey']); @@ -88,18 +88,18 @@ function createContentAreaContextMenuItem(name) { } function createContentAreaContextMenu() { - let menupopup = document.createElement('menupopup'); + let menupopup = document.createXULElement('menupopup'); menupopup.id = 'contentAreaContextMenu'; menupopup.appendChild(createContentAreaContextMenuItem('undo')); - let undoSep = document.createElement('menuseparator'); + let undoSep = document.createXULElement('menuseparator'); undoSep.id = 'context-sep-undo'; menupopup.appendChild(undoSep); menupopup.appendChild(createContentAreaContextMenuItem('cut')); menupopup.appendChild(createContentAreaContextMenuItem('copy')); menupopup.appendChild(createContentAreaContextMenuItem('paste')); menupopup.appendChild(createContentAreaContextMenuItem('delete')); - let pasteSep = document.createElement('menuseparator'); + let pasteSep = document.createXULElement('menuseparator'); pasteSep.id = 'context-sep-paste'; menupopup.appendChild(pasteSep); menupopup.appendChild(createContentAreaContextMenuItem('selectAll')); diff --git a/chrome/content/zotero/elements/itemBox.js b/chrome/content/zotero/elements/itemBox.js index 85b6f4ba95..c0ebabbe55 100644 --- a/chrome/content/zotero/elements/itemBox.js +++ b/chrome/content/zotero/elements/itemBox.js @@ -2331,8 +2331,6 @@ // don't overlap. if (!this._updateRetracted) { this._updateRetracted = Zotero.serial(async function (item) { - var htmlNS = 'http://www.w3.org/1999/xhtml'; - var show = Zotero.Retractions.isRetracted(item); if (!show) { this._id('retraction-box').hidden = true; @@ -2363,8 +2361,8 @@ elem.hidden = false; elem.textContent = ''; for (let reason of data.reasons) { - let dt = document.createElementNS(htmlNS, 'dt'); - let dd = document.createElementNS(htmlNS, 'dd'); + let dt = document.createElement('dt'); + let dd = document.createElement('dd'); dt.textContent = reason; dd.textContent = Zotero.Retractions.getReasonDescription(reason); @@ -2385,7 +2383,7 @@ if (data.doi || data.pmid) { let div = this._id('retraction-notice'); div.textContent = ''; - let a = document.createElementNS(htmlNS, 'a'); + let a = document.createElement('a'); a.textContent = Zotero.getString('retraction.notice'); if (data.doi) { a.href = 'https://doi.org/' + data.doi; @@ -2405,13 +2403,13 @@ div.hidden = false; div.textContent = ''; - let p = document.createElementNS(htmlNS, 'p'); + let p = document.createElement('p'); p.textContent = Zotero.getString('retraction.details'); - let ul = document.createElementNS(htmlNS, 'ul'); + let ul = document.createElement('ul'); for (let url of data.urls) { - let li = document.createElementNS(htmlNS, 'li'); - let a = document.createElementNS(htmlNS, 'a'); + let li = document.createElement('li'); + let a = document.createElement('a'); url = url.replace(/^http:/, 'https:'); a.href = url; a.textContent = url; @@ -2438,7 +2436,7 @@ creditElem.appendChild(document.createTextNode(part.text)); } else if (part.type == 'link') { - let a = document.createElementNS(htmlNS, 'a'); + let a = document.createElement('a'); a.href = part.attributes.href; a.textContent = part.text; creditElem.appendChild(a); diff --git a/chrome/content/zotero/elements/tagsBox.js b/chrome/content/zotero/elements/tagsBox.js index c692bf146b..a41271e2ec 100644 --- a/chrome/content/zotero/elements/tagsBox.js +++ b/chrome/content/zotero/elements/tagsBox.js @@ -286,7 +286,7 @@ var label = this.createValueElement(name, tabindex); if (this.editable) { - var remove = document.createElement("label"); + var remove = document.createXULElement("label"); remove.setAttribute('value', '-'); remove.setAttribute('class', 'zotero-clicky zotero-clicky-minus'); remove.setAttribute('tabindex', -1); @@ -371,7 +371,7 @@ createValueElement(valueText, tabindex) { - var valueElement = document.createElement("label"); + var valueElement = document.createXULElement("label"); valueElement.setAttribute('fieldname', 'tag'); valueElement.setAttribute('flex', 1); valueElement.className = 'zotero-box-label'; diff --git a/chrome/content/zotero/import/importWizard.js b/chrome/content/zotero/import/importWizard.js index 3d16905b72..9b9c3d2ecf 100644 --- a/chrome/content/zotero/import/importWizard.js +++ b/chrome/content/zotero/import/importWizard.js @@ -256,8 +256,7 @@ var Zotero_Import_Wizard = { catch (e) { if (e.message == 'Encrypted Mendeley database') { let url = 'https://www.zotero.org/support/kb/mendeley_import'; - let HTML_NS = 'http://www.w3.org/1999/xhtml' - let elem = document.createElementNS(HTML_NS, 'div'); + let elem = document.createElement('div'); elem.innerHTML = `The selected Mendeley database cannot be read, likely because it ` + `is encrypted. See How do I import a ` + `Mendeley library into Zotero? for more information.` diff --git a/chrome/content/zotero/integration/addCitationDialog.js b/chrome/content/zotero/integration/addCitationDialog.js index db25f5cab9..d9fe910546 100644 --- a/chrome/content/zotero/integration/addCitationDialog.js +++ b/chrome/content/zotero/integration/addCitationDialog.js @@ -117,7 +117,7 @@ var Zotero_Citation_Dialog = new function () { var locator = locators[value]; var locatorLabel = Zotero.getString('citation.locator.'+locator.replace(/\s/g,'')); // add to list of labels - var child = document.createElement("menuitem"); + var child = document.createXULElement("menuitem"); child.setAttribute("value", value); child.setAttribute("label", locatorLabel); label_list.appendChild(child); diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js index 351e63c1f5..8a204ecade 100644 --- a/chrome/content/zotero/integration/quickFormat.js +++ b/chrome/content/zotero/integration/quickFormat.js @@ -122,7 +122,7 @@ var Zotero_QuickFormat = new function () { var locatorLabel = Zotero.getString('citation.locator.'+locator.replace(/\s/g,'')); // add to list of labels - var child = document.createElement("menuitem"); + var child = document.createXULElement("menuitem"); child.setAttribute("value", locator); child.setAttribute("label", locatorLabel); labelList.appendChild(child); @@ -620,7 +620,7 @@ var Zotero_QuickFormat = new function () { var publicationTitle = item.getField("publicationTitle", false, true); if(publicationTitle) { - var label = document.createElement("label"); + var label = document.createXULElement("label"); label.setAttribute("value", publicationTitle); label.setAttribute("crop", "end"); label.style.fontStyle = "italic"; @@ -652,7 +652,7 @@ var Zotero_QuickFormat = new function () { if(i != 0) str += ", "; if(typeof node === "object") { - var label = document.createElement("label"); + var label = document.createXULElement("label"); label.setAttribute("value", str); label.setAttribute("crop", "end"); infoHbox.appendChild(label); @@ -666,7 +666,7 @@ var Zotero_QuickFormat = new function () { 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("crop", "end"); label.setAttribute("flex", "1"); @@ -677,13 +677,13 @@ var Zotero_QuickFormat = new function () { * Creates an item to be added to the item list */ function _buildListItem(item) { - var titleNode = document.createElement("label"); + var titleNode = document.createXULElement("label"); titleNode.setAttribute("class", "citation-dialog title"); titleNode.setAttribute("flex", "1"); titleNode.setAttribute("crop", "end"); titleNode.setAttribute("value", item.getDisplayTitle()); - var infoNode = document.createElement("hbox"); + var infoNode = document.createXULElement("hbox"); infoNode.setAttribute("class", "citation-dialog info"); _buildItemDescription(item, infoNode); @@ -703,7 +703,7 @@ var Zotero_QuickFormat = new function () { * Creates a list separator to be added to the item list */ function _buildListSeparator(labelText, loading) { - var titleNode = document.createElement("label"); + var titleNode = document.createXULElement("label"); titleNode.setAttribute("class", "citation-dialog separator-title"); titleNode.setAttribute("flex", "1"); titleNode.setAttribute("crop", "end"); diff --git a/chrome/content/zotero/itemTree.jsx b/chrome/content/zotero/itemTree.jsx index 175d8b9da8..2e669ac8ed 100644 --- a/chrome/content/zotero/itemTree.jsx +++ b/chrome/content/zotero/itemTree.jsx @@ -41,7 +41,6 @@ const CHILD_INDENT = 12; 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 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 var ItemTree = class ItemTree extends LibraryTree { @@ -132,7 +131,7 @@ var ItemTree = class ItemTree extends LibraryTree { this._itemTreeLoadingDeferred.resolve(); // 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 - let elem = this._dragImageContainer = document.createElementNS(HTML_NS, "div"); + let elem = this._dragImageContainer = document.createElement("div"); elem.style.width = "100%"; elem.style.height = "2000px"; elem.style.position = "absolute"; @@ -2621,7 +2620,7 @@ var ItemTree = class ItemTree extends LibraryTree { if (this._titleMarkup.hasOwnProperty(token)) { let markup = this._titleMarkup[token]; if (markup.beginsTag) { - let node = document.createElementNS(HTML_NS, markup.beginsTag); + let node = document.createElement(markup.beginsTag); if (markup.style) { Object.assign(node.style, markup.style); } @@ -2663,14 +2662,14 @@ var ItemTree = class ItemTree extends LibraryTree { } _renderPrimaryCell(index, data, column) { - let span = document.createElementNS(HTML_NS, 'span'); + let span = document.createElement('span'); span.className = `cell ${column.className}`; span.classList.add('primary'); // Add twisty, icon, tag swatches and retraction indicator let twisty; if (this.isContainerEmpty(index)) { - twisty = document.createElementNS(HTML_NS, 'span'); + twisty = document.createElement('span'); twisty.classList.add("spacer-twisty"); } else { @@ -2716,7 +2715,7 @@ var ItemTree = class ItemTree extends LibraryTree { Zotero.debug(e, 1); } - let textSpan = document.createElementNS(HTML_NS, 'span'); + let textSpan = document.createElement('span'); let textWithFullStop = this._renderItemTitle(data, textSpan); if (!textWithFullStop.match(/\.$/)) { textWithFullStop += '.'; @@ -2735,7 +2734,7 @@ var ItemTree = class ItemTree extends LibraryTree { } _renderHasAttachmentCell(index, data, column) { - let span = document.createElementNS(HTML_NS, 'span'); + let span = document.createElement('span'); span.className = `cell ${column.className}`; if (this.collectionTreeRow.isTrash()) return span; @@ -2865,7 +2864,7 @@ var ItemTree = class ItemTree extends LibraryTree { div.innerHTML = ""; } else { - div = document.createElementNS(HTML_NS, 'div'); + div = document.createElement('div'); div.className = "row"; } @@ -2878,7 +2877,7 @@ var ItemTree = class ItemTree extends LibraryTree { if (this._dropRow == index) { let span; 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"; div.appendChild(span); } else { @@ -3252,13 +3251,12 @@ var ItemTree = class ItemTree extends LibraryTree { if (this.collectionTreeRow && !this.rowCount) { let doc = this._ownerDocument; - let ns = 'http://www.w3.org/1999/xhtml'; let div; // My Library and no groups if (this.collectionTreeRow.isLibrary() && !Zotero.Groups.getAll().length) { - div = doc.createElementNS(ns, 'div'); - let p = doc.createElementNS(ns, 'p'); + div = doc.createElement('div'); + let p = doc.createElement('p'); let html = Zotero.getString( 'pane.items.intro.text1', [ @@ -3271,7 +3269,7 @@ var ItemTree = class ItemTree extends LibraryTree { p.innerHTML = html; div.appendChild(p); - p = doc.createElementNS(ns, 'p'); + p = doc.createElement('p'); html = Zotero.getString( 'pane.items.intro.text2', [ @@ -3290,7 +3288,7 @@ var ItemTree = class ItemTree extends LibraryTree { p.innerHTML = html; div.appendChild(p); - p = doc.createElementNS(ns, 'p'); + p = doc.createElement('p'); html = Zotero.getString('pane.items.intro.text3', [Zotero.clientName]); // Encode special chars, which shouldn't exist html = Zotero.Utilities.htmlSpecialChars(html); @@ -3323,17 +3321,17 @@ var ItemTree = class ItemTree extends LibraryTree { } // My Publications else if (this.collectionTreeRow.isPublications()) { - div = doc.createElementNS(ns, 'div'); + div = doc.createElement('div'); 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); div.appendChild(p); - p = doc.createElementNS(ns, 'p'); + p = doc.createElement('p'); p.textContent = Zotero.getString('publications.intro.text2'); div.appendChild(p); - p = doc.createElementNS(ns, 'p'); + p = doc.createElement('p'); let html = Zotero.getString('publications.intro.text3'); // Convert tags to placeholders html = html.replace('', ':b:').replace('', ':/b:'); @@ -3821,7 +3819,7 @@ var ItemTree = class ItemTree extends LibraryTree { var icon = getDOMElement(iconClsName); if (!icon) { Zotero.debug('Could not find tree icon for "' + itemType + '"'); - return document.createElementNS(HTML_NS, 'span'); + return document.createElement('span'); } return icon; } @@ -3832,7 +3830,7 @@ var ItemTree = class ItemTree extends LibraryTree { } _getTagSwatch(tag, color) { - let span = document.createElementNS(HTML_NS, 'span'); + let span = document.createElement('span'); span.className = 'tag-swatch'; // If only emoji, display directly // diff --git a/chrome/content/zotero/publicationsDialog.js b/chrome/content/zotero/publicationsDialog.js index 94b367a067..5e02838659 100644 --- a/chrome/content/zotero/publicationsDialog.js +++ b/chrome/content/zotero/publicationsDialog.js @@ -280,21 +280,21 @@ var Zotero_Publications_Dialog = new function () { var div = currentPage.getElementsByAttribute('class', 'license-description')[0]; } else { - let hbox = document.createElement('hbox'); + let hbox = document.createXULElement('hbox'); hbox.align = "center"; groupbox.appendChild(hbox); - var icon = document.createElement('image'); + var icon = document.createXULElement('image'); icon.className = 'license-icon'; icon.setAttribute('style', 'width: 88px'); hbox.appendChild(icon); - let sep = document.createElement('separator'); + let sep = document.createXULElement('separator'); sep.orient = 'vertical'; sep.setAttribute('style', 'width: 10px'); hbox.appendChild(sep); - var div = document.createElementNS('http://www.w3.org/1999/xhtml', 'div'); + var div = document.createElement('div'); div.className = 'license-description'; div.setAttribute('style', 'width: 400px'); hbox.appendChild(div); diff --git a/chrome/content/zotero/rtfScan.jsx b/chrome/content/zotero/rtfScan.jsx index edc09eb785..e049fd16ba 100644 --- a/chrome/content/zotero/rtfScan.jsx +++ b/chrome/content/zotero/rtfScan.jsx @@ -702,7 +702,7 @@ var Zotero_RTFScan = new function() { div.innerHTML = ""; } else { - div = document.createElementNS("http://www.w3.org/1999/xhtml", 'div'); + div = document.createElement('div'); div.className = "row"; } @@ -721,15 +721,15 @@ var Zotero_RTFScan = new function() { { passive: true }); } else { - twisty = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); + twisty = document.createElement('span'); 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.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.appendChild(twisty); span.appendChild(textSpan); @@ -737,7 +737,7 @@ var Zotero_RTFScan = new function() { div.appendChild(span); } 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}`; if (row.parent) { if (row.action) { @@ -753,7 +753,7 @@ var Zotero_RTFScan = new function() { div.appendChild(span); } else { - let span = document.createElementNS("http://www.w3.org/1999/xhtml", 'span'); + let span = document.createElement('span'); span.className = `cell ${column.className}`; span.innerText = row[column.dataKey] || ""; div.appendChild(span); diff --git a/chrome/content/zotero/tagColorChooser.js b/chrome/content/zotero/tagColorChooser.js index 21a364c6bb..d71c9c727a 100644 --- a/chrome/content/zotero/tagColorChooser.js +++ b/chrome/content/zotero/tagColorChooser.js @@ -128,7 +128,7 @@ var Zotero_Tag_Color_Chooser = new function() { var msg = Zotero.getString('tagColorChooser.numberKeyInstructions'); var matches = msg.match(/(.+)\$NUMBER(.+)/); - var num = document.createElement('label'); + var num = document.createXULElement('label'); num.id = 'number-key'; num.setAttribute('value', parseInt(tagPosition.value) + 1); diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js index a09e58a7f6..dedee8e2cc 100644 --- a/chrome/content/zotero/xpcom/data/tags.js +++ b/chrome/content/zotero/xpcom/data/tags.js @@ -826,7 +826,7 @@ Zotero.Tags = new function() { .getService(Components.interfaces.nsIAppShellService) .hiddenDOMWindow; var doc = win.document; - var canvas = doc.createElementNS('http://www.w3.org/1999/xhtml', 'canvas'); + var canvas = doc.createElement('canvas'); var width = extraImageWidth + (retracted diff --git a/chrome/content/zotero/xpcom/pdfWorker/manager.js b/chrome/content/zotero/xpcom/pdfWorker/manager.js index cb23029218..e2a8a060bd 100644 --- a/chrome/content/zotero/xpcom/pdfWorker/manager.js +++ b/chrome/content/zotero/xpcom/pdfWorker/manager.js @@ -475,7 +475,7 @@ class PDFRenderer { return new Promise((resolve) => { this._browser = Zotero.Browser.createHiddenBrowser(); let doc = this._browser.ownerDocument; - let container = doc.createElement('hbox'); + let container = doc.createXULElement('hbox'); container.style.position = 'fixed'; container.style.zIndex = '-1'; container.append(this._browser); diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index 9fb053f387..435cc7dc2c 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -32,7 +32,6 @@ if (!Zotero.Sync) { // Initialized as Zotero.Sync.Runner in zotero.js Zotero.Sync.Runner_Module = function (options = {}) { const stopOnError = false; - const HTML_NS = 'http://www.w3.org/1999/xhtml'; Zotero.defineProperty(this, 'enabled', { get: () => { @@ -1692,7 +1691,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { if (_tooltipMessages.length) { _currentTooltipMessages.textContent = ''; for (let message of _tooltipMessages) { - let elem = _currentTooltipMessages.ownerDocument.createElementNS(HTML_NS, 'p'); + let elem = _currentTooltipMessages.ownerDocument.createElement('p'); elem.textContent = message; _currentTooltipMessages.appendChild(elem); } diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index a93737cb62..a18afaf95d 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -1678,7 +1678,7 @@ Zotero.Utilities.Internal = { var selectedIndex = 0; var i = 0; for (let library of libraries) { - let menuitem = menulist.ownerDocument.createElement('menuitem'); + let menuitem = menulist.ownerDocument.createXULElement('menuitem'); menuitem.value = library.libraryID; menuitem.setAttribute('label', library.name); menupopup.appendChild(menuitem); @@ -1694,14 +1694,13 @@ Zotero.Utilities.Internal = { buildLibraryMenuHTML: function (select, libraries, selectedLibraryID) { - var namespaceURI = 'http://www.w3.org/1999/xhtml'; while (select.hasChildNodes()) { select.removeChild(select.firstChild); } var selectedIndex = 0; var i = 0; 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('data-editable', library.editable ? 'true' : 'false'); option.setAttribute('data-filesEditable', library.filesEditable ? 'true' : 'false'); diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index f2d1b8b065..1bb96b7dd6 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1453,8 +1453,6 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); * @return void */ 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. // The message is also cleared when the meters are hidden. _progressMessage = msg = (msg === undefined ? _progressMessage : msg) || ""; @@ -1489,7 +1487,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); let id = 'zotero-pane-progressmeter'; let progressMeter = doc.getElementById(id); if (!progressMeter) { - progressMeter = doc.createElementNS(HTML_NS, 'progress'); + progressMeter = doc.createElement('progress'); progressMeter.id = id; } if (determinate) { @@ -1647,10 +1645,10 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); button.id = 'zotero-tb-search-menu-button'; button.setAttribute('type', 'menu'); - var menupopup = document.createElement('menupopup'); + var menupopup = document.createXULElement('menupopup'); for (var i in modes) { - var menuitem = document.createElement('menuitem'); + var menuitem = document.createXULElement('menuitem'); menuitem.setAttribute('id', prefix + i); menuitem.setAttribute('label', modes[i].label); menuitem.setAttribute('name', 'searchMode'); diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 7f1511c915..ff0e421812 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -3248,7 +3248,7 @@ var ZoteroPane = new function() if (eligibleAttachments.length > 1) { show.add(m.createNoteFromAnnotationsMenu); for (let attachment of attachmentsWithAnnotations) { - let menuitem = document.createElement('menuitem'); + let menuitem = document.createXULElement('menuitem'); menuitem.setAttribute('label', attachment.getDisplayTitle()); menuitem.onclick = () => { ZoteroPane.createNoteFromAnnotationsForAttachment(attachment); @@ -3626,7 +3626,7 @@ var ZoteroPane = new function() if (typeof content == 'string') { let contentParts = content.split("\n\n"); for (let part of contentParts) { - let desc = document.createElement('description'); + let desc = document.createXULElement('description'); desc.appendChild(document.createTextNode(part)); elem.appendChild(desc); } diff --git a/resource/word-processor-plugin-installer.js b/resource/word-processor-plugin-installer.js index c0c90a86d1..3726402671 100644 --- a/resource/word-processor-plugin-installer.js +++ b/resource/word-processor-plugin-installer.js @@ -191,14 +191,14 @@ ZoteroPluginInstaller.prototype = { showPreferences: function(document) { this.prefPaneDoc = document; var isInstalled = this.isInstalled(), - groupbox = document.createElement("groupbox"); + groupbox = document.createXULElement("groupbox"); groupbox.id = this._addon.EXTENSION_DIR; - var caption = document.createElement("caption"); + var caption = document.createXULElement("caption"); caption.setAttribute("label", this._addon.APP); groupbox.appendChild(caption); - var description = document.createElement("description"); + var description = document.createXULElement("description"); description.style.width = "45em"; description.appendChild(document.createTextNode( isInstalled ? @@ -206,9 +206,9 @@ ZoteroPluginInstaller.prototype = { Zotero.getString('zotero.preferences.wordProcessors.notInstalled', this._addon.APP))); groupbox.appendChild(description); - var hbox = document.createElement("hbox"); + var hbox = document.createXULElement("hbox"); hbox.setAttribute("pack", "center"); - var button = document.createElement("button"), + var button = document.createXULElement("button"), addon = this._addon; button.setAttribute("label", (isInstalled ?