Browse Source
* Refactor custom.js * Refactor scorer.js * tables variable shoudn't be in global scopepull/4143/head
committed by
GitHub
2 changed files with 71 additions and 63 deletions
@ -1,40 +1,43 @@ |
|||||
$(document).ready(function () { |
'use-strict'; |
||||
var sections = $('div.section'); |
|
||||
var activeLink = null; |
|
||||
var bottomHeightThreshold = $(document).height() - 30; |
|
||||
|
|
||||
$(window).scroll(function (event) { |
let activeLink = null; |
||||
var distanceFromTop = $(this).scrollTop(); |
let bottomHeightThreshold, sections; |
||||
var currentSection = null; |
|
||||
|
|
||||
if(distanceFromTop + window.innerHeight > bottomHeightThreshold) { |
document.addEventListener('DOMContentLoaded', () => { |
||||
currentSection = $(sections[sections.length - 1]); |
bottomHeightThreshold = document.documentElement.scrollHeight - 30; |
||||
|
sections = document.querySelectorAll('div.section'); |
||||
|
|
||||
|
const tables = document.querySelectorAll('.py-attribute-table[data-move-to-id]'); |
||||
|
tables.forEach(table => { |
||||
|
let element = document.getElementById(table.getAttribute('data-move-to-id')); |
||||
|
let parent = element.parentNode; |
||||
|
// insert ourselves after the element
|
||||
|
parent.insertBefore(table, element.nextSibling); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
window.addEventListener('scroll', () => { |
||||
|
let currentSection = null; |
||||
|
|
||||
|
if (window.scrollY + window.innerHeight > bottomHeightThreshold) { |
||||
|
currentSection = sections[sections.length - 1]; |
||||
} |
} |
||||
else { |
else { |
||||
sections.each(function () { |
sections.forEach(section => { |
||||
var section = $(this); |
let rect = section.getBoundingClientRect(); |
||||
if (section.offset().top - 1 < distanceFromTop) { |
if (rect.top + document.body.scrollTop - 1 < window.scrollY) { |
||||
currentSection = section; |
currentSection = section; |
||||
} |
} |
||||
}); |
}); |
||||
} |
} |
||||
|
|
||||
if (activeLink) { |
if (activeLink) { |
||||
activeLink.parent().removeClass('active'); |
activeLink.parentElement.classList.remove('active'); |
||||
} |
} |
||||
|
|
||||
if (currentSection) { |
if (currentSection) { |
||||
activeLink = $('.sphinxsidebar a[href="#' + currentSection.attr('id') + '"]'); |
activeLink = document.querySelector(`.sphinxsidebar a[href="#${currentSection.id}"]`); |
||||
activeLink.parent().addClass('active'); |
activeLink.parentElement.classList.add('active'); |
||||
} |
} |
||||
|
|
||||
}); |
|
||||
|
|
||||
const tables = document.querySelectorAll('.py-attribute-table[data-move-to-id]'); |
|
||||
tables.forEach(table => { |
|
||||
let element = document.getElementById(table.getAttribute('data-move-to-id')); |
|
||||
let parent = element.parentNode; |
|
||||
// insert ourselves after the element
|
|
||||
parent.insertBefore(table, element.nextSibling); |
|
||||
}); |
|
||||
}); |
}); |
Loading…
Reference in new issue