Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #9108 implemented. A scroll to top anchor tag added. #9111

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ GEM
jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1)
minitest (5.19.0)
nokogiri (1.14.3-x64-mingw-ucrt)
racc (~> 1.4)
nishantjo-c marked this conversation as resolved.
Show resolved Hide resolved
nokogiri (1.14.3-x86_64-linux)
racc (~> 1.4)
octokit (4.25.1)
Expand Down Expand Up @@ -250,6 +252,7 @@ GEM
webrick (1.8.1)

PLATFORMS
x64-mingw-ucrt
nishantjo-c marked this conversation as resolved.
Show resolved Hide resolved
x86_64-linux

DEPENDENCIES
Expand Down
5 changes: 3 additions & 2 deletions docs/_layouts/v2.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,16 @@ <h1><a href="https://leafletjs.com/"><img src="{{ root }}docs/images/logo.png" a
</main>

<footer class="container">

<div class="footer">
<p>&copy; 2010–{{ 'now' | date: "%Y" }} <a href="https://agafonkin.com">Volodymyr Agafonkin</a>. Maps &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors.</p>
</div>

<nav class="ext-links">
<a class="ext-link twitter" href="https://twitter.com/LeafletJS" title="Follow LeafletJS on Twitter"><img alt="Follow LeafletJS on Twitter" src="{{root}}docs/images/twitter-round.svg" width="46" /></a>
<a class="ext-link twitter" href="https://twitter.com/LeafletJS" title="Follow LeafletJS on Twitter"><img alt="Follow LeafletJS on Twitter" src="{{root}}docs/images/twitter-round.svg" width="46" /></a>
<a class="ext-link github" href="http://github.com/Leaflet/Leaflet" title="View Source on GitHub"><img alt="View Source on GitHub" src="{{root}}docs/images/github-round.svg" width="46" /></a>
<a class="ext-link forum" href="https://stackoverflow.com/questions/tagged/leaflet" title="Ask for help on Stack Overflow"><img alt="Leaflet questions on Stack Overflow" src="{{root}}docs/images/forum-round.svg" width="46" /></a>
</nav>
<a id="backtotop">back to top</a>
</footer>

<script>
Expand Down
1 change: 0 additions & 1 deletion docs/docs/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ h4 {
color: #777;
}


/* header */

h1 {
Expand Down
36 changes: 24 additions & 12 deletions docs/docs/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ if (toc) {
const scrollPos = function scrollPos() {
const scroll = window.scrollY;

if (scroll >= (toc.offsetHeight + toc.offsetTop)) {
if (scroll >= toc.offsetHeight + toc.offsetTop) {
nishantjo-c marked this conversation as resolved.
Show resolved Hide resolved
document.body.classList.add('scrolled');
} else {
document.body.classList.remove('scrolled');
Expand All @@ -69,17 +69,23 @@ if (toc) {
scrollPos();
});

window.addEventListener('load', () => {
const currentHash = window.location.hash;
if (!currentHash) { return; }
const elem = document.querySelector(currentHash);

if (elem.tagName === 'H2' || elem.tagName === 'H4') {
setTimeout(() => {
scrollToHeader(elem, true);
}, 10);
}
}, false);
window.addEventListener(
'load',
() => {
const currentHash = window.location.hash;
if (!currentHash) {
return;
}
const elem = document.querySelector(currentHash);

if (elem.tagName === 'H2' || elem.tagName === 'H4') {
setTimeout(() => {
scrollToHeader(elem, true);
}, 10);
}
},
false
);
nishantjo-c marked this conversation as resolved.
Show resolved Hide resolved
}

let currentAnchor = '';
Expand Down Expand Up @@ -115,3 +121,9 @@ function scrollToHeader(elemHeader, sameAnchor) {
// apply the new anchor to the location url
currentAnchor = window.location.hash = `#${elemHeader.id}`;
}

// back to top
const backToTop = document.getElementById('backtotop');
backToTop.addEventListener('click', () => {
document.documentElement.scrollIntoView({behavior: 'smooth'});
});