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

rustdoc: replace elemIsInParent with Node.contains #118296

Merged
merged 1 commit into from
Nov 26, 2023
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
28 changes: 9 additions & 19 deletions src/librustdoc/html/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,9 @@ function showMain() {
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) {
if (!elemIsInParent(document.activeElement, parentElem) &&
!elemIsInParent(event.relatedTarget, parentElem)
if (!parentElem.contains(document.activeElement) &&
!parentElem.contains(event.relatedTarget)
) {
hideCallback();
}
Expand Down Expand Up @@ -1118,7 +1108,7 @@ function preLoadCss(cssUrl) {
if (ev.pointerType !== "mouse") {
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.
setTooltipHoverTimeout(e, false);
addClass(wrapper, "fade-out");
Expand Down Expand Up @@ -1178,10 +1168,10 @@ function preLoadCss(cssUrl) {

function tooltipBlurHandler(event) {
if (window.CURRENT_TOOLTIP_ELEMENT &&
!elemIsInParent(document.activeElement, window.CURRENT_TOOLTIP_ELEMENT) &&
!elemIsInParent(event.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT) &&
!elemIsInParent(document.activeElement, window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE) &&
!elemIsInParent(event.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE)
!window.CURRENT_TOOLTIP_ELEMENT.contains(document.activeElement) &&
!window.CURRENT_TOOLTIP_ELEMENT.contains(event.relatedTarget) &&
!window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.contains(document.activeElement) &&
!window.CURRENT_TOOLTIP_ELEMENT.TOOLTIP_BASE.contains(event.relatedTarget)
) {
// 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
Expand Down Expand Up @@ -1248,8 +1238,8 @@ function preLoadCss(cssUrl) {
if (ev.pointerType !== "mouse") {
return;
}
if (!e.TOOLTIP_FORCE_VISIBLE &&
!elemIsInParent(ev.relatedTarget, window.CURRENT_TOOLTIP_ELEMENT)) {
if (!e.TOOLTIP_FORCE_VISIBLE && window.CURRENT_TOOLTIP_ELEMENT &&
!window.CURRENT_TOOLTIP_ELEMENT.contains(ev.relatedTarget)) {
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved
// Tooltip pointer leave gesture:
//
// Designing a good hover microinteraction is a matter of guessing user
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/static/js/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Local js definitions:
/* global getSettingValue, updateLocalStorage, updateTheme */
/* global addClass, removeClass, onEach, onEachLazy, blurHandler, elemIsInParent */
/* global addClass, removeClass, onEach, onEachLazy, blurHandler */
/* global MAIN_ID, getVar, getSettingsButton */

"use strict";
Expand Down Expand Up @@ -232,7 +232,7 @@
const settingsButton = getSettingsButton();
const settingsMenu = document.getElementById("settings");
settingsButton.onclick = event => {
if (elemIsInParent(event.target, settingsMenu)) {
if (settingsMenu.contains(event.target)) {
return;
}
event.preventDefault();
Expand Down
Loading