Rollup merge of #118296 - notriddle:notriddle/main-dom, r=GuillaumeGomez

rustdoc: replace `elemIsInParent` with `Node.contains`

According to [MDN], this function is compatible with:

* Chrome 16 and Edge 12
* Firefox 9
* Safari 1.1 and iOS Safari 1

These browsers are well within our [support matrix], which requires compatibility with Chrome 118, Firefox 115, Safari 17, and Edge 119.

[MDN]: https://developer.mozilla.org/en-US/docs/Web/API/Node/contains#browser_compatibility
[support matrix]: https://browsersl.ist/#q=last+2+Chrome+versions%2C+last+1+Firefox+version%2C+Firefox+ESR%2C+last+1+Safari+version%2C+last+1+iOS+version%2C+last+1+Edge+version%2C+last+1+UCAndroid+version
This commit is contained in:
Guillaume Gomez 2023-11-26 15:44:53 +01:00 committed by GitHub
commit bb5bbbf4ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 21 deletions

View File

@ -25,19 +25,9 @@ function showMain() {
removeClass(document.getElementById(MAIN_ID), "hidden"); removeClass(document.getElementById(MAIN_ID), "hidden");
} }
function elemIsInParent(elem, parent) {
while (elem && elem !== document.body) {
if (elem === parent) {
return true;
}
elem = elem.parentElement;
}
return false;
}
function blurHandler(event, parentElem, hideCallback) { function blurHandler(event, parentElem, hideCallback) {
if (!elemIsInParent(document.activeElement, parentElem) && if (!parentElem.contains(document.activeElement) &&
!elemIsInParent(event.relatedTarget, parentElem) !parentElem.contains(event.relatedTarget)
) { ) {
hideCallback(); hideCallback();
} }
@ -1118,7 +1108,7 @@ function preLoadCss(cssUrl) {
if (ev.pointerType !== "mouse") { if (ev.pointerType !== "mouse") {
return; return;
} }
if (!e.TOOLTIP_FORCE_VISIBLE && !elemIsInParent(ev.relatedTarget, e)) { if (!e.TOOLTIP_FORCE_VISIBLE && !e.contains(ev.relatedTarget)) {
// See "Tooltip pointer leave gesture" below. // See "Tooltip pointer leave gesture" below.
setTooltipHoverTimeout(e, false); setTooltipHoverTimeout(e, false);
addClass(wrapper, "fade-out"); addClass(wrapper, "fade-out");
@ -1178,10 +1168,10 @@ function preLoadCss(cssUrl) {
function tooltipBlurHandler(event) { function tooltipBlurHandler(event) {
if (window.CURRENT_TOOLTIP_ELEMENT && if (window.CURRENT_TOOLTIP_ELEMENT &&
!elemIsInParent(document.activeElement, window.CURRENT_TOOLTIP_ELEMENT) && !window.CURRENT_TOOLTIP_ELEMENT.contains(document.activeElement) &&
!elemIsInParent(event.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT) && !window.CURRENT_TOOLTIP_ELEMENT.contains(event.relatedTarget) &&
!elemIsInParent(document.activeElement, window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE) && !window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.contains(document.activeElement) &&
!elemIsInParent(event.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE) !window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.contains(event.relatedTarget)
) { ) {
// Work around a difference in the focus behaviour between Firefox, Chrome, and Safari. // Work around a difference in the focus behaviour between Firefox, Chrome, and Safari.
// When I click the button on an already-opened tooltip popover, Safari // When I click the button on an already-opened tooltip popover, Safari
@ -1248,8 +1238,8 @@ function preLoadCss(cssUrl) {
if (ev.pointerType !== "mouse") { if (ev.pointerType !== "mouse") {
return; return;
} }
if (!e.TOOLTIP_FORCE_VISIBLE && if (!e.TOOLTIP_FORCE_VISIBLE && window.CURRENT_TOOLTIP_ELEMENT &&
!elemIsInParent(ev.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT)) { !window.CURRENT_TOOLTIP_ELEMENT.contains(ev.relatedTarget)) {
// Tooltip pointer leave gesture: // Tooltip pointer leave gesture:
// //
// Designing a good hover microinteraction is a matter of guessing user // Designing a good hover microinteraction is a matter of guessing user

View File

@ -1,6 +1,6 @@
// Local js definitions: // Local js definitions:
/* global getSettingValue, updateLocalStorage, updateTheme */ /* global getSettingValue, updateLocalStorage, updateTheme */
/* global addClass, removeClass, onEach, onEachLazy, blurHandler, elemIsInParent */ /* global addClass, removeClass, onEach, onEachLazy, blurHandler */
/* global MAIN_ID, getVar, getSettingsButton */ /* global MAIN_ID, getVar, getSettingsButton */
"use strict"; "use strict";
@ -232,7 +232,7 @@
const settingsButton = getSettingsButton(); const settingsButton = getSettingsButton();
const settingsMenu = document.getElementById("settings"); const settingsMenu = document.getElementById("settings");
settingsButton.onclick = event => { settingsButton.onclick = event => {
if (elemIsInParent(event.target, settingsMenu)) { if (settingsMenu.contains(event.target)) {
return; return;
} }
event.preventDefault(); event.preventDefault();