WikiDocs icon indicating copy to clipboard operation
WikiDocs copied to clipboard

back to top link

Open Zavy86 opened this issue 2 years ago • 3 comments

There are only 2 (fairly minor) features that I feel are missing:

  • [x] A right side bar with content of headings on the page that is being viewed (created from H2 and H3 headings on the page) to make navigation within the page easier
  • [ ] A back to top button to prevent sometimes long scrolling up

Originally posted by @stormpaul in https://github.com/Zavy86/WikiDocs/issues/75#issuecomment-1864726381

Zavy86 avatar Dec 20 '23 16:12 Zavy86

A right side bar with content of headings on the page that is being viewed (created from H2 and H3 headings on the page) to make navigation within the page easier

Would love a table of contents!

bverkron avatar Dec 29 '23 00:12 bverkron

Edit: I see that you can manually add a table of contents with the [toc] syntax but having an automatically generated ToC on each page would be much easier and avoid using custom syntax that may not be supported in other wiki platforms / renderers.

Also IMO it should created the ToC based on all headings tags not just h2 and h3.

bverkron avatar Dec 29 '23 18:12 bverkron

Hi,

I have 2 ways to go to TOP

  1. markdown Mode
\> [Homepage](/biblio.code)  

[Go UP](#homepage)
  1. html code Mode
<a href="#" style="position: fixed;bottom: 15px;right: 30px;z-index: 99;font-size: 12px;border: none;outline: none;background-color: red;color: white;cursor: pointer;padding: 15px;border-radius: 4px;" target="_top">TOP</a>   
  • Go UP

image

ffiesta avatar Jun 07 '24 11:06 ffiesta

we can add a green (main color) button in the bottom of the page..

Zavy86 avatar Aug 22 '24 15:08 Zavy86

Due to my basic PHP knowledge, it is preferable to be "someone" with more knowledge to add the back to top link to the wikidocs code.

Teste on wikidocs 1.0.37 and 1.0.42.

The line numbers refer to the approximate location.

  1. Add code to file template.inc.php after </main> line341 :
<button onclick="topFunction()" id="myBtn" title="Go to top" style="display: none; position: fixed;bottom: 15px;right: 30px;z-index: 99;font-size: 12px;border: none;outline: none;background-color: #4caf50;color: white;cursor: pointer;padding: 15px;border-radius: 4px;">Top</button>
  1. Add code to file template.inc.php after <?php endif; ?> line379:
<script>
// Get the button Top
let mybutton = document.getElementById("myBtn");

// When the user scrolls down 30px from the top of the document, show the button
window.onscroll = function() {scrollFunction()};

function scrollFunction() {
 if (document.body.scrollTop > 40 || document.documentElement.scrollTop > 40) {
   mybutton.style.display = "block";
 } else {
   mybutton.style.display = "none";
 }
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
 document.body.scrollTop = 0;
 document.documentElement.scrollTop = 0;
}
</script>

ffiesta avatar Oct 01 '24 15:10 ffiesta

Image without Top Button
Screenshot_20241001-165313_Brave

Image with Top Button
Screenshot_20241001-165323_Brave

:memo: The code only add the green TOP button on right lower corner of webpage.

ffiesta avatar Oct 01 '24 16:10 ffiesta

Edit: I see that you can manually add a table of contents with the [toc] syntax but having an automatically generated ToC on each page would be much easier and avoid using custom syntax that may not be supported in other wiki platforms / renderers.

Also IMO it should created the ToC based on all headings tags not just h2 and h3.

About the TOC, not everyone like TOC on every doc.

One example would be a short page doesn't need TOC...

We want to follow standard wiki workflows.

leomoon avatar Oct 01 '24 16:10 leomoon

Edit: I see that you can manually add a table of contents with the [toc] syntax but having an automatically generated ToC on each page would be much easier and avoid using custom syntax that may not be supported in other wiki platforms / renderers. Also IMO it should created the ToC based on all headings tags not just h2 and h3.

About the TOC, not everyone like TOC on every doc.

One example would be a short page doesn't need TOC...

We want to follow standard wiki workflows.

Hi @leomoon , I don't understand what you mean by TOC, but if you are referencing the text with dot point,

  • the 3 dot's and names are my folders, not go to top button

The code only add the lower right corner green top button

image

Images is to show with-out and with top button!!!

Code is based on: https://www.w3schools.com/howto/howto_js_scroll_to_top.asp

ffiesta avatar Oct 01 '24 17:10 ffiesta

TOC = table of contents.

leomoon avatar Oct 01 '24 18:10 leomoon

Please check if my location of UP button is good, otherwise send me better location to I try.

ffiesta avatar Oct 01 '24 21:10 ffiesta

Hi @ffiesta, open a pull request so we can test it together, if necessary we can make the changes directly there!

Due to my basic PHP knowledge, it is preferable to be "someone" with more knowledge to add the back to top link to the wikidocs code.

Zavy86 avatar Oct 02 '24 06:10 Zavy86

This is added thanks to @ffiesta in version 1.0.60

leomoon avatar Oct 04 '24 01:10 leomoon