Inject custom JavaScript in HelpCenter

60 views
Skip to first unread message

Volker Weinreich

unread,
Jun 17, 2020, 8:21:09 AM6/17/20
to Scroll Viewport Developers

Hi,

so far we maintain our own further development of the WebHelp Theme. With release 2.17 it is now possible to add your own CSS and JavaScript to the HelpCenter.

But now I encounter problems with overwriting JavaScript functions. In our variant of the WebHelp Theme we also use a version of the TocBot function to generate a table of contents. (But with different specifications, because we have very long pages.) Now I try to overwrite the TocBot specifications of the HelpCenter JavaScript, but I do not succeed. I tried this:


var tocBot= myTocBot;
myTocBot
= function() {
tocbot
.init({
...
<my specifications>
...
});
return tocBot();
}

Or can it not succeed because it is a private function? Unfortunately my JavaScript skills are limited.


Does anyone have an idea?

Greetings,

Volker

David Majninger (K15t)

unread,
Jun 17, 2020, 9:59:20 AM6/17/20
to Scroll Viewport Developers
Hi Volker,

what are your specifications? I think adjusting the native TOC's output is probably easier than running it again.

Cheers,
David

Volker Weinreich

unread,
Jun 17, 2020, 10:27:46 AM6/17/20
to Scroll Viewport Developers
Hi David,

yes, I would do that, if I was able to do it.

My specifications are in particular

...
headingSelector: 'h1, h2, h3, h4, h5',
...
collapseDepth: 2,


Thanks,
Volker

David Majninger (K15t)

unread,
Jun 18, 2020, 2:39:32 AM6/18/20
to scroll-vi...@googlegroups.com
Hi Volker,
I have done a little bit of testing and found that it's enough to just remove the generic TOC and invoke it again, but you need to wait a little first to let the theme finish its code first. 
Here's the code that worked for me, depending on your system, you might need to adjust the timeout milliseconds:

$( document ).ready(function(){
  setTimeout(function(){
      $("ol.toc-list").remove();
            tocbot.init({
            tocSelector: '.js-tocBot',
            contentSelector: '.js-tocBot-content',

            headingSelector: 'h1, h2, h3, h4, h5',
            linkClass: 'article__content__toc__link',
            activeLinkClass: 'article__content__toc__link--active',
scrollSmooth: true,
            scrollSmoothDuration: 500,
headingsOffset: 1,
            collapseDepth: 2,
            });
  }, 500);
});

Cheers,
David

--
You received this message because you are subscribed to the Google Groups "Scroll Viewport Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scroll-viewport...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scroll-viewport-dev/7b123d65-5dcf-48fa-8159-7e9f64f16766o%40googlegroups.com.


--
David Majninger, Product Manager
Email: da...@k15t.com

K15t GmbH, Ostendstr. 110, 70188 Stuttgart, Germany
Phone: +49 (711) 935 935 30 | Fax: +49 (711) 935 935 39
Registration: Stuttgart HRB 729752, VAT ID: DE264753756
Geschaeftsfuehrer (CEO): Stefan Kleineikenscheidt

Join us for our Virtual Team Up Forum by K15t and Scandio on June 30th, 2020
https://www.k15t.com/events/teamup-forum

We amplify the Atlassian experience for everybody. See what's new:
https://www.k15t.com/blog

Tweet along with us:
https://twitter.com/k15tsoftware

Volker Weinreich

unread,
Jun 18, 2020, 3:10:09 AM6/18/20
to Scroll Viewport Developers
Hi David,

thanks, this code works for me too.

Kind regards

Volker
Reply all
Reply to author
Forward
0 new messages