Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
SHA: 9679799
Reason: push, by backkem

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
backkem and github-actions[bot] committed Feb 4, 2024
1 parent 6a4b001 commit 7f3d5b3
Showing 1 changed file with 27 additions and 66 deletions.
93 changes: 27 additions & 66 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<title>Local Peer-to-Peer API</title>
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<link href="https://www.w3.org/StyleSheets/TR/2021/cg-draft" rel="stylesheet">
<meta content="Bikeshed version e20e08949, updated Wed Jan 24 11:50:28 2024 -0800" name="generator">
<meta content="Bikeshed version d5d58a306, updated Fri Jan 26 16:12:28 2024 -0800" name="generator">
<link href="https://WICG.github.io/local-peer-to-peer/" rel="canonical">
<meta content="57be8da16f00fbbb9c5c792582dac8f6819481b6" name="revision">
<meta content="9679799e46ff0c5b45c9351e22e331cab8d94f1e" name="revision">
<style>/* Boilerplate: style-autolinks */
.css.css, .property.property, .descriptor.descriptor {
color: var(--a-normal-text);
Expand Down Expand Up @@ -692,7 +692,7 @@
<div class="head">
<p data-fill-with="logo"><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2021/logos/W3C" width="72"> </a> </p>
<h1 class="p-name no-ref" id="title">Local Peer-to-Peer API</h1>
<p id="w3c-state"><a href="https://www.w3.org/standards/types#CG-DRAFT">Draft Community Group Report</a>, <time class="dt-updated" datetime="2024-01-25">25 January 2024</time></p>
<p id="w3c-state"><a href="https://www.w3.org/standards/types#CG-DRAFT">Draft Community Group Report</a>, <time class="dt-updated" datetime="2024-02-04">4 February 2024</time></p>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
Expand Down Expand Up @@ -2204,7 +2204,7 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content

function positionDfnPanel(dfnPanel) {
const dfn = dfnPanel.dfn;
const dfnPos = getRootLevelAbsolutePosition(dfn);
const dfnPos = getBounds(dfn);
dfnPanel.style.top = dfnPos.bottom + "px";
dfnPanel.style.left = dfnPos.left + "px";

Expand Down Expand Up @@ -2273,40 +2273,19 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
});
}

// TODO: shared util
// Returns the root-level absolute position {left and top} of element.
function getRootLevelAbsolutePosition(el) {
const boundsRect = el.getBoundingClientRect();
let xPos = 0;
let yPos = 0;

while (el) {
let xScroll = el.scrollLeft;
let yScroll = el.scrollTop;

// Ignore scrolling of body.
if (el.tagName === "BODY") {
xScroll = 0;
yScroll = 0;
}
xPos += (el.offsetLeft - xScroll + el.clientLeft);
yPos += (el.offsetTop - yScroll + el.clientTop);

el = el.offsetParent;
}
function getBounds(el, relativeTo=document.body) {
const relativeRect = relativeTo.getBoundingClientRect();
const elRect = el.getBoundingClientRect();
const top = elRect.top - relativeRect.top;
const left = elRect.left - relativeRect.left;
return {
left: xPos,
top: yPos,
right: xPos + boundsRect.width,
bottom: yPos + boundsRect.height,
};
}

function scrolledIntoView(element) {
const rect = element.getBoundingClientRect();
return (
rect.top > 0 &&
rect.bottom < window.innerHeight
);
top,
left,
bottom: top + elRect.height,
right: left + elRect.width,
}
}

function scrollToTargetAndHighlight(event) {
Expand All @@ -2315,10 +2294,6 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
hash = decodeURIComponent(hash.substring(1));
const dest = document.getElementById(hash);
if (dest) {
// Maybe prevent default scroll.
if (scrolledIntoView(dest)) {
event.preventDefault();
}
dest.classList.add('highlighted');
setTimeout(() => dest.classList.remove('highlighted'), 1000);
}
Expand Down Expand Up @@ -2728,7 +2703,7 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content

function positionRefHint(refHint) {
const link = refHint.forLink;
const linkPos = getRootLevelAbsolutePosition(link);
const linkPos = getBounds(link);
refHint.style.top = linkPos.bottom + "px";
refHint.style.left = linkPos.left + "px";

Expand All @@ -2744,31 +2719,17 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content

// TODO: shared util
// Returns the root-level absolute position {left and top} of element.
function getRootLevelAbsolutePosition(el) {
const boundsRect = el.getBoundingClientRect();
let xPos = 0;
let yPos = 0;

while (el) {
let xScroll = el.scrollLeft;
let yScroll = el.scrollTop;

// Ignore scrolling of body.
if (el.tagName === "BODY") {
xScroll = 0;
yScroll = 0;
}
xPos += (el.offsetLeft - xScroll + el.clientLeft);
yPos += (el.offsetTop - yScroll + el.clientTop);

el = el.offsetParent;
}
function getBounds(el, relativeTo=document.body) {
const relativeRect = relativeTo.getBoundingClientRect();
const elRect = el.getBoundingClientRect();
const top = elRect.top - relativeRect.top;
const left = elRect.left - relativeRect.left;
return {
left: xPos,
top: yPos,
right: xPos + boundsRect.width,
bottom: yPos + boundsRect.height,
};
top,
left,
bottom: top + elRect.height,
right: left + elRect.width,
}
}

function showRefHintListener(e) {
Expand All @@ -2794,7 +2755,7 @@ <h2 class="no-num no-ref heading settled" id="issues-index"><span class="content
}

document.addEventListener("DOMContentLoaded", () => {
document.body.addEventListener("mouseover", showRefHintListener);
document.body.addEventListener("mousedown", showRefHintListener);
document.body.addEventListener("focus", showRefHintListener);

document.body.addEventListener("click", hideAllHintsListener);
Expand Down

0 comments on commit 7f3d5b3

Please sign in to comment.