From 4c25c1a8f0c52b79a4b2d824bc980bf9c9503eca Mon Sep 17 00:00:00 2001 From: Zehua-Chen Date: Wed, 23 Jun 2021 20:56:22 -0500 Subject: [PATCH] Use "id" as Refs in Table of Content If Available When header already have ids specified, rather than using the header content as refs in the table of content, use the id. Fallback to using header content when ids are not available. --- assets/js/main.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/js/main.js b/assets/js/main.js index 811bd2ea13..3b746c709b 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -14,8 +14,14 @@ $(window).resize(sectionHeight); $(function() { $("section h1, section h2, section h3").each(function(){ - $("nav ul").append("
  • " + $(this).text() + "
  • "); - $(this).attr("id",$(this).text().toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g,'')); + var href = $(this).attr("id"); + + if (!href) { + href = $(this).text().toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g,''); + } + + $("nav ul").append("
  • " + $(this).text() + "
  • "); + $(this).attr("id",href); $("nav ul li:first-child a").parent().addClass("active"); });