mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-06 09:56:09 +00:00
[matrix] Refactor docs JS
* Refactor custom.js * Refactor scorer.js * tables variable shoudn't be in global scope
This commit is contained in:
61
docs/_static/custom.js
vendored
61
docs/_static/custom.js
vendored
@ -1,34 +1,11 @@
|
||||
$(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]);
|
||||
}
|
||||
else {
|
||||
sections.each(function () {
|
||||
var section = $(this);
|
||||
if (section.offset().top - 1 < distanceFromTop) {
|
||||
currentSection = section;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (activeLink) {
|
||||
activeLink.parent().removeClass('active');
|
||||
}
|
||||
|
||||
if (currentSection) {
|
||||
activeLink = $('.sphinxsidebar a[href="#' + currentSection.attr('id') + '"]');
|
||||
activeLink.parent().addClass('active');
|
||||
}
|
||||
|
||||
});
|
||||
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 => {
|
||||
@ -38,3 +15,29 @@ $(document).ready(function () {
|
||||
parent.insertBefore(table, element.nextSibling);
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener('scroll', () => {
|
||||
let currentSection = null;
|
||||
|
||||
if (window.scrollY + window.innerHeight > bottomHeightThreshold) {
|
||||
currentSection = sections[sections.length - 1];
|
||||
}
|
||||
else {
|
||||
sections.forEach(section => {
|
||||
let rect = section.getBoundingClientRect();
|
||||
if (rect.top + document.body.scrollTop - 1 < window.scrollY) {
|
||||
currentSection = section;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (activeLink) {
|
||||
activeLink.parentElement.classList.remove('active');
|
||||
}
|
||||
|
||||
if (currentSection) {
|
||||
activeLink = document.querySelector(`.sphinxsidebar a[href="#${currentSection.id}"]`);
|
||||
activeLink.parentElement.classList.add('active');
|
||||
}
|
||||
|
||||
});
|
Reference in New Issue
Block a user