-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
chore: ♻️ remove jquery #1964
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
chore: ♻️ remove jquery #1964
Changes from all commits
4c372d3
47bf6fc
9386a95
f492c50
f1ae195
3655e87
5550938
c327d43
5b03669
3a51fb7
7946483
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,122 +1,124 @@ | ||||||
| $(function(){ | ||||||
| var doc = $(document); | ||||||
|
|
||||||
| // top link | ||||||
| $('#top').click(function(e){ | ||||||
| $('html, body').animate({scrollTop : 0}, 500); | ||||||
| return false; | ||||||
| }); | ||||||
| const languageElement = document.getElementById('languageData'); | ||||||
| const languagesData = languageElement ? JSON.parse(languageElement.dataset.languages) : []; | ||||||
| const langDisplay = document.getElementById('current-lang'); | ||||||
| const i18nMsgBox = document.getElementById("i18n-notice-box"); | ||||||
| const scrollToTopBtn = document.getElementById("top"); | ||||||
|
|
||||||
| // display current language in language picker component | ||||||
| if (langDisplay) { | ||||||
| const currentLanguage = window.location.pathname.split('/')[1]; | ||||||
| const matchedLang = languagesData.find(lang => lang.code === currentLanguage); | ||||||
| langDisplay.textContent = matchedLang ? matchedLang.name : 'English'; | ||||||
| } | ||||||
|
|
||||||
| // scrolling links | ||||||
| var added; | ||||||
| doc.scroll(function(e){ | ||||||
| if (doc.scrollTop() > 5) { | ||||||
| if (added) return; | ||||||
| added = true; | ||||||
| $('body').addClass('scroll'); | ||||||
| } else { | ||||||
| $('body').removeClass('scroll'); | ||||||
| added = false; | ||||||
| } | ||||||
| // scroll to top of the page | ||||||
| if (scrollToTopBtn) { | ||||||
| scrollToTopBtn.addEventListener("click", function (e) { | ||||||
| e.preventDefault(); | ||||||
| window.scrollTo({ | ||||||
| top: 0, | ||||||
| behavior: "smooth" | ||||||
| }) | ||||||
| }) | ||||||
| } | ||||||
|
|
||||||
| // menu bar | ||||||
|
|
||||||
| var headings = $('h2, h3').map(function(i, el){ | ||||||
| return { | ||||||
| top: $(el).offset().top - 200, | ||||||
| id: el.id | ||||||
| } | ||||||
| }); | ||||||
|
|
||||||
| function closest() { | ||||||
| var h; | ||||||
| var top = $(window).scrollTop(); | ||||||
| var i = headings.length; | ||||||
| while (i--) { | ||||||
| h = headings[i]; | ||||||
| if (top >= h.top) return h; | ||||||
| // add/remove class 'scroll' on scroll by 5px | ||||||
| const scrollTarget = document.querySelector('.logo-container'); | ||||||
| const scrollObserver = new IntersectionObserver( | ||||||
| ([entry]) => { | ||||||
| if (!entry.isIntersecting) { | ||||||
| document.body.classList.add('scroll'); | ||||||
| } else { | ||||||
| document.body.classList.remove('scroll'); | ||||||
| } | ||||||
| }, | ||||||
| { | ||||||
| root: null, | ||||||
| threshold: 0, | ||||||
| rootMargin: '0px 0px 0px 0px' | ||||||
| } | ||||||
|
|
||||||
| var currentApiPrefix; | ||||||
| var parentMenuSelector; | ||||||
| var lastApiPrefix; | ||||||
|
|
||||||
| if (document.readyState !== 'loading') { | ||||||
| const languageElement = document.getElementById('languageData'); | ||||||
| const languagesData = languageElement ? JSON.parse(languageElement.dataset.languages) : []; | ||||||
|
|
||||||
| const langDisplay = document.getElementById('current-lang'); | ||||||
|
|
||||||
| if (langDisplay) { | ||||||
| const currentLanguage = window.location.pathname.split('/')[1]; | ||||||
| const matchedLang = languagesData.find(lang => lang.code === currentLanguage); | ||||||
| langDisplay.textContent = matchedLang ? matchedLang.name : 'English'; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| $(document).scroll(function() { | ||||||
| var h = closest(); | ||||||
| if (!h) return; | ||||||
|
|
||||||
| currentApiPrefix = h.id.split('.')[0]; | ||||||
| parentMenuSelector = '#'+ currentApiPrefix + '-menu'; | ||||||
|
|
||||||
| $(parentMenuSelector).addClass('active'); | ||||||
|
|
||||||
| if (lastApiPrefix && (lastApiPrefix != currentApiPrefix)) { | ||||||
| $('#'+ lastApiPrefix + '-menu').removeClass('active'); | ||||||
| ); | ||||||
|
|
||||||
| if (scrollTarget) scrollObserver.observe(scrollTarget); | ||||||
|
|
||||||
| // heighlight current Menu on scroll | ||||||
| const headings = Array.from(document.querySelectorAll("h2, h3")); | ||||||
| const menuLinks = document.querySelectorAll("#menu li a"); | ||||||
|
|
||||||
| const observerOptions = { | ||||||
| root: null, | ||||||
| rootMargin: "-10% 0px -65% 0px", | ||||||
| threshold: 1, | ||||||
| }; | ||||||
|
|
||||||
| const menuObserver = new IntersectionObserver((entries) => { | ||||||
| entries.forEach((entry) => { | ||||||
| if (entry.isIntersecting) { | ||||||
| const currentApiPrefix = entry.target.id.split(".")[0]; | ||||||
| const parentMenuSelector = `#${currentApiPrefix}-menu`; | ||||||
| const parentMenuEl = document.querySelector(parentMenuSelector); | ||||||
|
|
||||||
| // open submenu on scroll | ||||||
| if (parentMenuEl) parentMenuEl.classList.add("active"); | ||||||
|
|
||||||
| // Remove active class from last menu item | ||||||
| const lastActiveMenu = document.querySelector(".active[id$='-menu']"); | ||||||
| if (lastActiveMenu && lastActiveMenu.id !== parentMenuEl.id) { | ||||||
|
||||||
| if (lastActiveMenu && lastActiveMenu.id !== parentMenuEl.id) { | |
| if (lastActiveMenu && parentMenuEl && lastActiveMenu.id !== parentMenuEl.id) { |
Copilot
AI
Aug 2, 2025
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.
[nitpick] The magic number 864e5 should be replaced with a more readable constant or calculation like 24 * 60 * 60 * 1000 to clearly represent milliseconds in a day.
| date.setTime(date.getTime() + (days * 864e5)); | |
| date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); |
Copilot
AI
Aug 2, 2025
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.
The Secure flag requires HTTPS connections. This could break functionality on HTTP development environments. Consider making the Secure flag conditional based on the protocol.
| document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}${expires}; path=/; SameSite=Lax; Secure`; | |
| document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}${expires}; path=/; SameSite=Lax${window.location.protocol === 'https:' ? '; Secure' : ''}`; |
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.
There's a spelling error in the comment. 'heighlight' should be 'highlight'.