Skip to content

Commit bb5bbbf

Browse files
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
2 parents 0b8a61b + bdcf916 commit bb5bbbf

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

Diff for: src/librustdoc/html/static/js/main.js

+9-19
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,9 @@ function showMain() {
2525
removeClass(document.getElementById(MAIN_ID), "hidden");
2626
}
2727

28-
function elemIsInParent(elem, parent) {
29-
while (elem && elem !== document.body) {
30-
if (elem === parent) {
31-
return true;
32-
}
33-
elem = elem.parentElement;
34-
}
35-
return false;
36-
}
37-
3828
function blurHandler(event, parentElem, hideCallback) {
39-
if (!elemIsInParent(document.activeElement, parentElem) &&
40-
!elemIsInParent(event.relatedTarget, parentElem)
29+
if (!parentElem.contains(document.activeElement) &&
30+
!parentElem.contains(event.relatedTarget)
4131
) {
4232
hideCallback();
4333
}
@@ -1118,7 +1108,7 @@ function preLoadCss(cssUrl) {
11181108
if (ev.pointerType !== "mouse") {
11191109
return;
11201110
}
1121-
if (!e.TOOLTIP_FORCE_VISIBLE && !elemIsInParent(ev.relatedTarget, e)) {
1111+
if (!e.TOOLTIP_FORCE_VISIBLE && !e.contains(ev.relatedTarget)) {
11221112
// See "Tooltip pointer leave gesture" below.
11231113
setTooltipHoverTimeout(e, false);
11241114
addClass(wrapper, "fade-out");
@@ -1178,10 +1168,10 @@ function preLoadCss(cssUrl) {
11781168

11791169
function tooltipBlurHandler(event) {
11801170
if (window.CURRENT_TOOLTIP_ELEMENT &&
1181-
!elemIsInParent(document.activeElement, window.CURRENT_TOOLTIP_ELEMENT) &&
1182-
!elemIsInParent(event.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT) &&
1183-
!elemIsInParent(document.activeElement, window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE) &&
1184-
!elemIsInParent(event.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE)
1171+
!window.CURRENT_TOOLTIP_ELEMENT.contains(document.activeElement) &&
1172+
!window.CURRENT_TOOLTIP_ELEMENT.contains(event.relatedTarget) &&
1173+
!window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.contains(document.activeElement) &&
1174+
!window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.contains(event.relatedTarget)
11851175
) {
11861176
// Work around a difference in the focus behaviour between Firefox, Chrome, and Safari.
11871177
// When I click the button on an already-opened tooltip popover, Safari
@@ -1248,8 +1238,8 @@ function preLoadCss(cssUrl) {
12481238
if (ev.pointerType !== "mouse") {
12491239
return;
12501240
}
1251-
if (!e.TOOLTIP_FORCE_VISIBLE &&
1252-
!elemIsInParent(ev.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT)) {
1241+
if (!e.TOOLTIP_FORCE_VISIBLE && window.CURRENT_TOOLTIP_ELEMENT &&
1242+
!window.CURRENT_TOOLTIP_ELEMENT.contains(ev.relatedTarget)) {
12531243
// Tooltip pointer leave gesture:
12541244
//
12551245
// Designing a good hover microinteraction is a matter of guessing user

Diff for: src/librustdoc/html/static/js/settings.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Local js definitions:
22
/* global getSettingValue, updateLocalStorage, updateTheme */
3-
/* global addClass, removeClass, onEach, onEachLazy, blurHandler, elemIsInParent */
3+
/* global addClass, removeClass, onEach, onEachLazy, blurHandler */
44
/* global MAIN_ID, getVar, getSettingsButton */
55

66
"use strict";
@@ -232,7 +232,7 @@
232232
const settingsButton = getSettingsButton();
233233
const settingsMenu = document.getElementById("settings");
234234
settingsButton.onclick = event => {
235-
if (elemIsInParent(event.target, settingsMenu)) {
235+
if (settingsMenu.contains(event.target)) {
236236
return;
237237
}
238238
event.preventDefault();

0 commit comments

Comments
 (0)