From 3ad6ae52ee8a2cdb3d716ffe9ebdeb7ce874088d Mon Sep 17 00:00:00 2001 From: Vincent Fiduccia Date: Tue, 10 Jul 2018 11:54:06 -0700 Subject: [PATCH] Add anchor links to headers on hover --- src/js/app.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/js/app.js b/src/js/app.js index 81ee65d8e32..dd7b4cfbfc7 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -72,13 +72,21 @@ const bootstrapDocsSearch = function() { overlay.css({top: 120}); }); - } -const bootstrapDocsJS = function() { - bootstrapDocsSearch(); +const bootstrapIdLinks = function() { + const container = '.wrapper ARTICLE'; + const selector = 'h2[id], h3[id], h4[id], h5[id], h6[id]'; + $(container).on('mouseenter', selector, function(e) { + $(e.target).append($('').addClass('header-anchor').attr('href', '#' + e.target.id).html('')); + }); + + $(container).on('mouseleave', selector, function(e) { + $(e.target).parent().find('.header-anchor').remove(); + }); } $(document).ready(() => { - bootstrapDocsJS(); + bootstrapDocsSearch(); + bootstrapIdLinks(); });