diff --git a/asset/js/setup.js b/asset/js/setup.js index 168c00424e..1e868398bf 100644 --- a/asset/js/setup.js +++ b/asset/js/setup.js @@ -15,13 +15,14 @@ function flattenModals() { }); } -function setupAnchorVisibility() { - jQuery('h1, h2, h3, h4, h5, h6').each((index, heading) => { - jQuery(heading).on('mouseenter', function () { - jQuery(this).children('.fa.fa-anchor').show(); - }); - jQuery(heading).on('mouseleave', function () { - jQuery(this).children('.fa.fa-anchor').hide(); +function setupAnchors() { + jQuery('h1, h2, h3, h4, h5, h6, .header-wrapper').each((index, heading) => { + jQuery(heading).on('mouseenter', () => jQuery(heading).find('.fa.fa-anchor').show()); + jQuery(heading).on('mouseleave', () => jQuery(heading).find('.fa.fa-anchor').hide()); + }); + jQuery('.fa-anchor').each((index, anchor) => { + jQuery(anchor).on('click', function () { + window.location.href = jQuery(this).attr('href'); }); }); } @@ -29,7 +30,7 @@ function setupAnchorVisibility() { function executeAfterMountedRoutines() { flattenModals(); scrollToUrlAnchorHeading(); - setupAnchorVisibility(); + setupAnchors(); } function setupSiteNav() { diff --git a/lib/Page.js b/lib/Page.js index 997b238c3b..f867ae308a 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -330,6 +330,14 @@ Page.prototype.addAnchors = function (content) { $(headingsSelector).each((i, heading) => { $(heading).append(ANCHOR_HTML.replace('#', `#${$(heading).attr('id')}`)); }); + $('panel[header]').each((i, panel) => { + const panelHeading = cheerio.load(md.render(panel.attribs.header), { xmlMode: false }); + if (panelHeading(headingsSelector).length >= 1) { + const headingId = $(panelHeading(headingsSelector)[0]).attr('id'); + const anchorIcon = ANCHOR_HTML.replace(/"/g, "'").replace('#', `#${headingId}`); + $(panel).attr('header', `${$(panel).attr('header')}${anchorIcon}`); + } + }); } return $.html(); }; diff --git a/test/test_site/expected/index.html b/test/test_site/expected/index.html index 65a81a9fca..ad48c9a03b 100644 --- a/test/test_site/expected/index.html +++ b/test/test_site/expected/index.html @@ -235,43 +235,43 @@