From 0e6edb0d1a2992b16315ae195fc4fba39ad036cd Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Mon, 25 Nov 2019 00:19:03 +0800 Subject: [PATCH] Optimized JS to hide empty ToC. --- assets/js/_src/toc.js | 9 ++++++--- assets/js/dist/toc.min.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/assets/js/_src/toc.js b/assets/js/_src/toc.js index 513e99a..5e64906 100644 --- a/assets/js/_src/toc.js +++ b/assets/js/_src/toc.js @@ -6,8 +6,11 @@ */ $(function() { - // Hide ToC title if there is no head - if ($("#toc-wrap>nav#toc>ul>li").length == 0) { - $("#toc-wrap>h3").addClass("hidden"); + if ($("#post-wrap .post-content h1").length == 0 + && $("#post-wrap .post-content h2").length == 0 + && $("#post-wrap .post-content h3").length == 0 + && $("#post-wrap .post-content h4").length == 0 + && $("#post-wrap .post-content h5").length == 0) { + $("#toc-wrap").addClass("hidden"); } }); \ No newline at end of file diff --git a/assets/js/dist/toc.min.js b/assets/js/dist/toc.min.js index c158e79..d5dd257 100644 --- a/assets/js/dist/toc.min.js +++ b/assets/js/dist/toc.min.js @@ -1 +1 @@ -$(function(){if($("#toc-wrap>nav#toc>ul>li").length==0){$("#toc-wrap>h3").addClass("hidden")}}); \ No newline at end of file +$(function(){if($("#post-wrap .post-content h1").length==0&&$("#post-wrap .post-content h2").length==0&&$("#post-wrap .post-content h3").length==0&&$("#post-wrap .post-content h4").length==0&&$("#post-wrap .post-content h5").length==0){$("#toc-wrap").addClass("hidden")}}); \ No newline at end of file