Merge pull request #15035 from Snuffleupagus/prefer-modern-dom-apis-2

Use modern DOM methods a bit more (PR 15031 follow-up)
This commit is contained in:
Jonas Jenwald 2022-06-17 19:37:43 +02:00 committed by GitHub
commit be2dfe45f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 9 deletions

View File

@ -27,6 +27,7 @@
- Removes window._ assignment.
- Remove compatibility code for OldIE.
- Replaces `String.prototype.substr()` with `String.prototype.substring()`.
- Replaces one `Node.insertBefore()` with `Element.prepend()`.
- Removes `fireL10nReadyEvent` since the "localized" event it dispatches
is unused and may clash with an identically named event in the viewer.
*/
@ -921,7 +922,7 @@ document.webL10n = (function(window, document, undefined) {
// first element child.
if (!found) {
var textNode = document.createTextNode(data[gTextProp]);
element.insertBefore(textNode, element.firstChild);
element.prepend(textNode);
}
}
delete data[gTextProp];

View File

@ -1507,7 +1507,7 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
noneOptionElement.value = " ";
noneOptionElement.setAttribute("hidden", true);
noneOptionElement.setAttribute("selected", true);
selectElement.insertBefore(noneOptionElement, selectElement.firstChild);
selectElement.prepend(noneOptionElement);
removeEmptyEntry = () => {
noneOptionElement.remove();
@ -1581,13 +1581,16 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
},
insert(event) {
const { index, displayValue, exportValue } = event.detail.insert;
const selectChild = selectElement.children[index];
const optionElement = document.createElement("option");
optionElement.textContent = displayValue;
optionElement.value = exportValue;
selectElement.insertBefore(
optionElement,
selectElement.children[index]
);
if (selectChild) {
selectChild.before(optionElement);
} else {
selectElement.append(optionElement);
}
storage.setValue(id, {
value: getValue(event, /* isExport */ true),
items: getItems(event),

View File

@ -87,7 +87,7 @@ class BaseTreeViewer {
this._toggleTreeItem(div, shouldShowAll);
}
};
div.insertBefore(toggler, div.firstChild);
div.prepend(toggler);
}
/**

View File

@ -51,7 +51,7 @@ class OverlayManager {
const style = document.createElement("style");
style.textContent = PDFJSDev.eval("DIALOG_POLYFILL_CSS");
document.head.insertBefore(style, document.head.firstElementChild);
document.head.prepend(style);
}
}

View File

@ -176,7 +176,7 @@ class TextHighlighter {
let div = textDivs[divIdx];
if (div.nodeType === Node.TEXT_NODE) {
const span = document.createElement("span");
div.parentNode.insertBefore(span, div);
div.before(span);
span.append(div);
textDivs[divIdx] = span;
div = span;