From 52b062c3b6db925d9294b5ee7337e546158109b5 Mon Sep 17 00:00:00 2001 From: liuyib <1656081615@qq.com> Date: Wed, 28 Aug 2019 17:52:58 +0800 Subject: [PATCH] refactor: Not show toc when the post not heading --- source/js/scroll.js | 2 +- source/js/sidebar.js | 10 +++++----- source/js/stun-boot.js | 7 ++++--- source/js/utils.js | 13 ++++++++++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/source/js/scroll.js b/source/js/scroll.js index e14bc8d..67a241f 100644 --- a/source/js/scroll.js +++ b/source/js/scroll.js @@ -92,7 +92,7 @@ $(document).ready(function () { .on('click', function () { scrollHeadingToTop('#' + $(this).attr('id')); }); - + // Click the post toc. $('.toc-link').on('click', function (e) { e.preventDefault(); diff --git a/source/js/sidebar.js b/source/js/sidebar.js index 877f2c1..c997fb6 100644 --- a/source/js/sidebar.js +++ b/source/js/sidebar.js @@ -149,21 +149,21 @@ $(document).ready(function () { $('.sidebar-nav-toc').on('click', function () { $('.sidebar-nav-toc').toggleClass('current'); $('.sidebar-nav-overview').toggleClass('current'); - + $tocWrapper.css('display', 'block'); $tocWrapper.velocity('fadeIn'); - + $view.css('display', 'none'); $view.velocity('fadeOut'); }); - + $('.sidebar-nav-overview').on('click', function () { $('.sidebar-nav-toc').toggleClass('current'); $('.sidebar-nav-overview').toggleClass('current'); - + $tocWrapper.css('display', 'none'); $tocWrapper.velocity('fadeOut'); - + $view.css('display', 'block'); $view.velocity('fadeIn'); }); diff --git a/source/js/stun-boot.js b/source/js/stun-boot.js index d25a72d..7345503 100644 --- a/source/js/stun-boot.js +++ b/source/js/stun-boot.js @@ -1,5 +1,5 @@ $(document).ready(function () { - CONFIG.shortcuts.switch_post && Stun.utils.registerSwitchPost(); + CONFIG.shortcuts.switch_post && Stun.utils.registerHotkeyToSwitchPost(); // Not reload this, because it's changeless. if (CONFIG.external_link) { @@ -7,11 +7,12 @@ $(document).ready(function () { } Stun.utils.pjaxReloadBoot = function () { + this.initTocDisplay(); this.addCopyButtonToCopyright(); this.registerCopyEvent(); CONFIG.reward && this.registerShowReward(); - CONFIG.gallery_waterfall && this.galleryWaterFall(); - CONFIG.lazyload && this.lazyLoadImages(); + CONFIG.gallery_waterfall && this.showImageToWaterfall(); + CONFIG.lazyload && this.lazyLoadImage(); if (CONFIG.external_link) { var WRAPPER = '.archive-inner, .post-title'; diff --git a/source/js/utils.js b/source/js/utils.js index 3c4c82f..5e61d33 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -174,6 +174,13 @@ Stun.utils = Stun.$u = { return false; } }, + initTocDisplay: function () { + if ($('.post-body').find('h1,h2,h3,h4,h5,h6')[0]) return; + + $('.sidebar-nav').addClass('hide'); + $('.sidebar-toc').addClass('hide'); + $('.sidebar-overview').removeClass('hide'); + }, // Wrap images with fancybox support. wrapImageWithFancyBox: function () { $('.content img').not(':hidden').each(function () { @@ -223,7 +230,7 @@ Stun.utils = Stun.$u = { }); }, // Display the image in the gallery as a waterfall. - galleryWaterFall: function () { + showImageToWaterfall: function () { var gConfig = CONFIG.gallery_waterfall; var colWidth = parseInt(gConfig.col_width); var colGapX = parseInt(gConfig.gap_x); @@ -239,7 +246,7 @@ Stun.utils = Stun.$u = { }); }, // Lazy load the images of post. - lazyLoadImages: function () { + lazyLoadImage: function () { $('img.lazyload').lazyload(); }, // Add a mark icon to the link with `target="_blank"` attribute. @@ -260,7 +267,7 @@ Stun.utils = Stun.$u = { .append($icon); }, // Switch to the prev / next post by shortcuts. - registerSwitchPost: function () { + registerHotkeyToSwitchPost: function () { var _this = this; $(document).on('keydown', function (e) { -- GitLab