Page tree not jumping to current position

Comments

11 comments

  • Avatar
    Amit Kapoor

    Hi,

    I don't use this theme, but the solution is simple for Web Help theme. I had the same issue and K15T suggested this:

    Add the following to the $('document').ready function:

    $('.ht-sidebar-content').scrollTop($('.current').offset().top)

    The idea is use the scrollTop function to scroll to the desired position calculated using offset().top. I believe the logic would work in the Help Center theme also.

     

    -Amit

    2
    Comment actions Permalink
  • Avatar
    Volker Weinreich

    Hi Amit,

    thanks for your suggestion. I've tested it in the Web Help theme, but unfortunately it does not work. I've even tested it in a direct copy of the original theme.

    What else do I have to consider?

    Thanks,

    Volker

    0
    Comment actions Permalink
  • Avatar
    Steffen Burzlaff

    Hi Volker,

    could you share some insights to you code how you implemented the snippet from Amit?

    Thanks and have a nice day.

    Best Regards,
    Steffen

    0
    Comment actions Permalink
  • Avatar
    Volker Weinreich (Edited )

    Hi Steffen,

    as Amit said, I added it to the function $('document').ready - at the end. I have found it in theme.main.js.

    $(document).ready(function() {
    initI18n();

    //pageId = $('body').attr('pageid');
    /* Set Type of Device */
    checkDevice();

    /* init Sidebar Functions */
    initDragbar();
    initSidebar();
    checkGrid();

    /* init Search Functions */
    initSearch();
    initButtons();
    initFooter();

    /* init Keyboard */
    initKeyboard();

    $('.sp-picker').change(function () {
    $(this).closest('form').trigger('submit');
    });

    $('#ht-error-search-button').bind('click', function (e) {
    e.preventDefault();
    e.stopPropagation();
    openSearch();
    });

    /* handle links to anchors correctly with the headerbar */
    scrollToPosition();

    //setTimeout(function() {$('#ht-loader').hide();}, 500);
    $('#ht-loader').hide();

    // Scroll to navigation sidebar position
    $('.ht-sidebar-content').scrollTop($('.current').offset().top);
    });

     

    Greetings,

    Volker

    0
    Comment actions Permalink
  • Avatar
    Volker Weinreich

    Hi Steffen,

    could you help me here?

    Greetings,

    Volker

    0
    Comment actions Permalink
  • Avatar
    Amit Kapoor

     

    Hi Volker,

    Does this code work when you run it in the browser console (F12). It should. If it doesn't, is there a way we can access your page?

    -Amit

     

    0
    Comment actions Permalink
  • Avatar
    Volker Weinreich

    Hi Amit,

    I wonder if "offset" even (or still) exists in javaSript. I've only found "offsetTop()" (https://www.w3schools.com/jsref/prop_element_offsettop.asp) and had wondered about it when I inserted it. The development tools also say "deprecated".

    Uncaught TypeError: $(...).offset() is undefined

    But I don' know how to change it.

    Thanks,

    Volker

     

    0
    Comment actions Permalink
  • Avatar
    Volker Weinreich

    But you're right. It will be executed when I confirm it in the console.

     

    0
    Comment actions Permalink
  • Avatar
    Lukas Zervudakis

    Hi Volker & Amit,

    thank you both for your support. I'm still waiting myself to receive the editable .jar file from our company's docupedia admins. While reading the documentation of scroll viewport I found this quote:

    "- Edit a theme bundled with Scroll Viewport, or a theme that was installed as an add-on. It's not possible to edit these themes – just copy the theme and edit the new copy. Keep in mind that you can't develop a custom theme based on the The Help Center Theme."

     

    But it seems that you are still able to edit the script file of the theme, right? Once I get finally access to the respective files I will let you know if Amit's method works for me.

    0
    Comment actions Permalink
  • Avatar
    Amit Kapoor (Edited )

     

    Allow me to share my exact code snippet for this:

    I am using setInterval because the toc is not ready immediately and I need to wait before I execute the jump to the currently selected page. Also, note that I am subtracting the my #search.offset to take into account my UI layout. You don't need to do this.

      
      //Move currently opened pages TOC entry to near the top of TOC - when it is originally too low and not visible. 

      var tocReadyTimer;

      tocReadyTimer = setInterval(function () {

        if (document.getElementsByClassName("current").length > 0) {

          console.log("current heading exists now");

          $('.ht-sidebar-content').scrollTop($('.current').offset().top - $('#search').offset().top - 100);      

          clearInterval(tocReadyTimer);

        }

      }, 10);
     

     

    On console, you will need to run only:

     $('.ht-sidebar-content').scrollTop($('.current').offset().top; 

     

    0
    Comment actions Permalink
  • Avatar
    Volker Weinreich

    Hi Amit,

    sorry for the late reply. Now I found time to test this. It works for me with the setInterval function.

    Thanks,

    Volker

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk