I use Xwiki for documentation which often leads to massive Content within one Page.
I really love the content-macro to display all the headlines. The only problem for me is
the effort of scrolling back to the top of the page just to reach the macro again.
How much effort would it be -or better - which approach could i take to make that macro moving with
the top corner of the page?
I dont know the english name cause the macros are labled in german. But actually you can see which macro i mean in the gif? This macro makes a visuzal content-index according to “headlined” words. What you see in the gif is a slightly changed version of the original Encyclopedia template…i just “animated” my idea…
Again, the whole macro is described in german.there is no hint, how the extension could be called in english.
The information i can provide is that:
A) the html code for the macro is {{toc/}}
B) Its part of the encyclopedia template which is a standard i guess?(righthand side under Avatarpic)
C) its shown in the gif on the right side under the avatarpic.
I’d thought about this too, but the hovering TOC would get in the way of content further below.
Maybe this is possible by manipulating css? Since floatinginfobox is a cssclass too.
I thought about pinning the content in the left or right sidebar panels of xwiki instead. This would be nice to have independently of a TOC.
I have yet to find out how to display a TOC in a Panel which uses the currently viewed page as a reference
window.onload = function myFunction() {
// Get the TOC
var elements = document.getElementsByClassName("pagetoc");
// When the user scrolls the page, execute myFunc
window.onscroll = function myFunc() {
// Get the offset position of the content container
var element = document.getElementById("xwikicontent");
var icon = document.getElementById("toc-icon");
var sticky = element.offsetTop;
// Add the sticky class to the TOC when you reach the scroll position. Remove "sticky" when you leave the scroll position
if (window.pageYOffset >= sticky) {
elements[0].classList.add("toc-sticky");
if (icon == null) {
elements[0].innerHTML += `<i id="toc-icon"></i>`;
var t = document.getElementById("toc-icon");
t.addEventListener("click", function iToggle() {
var elements = document.getElementsByClassName("pagetoc");
if (elements[0].classList.contains('toc-sticky-expanded')) {
elements[0].classList.remove("toc-sticky-expanded");
} else {
elements[0].classList.add("toc-sticky-expanded");
}
});
}
} else {
elements[0].classList.remove("toc-sticky");
elements[0].classList.remove("toc-sticky-expanded");
if (icon != null) {
icon.remove();
icon.removeEventListener("click", iToggle)
}
}
};
};
Hey Pako!
It looks like you have created a nice solution for a problem, which i also like to solve. My only problem is, that i don’t know much about XWiki and Java, because i’m new to it and i do not know exactly, how i can implement your solution. The TOC Code is already working in the page, but i don’t know where to insert the JSX and SSX Code. I hope you can help me with that.
Thank you very much in advance!