Browse Source
* Refactor custom.js * Refactor scorer.js * tables variable shoudn't be in global scopepull/6176/head
committed by
Rapptz
2 changed files with 71 additions and 63 deletions
@ -1,40 +1,43 @@ |
|||
$(document).ready(function () { |
|||
var sections = $('div.section'); |
|||
var activeLink = null; |
|||
var bottomHeightThreshold = $(document).height() - 30; |
|||
'use-strict'; |
|||
|
|||
$(window).scroll(function (event) { |
|||
var distanceFromTop = $(this).scrollTop(); |
|||
var currentSection = null; |
|||
let activeLink = null; |
|||
let bottomHeightThreshold, sections; |
|||
|
|||
if(distanceFromTop + window.innerHeight > bottomHeightThreshold) { |
|||
currentSection = $(sections[sections.length - 1]); |
|||
document.addEventListener('DOMContentLoaded', () => { |
|||
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 { |
|||
sections.each(function () { |
|||
var section = $(this); |
|||
if (section.offset().top - 1 < distanceFromTop) { |
|||
sections.forEach(section => { |
|||
let rect = section.getBoundingClientRect(); |
|||
if (rect.top + document.body.scrollTop - 1 < window.scrollY) { |
|||
currentSection = section; |
|||
} |
|||
}); |
|||
} |
|||
|
|||
if (activeLink) { |
|||
activeLink.parent().removeClass('active'); |
|||
activeLink.parentElement.classList.remove('active'); |
|||
} |
|||
|
|||
if (currentSection) { |
|||
activeLink = $('.sphinxsidebar a[href="#' + currentSection.attr('id') + '"]'); |
|||
activeLink.parent().addClass('active'); |
|||
activeLink = document.querySelector(`.sphinxsidebar a[href="#${currentSection.id}"]`); |
|||
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