Skip to content

Commit

Permalink
Fix for 576 (#735)
Browse files Browse the repository at this point in the history
Additional improvements for the fix to #576.
  • Loading branch information
MukulAmbulgekar authored and kcoleman-marklogic committed Sep 26, 2017
1 parent 066cb4c commit 4df571c
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/apidoc/js/toc_filter.js
Expand Up @@ -69,8 +69,10 @@ $(function() {
// Ensure that non-fragment TOC links highlight appropriate TOC links.
$(document).on('pjax:end', function(event, options) {
var target = $(event.relatedTarget);
// scroll to page content, fix for #576
scrollToPageContent(event.relatedTarget);
// scroll to page content, fix for #576 - added timeout to take care for pages with images.
setTimeout(function() {
scrollToPageContent();
}, 100)
//LOG.debug("pjax:end", event, options, target);
if (target.parents("#api_sub").length) {
LOG.debug("Calling showInTOC via pjax:end handler.", target[0]);
Expand All @@ -86,16 +88,17 @@ $(function() {
});

// scroll to page content
function scrollToPageContent(targetURL) {
var scrollTo = 0;
var hash = targetURL.toString().split("#")[1] || "";
// if target contains hash value e.g. /guide/search-dev/search-api#id_39268, calculate offsetTop
if (hash) {
var target = document.getElementById(hash) || document.getElementsByName(hash)[0];
scrollTo = $(target)[0].offsetTop;
}
$('#page_content').scrollTop(scrollTo);
}
function scrollToPageContent() {
var scrollTo = 0;
var hash = window.location.hash.slice(1) || "";
// if target contains hash value e.g. /guide/search-dev/search-api#id_39268, calculate offsetTop
if (hash) {
var target = document.getElementById(hash) || document.getElementsByName(hash)[0];
scrollTo = $(target)[0] ? $(target)[0].offsetTop : 0;
}
$('#page_content').scrollTop(scrollTo);
};


function tocInitGlobals() {
LOG.debug("tocInitGlobals");
Expand Down Expand Up @@ -248,6 +251,11 @@ function tocInit() {

// If this was a deep link, load and scroll.
updateTocForSelection();

// scroll to page content on page refresh, timeout is intentional for pages with images.
setTimeout(function() {
scrollToPageContent();
}, 100)
}

// This logic is essentially duplicated from the treeview plugin...bad, I know
Expand Down

0 comments on commit 4df571c

Please sign in to comment.