Hi Alex,
thanks for letting us know about that.
Are you using Confluence 5.8 or later? Atlassian introduced a
client-side rendering mode for the TOC macro in 5.8 and I suspect that's
causing the issue for you.
The current implementation of the scrollToPosition function uses
jQuery's click() method to add handlers to all existing anchor links.
I suppose the client-side toc macro simply did not create the links when
the scrollToPosition is executed.
Try to change:
$('a[href^="#"]:not(.tabs-menu *)').click(function (e) { ...
to
$('a[href^="#"]:not(.tabs-menu *)').on('click', function (e) { ...
in the scrollToPosition function.
This will make sure the handler will be attached to links added later on
as well.
You might want to reconsider the setTimeout wrapper because I believe
that will break incoming links having an anchor (when coming from
outside of the current page). The setTimeout call should no longer be
required once you use .on().
Does this work for you?
Cheers,
Jens