-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Make members explorer highlight the current member being vie…
…wed (#187)
- Loading branch information
1 parent
efe9613
commit deda145
Showing
7 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// @flow | ||
|
||
const toc /*: Map<string, HTMLElement> */ = new Map(); | ||
const css = "page-members-explorer__item--current"; | ||
let current /*: HTMLElement | null */ = null; | ||
|
||
function onIntersectionChange(entries /*: IntersectionObserverEntry[] */) { | ||
for (let i = entries.length - 1; i >= 0; i--) { | ||
const {target, isIntersecting} = entries[i]; | ||
const id = target.getAttribute("data-id"); | ||
const explorerItemElement = toc.get(id); | ||
|
||
explorerItemElement.setAttribute("data-visible", String(isIntersecting)); | ||
} | ||
|
||
let next = null; | ||
for (const [, explorerItemElement] of toc) { | ||
if (explorerItemElement.getAttribute("data-visible") === "true") { | ||
next = explorerItemElement; | ||
} | ||
} | ||
|
||
if (next !== current) { | ||
if (next) next.classList.add(css); | ||
if (current) current.classList.remove(css); | ||
current = next; | ||
} | ||
} | ||
|
||
if (typeof IntersectionObserver !== "undefined") { | ||
const observer = new IntersectionObserver(onIntersectionChange, { | ||
root: null, | ||
rootMargin: "0px", | ||
threshold: [1], | ||
}); | ||
|
||
document.addEventListener("DOMContentLoaded", function() { | ||
for (const explorerItemElement of document.querySelectorAll(".page-members-explorer__item")) { | ||
const targetId = explorerItemElement.getAttribute("data-id"); | ||
const targetElement = document.querySelector(`.member__title[data-id="${targetId}"]`); | ||
|
||
if (!targetElement) { | ||
console.warn(`${targetId} member not found in DOM!`); | ||
continue; | ||
} | ||
|
||
toc.set(targetId, explorerItemElement); | ||
observer.observe(targetElement); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deda145
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ShukantPal,
it's a nice features, but I'm afraid its not working properly, in the screenshot below, I did click on
clearInterval
, but the one being highlighted isgetDelta
, also I noticed that whichever items I click, the one at the bottom of the page is the one being actually highlightedelse, timer and Timer are working now :)