mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Use modern DOM methods a bit more (PR 15031 follow-up)
Apparently the ESLint rule added in PR 15031 wasn't able to catch all cases that can be converted, which is probably not all that surprising given how some of these call-sites look. - Use `Element.prepend()` to insert nodes before all other ones in the element, rather than using `firstChild` with `insertBefore`-calls; see https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend - Fix one *incorrect* `insertBefore` call, in the AnnotationLayer-code. Initially the patch simply changed that to an `Element.before()`-call, however that broke one of the integration-tests. It turns out that the `index` may try to access a non-existent select-child, which triggers undefined behaviour; note the warning in https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore#parameters
This commit is contained in:
parent
1a6ae5f034
commit
4902ad8923
5 changed files with 13 additions and 9 deletions
|
@ -87,7 +87,7 @@ class BaseTreeViewer {
|
|||
this._toggleTreeItem(div, shouldShowAll);
|
||||
}
|
||||
};
|
||||
div.insertBefore(toggler, div.firstChild);
|
||||
div.prepend(toggler);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue