Skip to content

Commit

Permalink
In Report, replace some uses of jQuery with vanilla JavaScript (mne…
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechenberger authored Apr 23, 2024
1 parent 52d9a9b commit 96ac7af
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions mne/report/js_and_css/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const refreshScrollSpy = () =>{
}

const propagateScrollSpyURL = () => {
$(window).on('activate.bs.scrollspy', (event) => {
history.replaceState({}, "", event.relatedTarget);
window.addEventListener('activate.bs.scrollspy', (e) => {
history.replaceState({}, "", e.relatedTarget);
});
}

Expand Down Expand Up @@ -40,10 +40,10 @@ const toggleTagVisibility = (tagName) => {

if (visibleTagNamesOfCurrentElement.size === 0) { // hide
$(currentElement).slideToggle('fast', () => {
$(currentElement).addClass('d-none');
currentElement.classList.add('d-none');
});
} else if ($(currentElement).hasClass('d-none')) { // show
$(currentElement).removeClass('d-none');
currentElement.classList.remove('d-none');
$(currentElement).slideToggle('fast');
}
})
Expand All @@ -52,12 +52,12 @@ const toggleTagVisibility = (tagName) => {
tagBadgeElements.forEach((badgeElement) => {
if (tag.visible) {
badgeElement.removeAttribute('data-mne-tag-hidden');
$(badgeElement).removeClass('bg-secondary');
$(badgeElement).addClass('bg-primary');
badgeElement.classList.remove('bg-secondary');
badgeElement.classList.add('bg-primary');
} else {
badgeElement.setAttribute('data-mne-tag-hidden', true);
$(badgeElement).removeClass('bg-primary');
$(badgeElement).addClass('bg-secondary');
badgeElement.classList.remove('bg-primary');
badgeElement.classList.add('bg-secondary');
}
})

Expand Down Expand Up @@ -164,8 +164,8 @@ const _handleTocLinkClick = (e) => {
const tocLinkElement = e.target;
const targetDomId = tocLinkElement.getAttribute('href');
const targetElement = document.querySelector(targetDomId);
const top = $(targetElement).offset().top;

const top = targetElement.getBoundingClientRect().top + window.scrollY;
// Update URL to reflect the current scroll position.
// We use history.pushState to change the URL without causing the browser to scroll.
history.pushState(null, "", targetDomId);
Expand Down Expand Up @@ -248,7 +248,8 @@ const disableGlobalKeysInSearchBox = () => {
})
}

$(document).ready(() => {
/* Run once all content is fully loaded. */
window.addEventListener('load', () => {
gatherTags();
updateTagCountBadges();
addFilterByTagsCheckboxEventHandlers();
Expand All @@ -261,6 +262,7 @@ $(document).ready(() => {
propagateScrollSpyURL();
});

/* Resizing the window throws off the scroll spy and top-margin handling. */
window.onresize = () => {
fixTopMargin();
refreshScrollSpy();
Expand Down

0 comments on commit 96ac7af

Please sign in to comment.