Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use modern DOM methods a bit more (PR 15031 follow-up) #15035

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion external/webL10n/l10n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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];
Expand Down
13 changes: 8 additions & 5 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,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();
Expand Down Expand Up @@ -1573,13 +1573,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),
Expand Down
2 changes: 1 addition & 1 deletion web/base_tree_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class BaseTreeViewer {
this._toggleTreeItem(div, shouldShowAll);
}
};
div.insertBefore(toggler, div.firstChild);
div.prepend(toggler);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion web/overlay_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion web/text_highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down