diff options
| author | Josh <[email protected]> | 2020-05-27 16:22:21 +1000 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-12-18 21:18:50 -0500 |
| commit | 8be9ef38db66a6d63447c1d22884eccc9c019cc6 (patch) | |
| tree | 966f830acb3435b76c336ca2fcd00c9d9bf5514c /docs/_static/custom.js | |
| parent | [matrix] Refactor docs JS (diff) | |
| download | discord.py-8be9ef38db66a6d63447c1d22884eccc9c019cc6.tar.xz discord.py-8be9ef38db66a6d63447c1d22884eccc9c019cc6.zip | |
[matrix] Create settings modal
* Create settings modal
* Fix issue with spacing after settings button
* Fix issue with modal background on mobile devices
* Add close button to modal
* Add tooltip to close button
* Support closing modal with escape key
* Add missing semicolon to keydown event listener
Diffstat (limited to 'docs/_static/custom.js')
| -rw-r--r-- | docs/_static/custom.js | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/docs/_static/custom.js b/docs/_static/custom.js index b8bac63b..97462e46 100644 --- a/docs/_static/custom.js +++ b/docs/_static/custom.js @@ -1,11 +1,28 @@ 'use-strict'; +let activeModal = null; let activeLink = null; let bottomHeightThreshold, sections; +let settings; + +function closeModal(modal) { + activeModal = null; + modal.style.display = 'none'; +} + +function openModal(modal) { + if (activeModal) { + closeModal(activeModal); + } + + activeModal = modal; + modal.style.removeProperty('display'); +} document.addEventListener('DOMContentLoaded', () => { bottomHeightThreshold = document.documentElement.scrollHeight - 30; sections = document.querySelectorAll('div.section'); + settings = document.querySelector('div#settings.modal') const tables = document.querySelectorAll('.py-attribute-table[data-move-to-id]'); tables.forEach(table => { @@ -25,7 +42,7 @@ window.addEventListener('scroll', () => { else { sections.forEach(section => { let rect = section.getBoundingClientRect(); - if (rect.top + document.body.scrollTop - 1 < window.scrollY) { + if (rect.top + document.body.offsetTop < 1) { currentSection = section; } }); @@ -37,7 +54,14 @@ window.addEventListener('scroll', () => { if (currentSection) { activeLink = document.querySelector(`.sphinxsidebar a[href="#${currentSection.id}"]`); - activeLink.parentElement.classList.add('active'); + if (activeLink) { + activeLink.parentElement.classList.add('active'); + } } +}); -});
\ No newline at end of file +document.addEventListener('keydown', (event) => { + if (event.keyCode == 27 && activeModal) { + closeModal(activeModal); + } +}); |