-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix expand/collapse all on site, make highlightjs lazier #14038
Conversation
84dcb9a
to
bb746e1
Compare
ty for this :D just tried to use expand all button at https://rust-lang.github.io/rust-clippy/master/index.html but can't :( |
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.
just a single nit, it's looking pretty good! (Tested manually)
document.getElementById("expand-all").addEventListener("click", () => toggleExpansion(true)); | ||
document.getElementById("collapse-all").addEventListener("click", () => toggleExpansion(false)); | ||
|
||
document.addEventListener("click", event => { |
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.
This could be more consistent with the code above it if we just used document.getElementsByClassName
. it does exactly what the code looks for, but in a built-in method.
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.
This bit is using event delegation in order to avoid adding ~1500 listeners
Maybe not a noticeable difference but it shaves off a few ms
if (!'IntersectionObserver' in window) { | ||
return; | ||
} | ||
const observer = new IntersectionObserver((entries) => { |
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.
Really smart move here! 👏
bb746e1
to
33bb8af
Compare
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.
LGTM, thanks! ❤️
This fixes the buttons that expand/collapse all the lints in the list, it also makes code block syntax highlighting only happen when the specific lint enters the viewport since highlighting them all at once was fairly heavy
There's also a few miscellaneous inline event handler removals
script.js
and highlightjs are now loaded withdefer
so that the download can start earlierAlso fixes #14048, we were calling highlight on the
pre
in<pre><code>...</code></pre>
but highlightjs wants us to call it on thecode
elementchangelog: none