Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wangchucheng/hugo-eureka.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'assets/js/eureka.js')
-rw-r--r--assets/js/eureka.js126
1 files changed, 57 insertions, 69 deletions
diff --git a/assets/js/eureka.js b/assets/js/eureka.js
index beff315..30ede24 100644
--- a/assets/js/eureka.js
+++ b/assets/js/eureka.js
@@ -1,75 +1,73 @@
function enableStickyToc() {
- window.addEventListener('DOMContentLoaded', () => {
- const observer = new IntersectionObserver(entries => {
- entries.forEach(entry => {
- const id = entry.target.getAttribute('id');
- if (entry.intersectionRatio > 0) {
- if (delay == true) {
- let element = document.querySelector('.sticky-toc li.active')
- element.firstChild.classList.remove(textColor);
- element.classList.remove('active');
- delay = false;
- updatePosAndColor();
- }
- document.querySelector(`.sticky-toc li a[href="#${id}"]`).parentElement.classList.add('active');
+ const observer = new IntersectionObserver(entries => {
+ entries.forEach(entry => {
+ const id = entry.target.getAttribute('id');
+ if (entry.intersectionRatio > 0) {
+ if (delay == true) {
+ let element = document.querySelector('.sticky-toc li.active')
+ element.firstChild.classList.remove(textColor);
+ element.classList.remove('active');
+ delay = false;
updatePosAndColor();
+ }
+ document.querySelector(`.sticky-toc li a[href="#${id}"]`).parentElement.classList.add('active');
+ updatePosAndColor();
+ } else {
+ if (document.querySelectorAll('.sticky-toc li.active').length == 1) {
+ delay = true;
} else {
- if (document.querySelectorAll('.sticky-toc li.active').length == 1) {
- delay = true;
- } else {
- let element = document.querySelector(`.sticky-toc li a[href="#${id}"]`)
- element.classList.remove(textColor);
- element.parentElement.classList.remove('active');
- updatePosAndColor();
- }
+ let element = document.querySelector(`.sticky-toc li a[href="#${id}"]`)
+ element.classList.remove(textColor);
+ element.parentElement.classList.remove('active');
+ updatePosAndColor();
}
- });
+ }
});
+ });
- var delay = false;
- var targetPos = window.innerHeight * 0.4
- var textColor = 'text-eureka'
+ var delay = false;
+ var targetPos = window.innerHeight * 0.4
+ var textColor = 'text-eureka'
- function updatePosAndColor() {
- let elements = document.querySelectorAll('.sticky-toc li.active')
- let len = elements.length
- if (len != 0) {
- let firstElement = elements[0]
- firstElement.firstChild.classList.add(textColor)
- let offset = firstElement.offsetTop - targetPos;
- if (offset > 0) {
- document.querySelector(`.sticky-toc`).style.top = `calc( 7rem - ${offset}px)`
- } else {
- document.querySelector(`.sticky-toc`).removeAttribute("style");
- }
- for (let i = 1; i < len; i++) {
- elements[i].firstChild.classList.remove(textColor)
- }
+ function updatePosAndColor() {
+ let elements = document.querySelectorAll('.sticky-toc li.active')
+ let len = elements.length
+ if (len != 0) {
+ let firstElement = elements[0]
+ firstElement.firstChild.classList.add(textColor)
+ let offset = firstElement.offsetTop - targetPos;
+ if (offset > 0) {
+ document.querySelector(`.sticky-toc`).style.top = `calc( 7rem - ${offset}px)`
+ } else {
+ document.querySelector(`.sticky-toc`).removeAttribute("style");
+ }
+ for (let i = 1; i < len; i++) {
+ elements[i].firstChild.classList.remove(textColor)
}
}
+ }
- // Track all sections that have an `id` applied
- document.querySelectorAll('.content h1[id]').forEach((section) => {
- observer.observe(section);
- });
- document.querySelectorAll('.content h2[id]').forEach((section) => {
- observer.observe(section);
- });
- document.querySelectorAll('.content h3[id]').forEach((section) => {
- observer.observe(section);
- });
+ // Track all sections that have an `id` applied
+ document.querySelectorAll('.content h1[id]').forEach((section) => {
+ observer.observe(section);
+ });
+ document.querySelectorAll('.content h2[id]').forEach((section) => {
+ observer.observe(section);
+ });
+ document.querySelectorAll('.content h3[id]').forEach((section) => {
+ observer.observe(section);
+ });
- document.querySelectorAll('.content h4[id]').forEach((section) => {
- observer.observe(section);
- });
+ document.querySelectorAll('.content h4[id]').forEach((section) => {
+ observer.observe(section);
+ });
- document.querySelectorAll('.content h5[id]').forEach((section) => {
- observer.observe(section);
- });
+ document.querySelectorAll('.content h5[id]').forEach((section) => {
+ observer.observe(section);
+ });
- document.querySelectorAll('.content h6[id]').forEach((section) => {
- observer.observe(section);
- });
+ document.querySelectorAll('.content h6[id]').forEach((section) => {
+ observer.observe(section);
});
}
@@ -92,14 +90,4 @@ function resizeAllGridItems() {
function resizeInstance(instance) {
item = instance.elements[0];
resizeGridItem(item);
-}
-
-function enableMasonry() {
- window.onload = resizeAllGridItems();
- window.addEventListener("resize", resizeAllGridItems);
-
- allItems = document.getElementsByClassName("item");
- for (x = 0; x < allItems.length; x++) {
- imagesLoaded(allItems[x], resizeInstance);
- }
} \ No newline at end of file