From 5f6271d4b87e0dd760d56eaf7c36ab4b7702b22d Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 2 Jun 2020 01:00:49 +0800 Subject: [PATCH] Some minor fixes --- _config.yml | 5 +---- layout/_partials/comments.njk | 6 ++---- scripts/tags/button.js | 4 +--- source/js/next-boot.js | 5 ++--- source/js/utils.js | 18 ++++++++---------- 5 files changed, 14 insertions(+), 24 deletions(-) diff --git a/_config.yml b/_config.yml index 8754f24..84eae51 100644 --- a/_config.yml +++ b/_config.yml @@ -609,10 +609,7 @@ valine: appKey: # Your leancloud application appkey placeholder: Just go go # Comment box placeholder avatar: mm # Gravatar style - meta: # Custom comment header - - nick - - mail - - link + meta: [nick, mail, link] # Custom comment header pageSize: 10 # Pagination size language: # Language, available values: en, zh-cn visitor: false # Article reading statistic diff --git a/layout/_partials/comments.njk b/layout/_partials/comments.njk index a43bad4..961789f 100644 --- a/layout/_partials/comments.njk +++ b/layout/_partials/comments.njk @@ -20,10 +20,8 @@ commentButton.forEach(element => { let commentClass = element.classList[2]; element.addEventListener('click', () => { - commentButton.forEach(rmActive => rmActive.classList.remove('active')); - element.classList.add('active'); - document.querySelectorAll('.comment-position').forEach(rmActive => rmActive.classList.remove('active')); - document.querySelector(`.comment-position.${commentClass}`).classList.add('active'); + commentButton.forEach(active => active.classList.toggle('active', active === element)); + document.querySelectorAll('.comment-position').forEach(active => active.classList.toggle('active', active.classList.contains(commentClass))); if (CONFIG.comments.storage) { localStorage.setItem('comments_active', commentClass); } diff --git a/scripts/tags/button.js b/scripts/tags/button.js index 4962fc0..8e0a865 100644 --- a/scripts/tags/button.js +++ b/scripts/tags/button.js @@ -22,9 +22,7 @@ function postButton(args) { icon = icon.startsWith('fa') ? icon : 'fa fa-' + icon; title = title.trim(); - return ` 0 ? ` title="${title}"` : ''}> -${icon.length > 0 ? `` : ''}${text} -`; + return ` 0 ? ` title="${title}"` : ''}>${icon.length > 0 ? `` : ''}${text}`; } hexo.extend.tag.register('button', postButton, {ends: false}); diff --git a/source/js/next-boot.js b/source/js/next-boot.js index fc341ad..29aa20c 100644 --- a/source/js/next-boot.js +++ b/source/js/next-boot.js @@ -8,7 +8,7 @@ NexT.boot.registerEvents = function() { NexT.utils.registerCanIUseTag(); // Mobile top menu bar. - document.querySelector('.site-nav-toggle .toggle').addEventListener('click', () => { + document.querySelector('.site-nav-toggle .toggle').addEventListener('click', event => { event.currentTarget.classList.toggle('toggle-close'); const siteNav = document.querySelector('.site-nav'); if (!siteNav) return; @@ -57,9 +57,8 @@ NexT.boot.registerEvents = function() { }); [...item.parentNode.children].forEach(element => { - element.classList.remove(activeTabClassName); + element.classList.toggle(activeTabClassName, element === item); }); - item.classList.add(activeTabClassName); }); }); diff --git a/source/js/utils.js b/source/js/utils.js index 4c8aa8b..e5573d1 100644 --- a/source/js/utils.js +++ b/source/js/utils.js @@ -99,9 +99,9 @@ NexT.utils = { } document.body.removeChild(ta); }); - button.addEventListener('mouseleave', event => { + element.addEventListener('mouseleave', () => { setTimeout(() => { - event.target.querySelector('i').className = 'fa fa-clipboard fa-fw'; + button.querySelector('i').className = 'fa fa-clipboard fa-fw'; }, 300); }); }); @@ -131,7 +131,7 @@ NexT.utils = { let width = Number(element.width); let height = Number(element.height); if (width && height) { - element.parentNode.style.paddingTop = (height / width * 100) + '%'; + box.style.paddingTop = (height / width * 100) + '%'; } } }); @@ -181,14 +181,12 @@ NexT.utils = { if (!target.classList.contains('active')) { // Add & Remove active class on `nav-tabs` & `tab-content`. [...target.parentNode.children].forEach(element => { - element.classList.remove('active'); + element.classList.toggle('active', element === target); }); - target.classList.add('active'); - const tActive = document.getElementById(target.querySelector('a').getAttribute('href').replace('#', '')); + const tActive = document.querySelector(target.querySelector('a').getAttribute('href')); [...tActive.parentNode.children].forEach(element => { - element.classList.remove('active'); + element.classList.toggle('active', element === tActive); }); - tActive.classList.add('active'); // Trigger event tActive.dispatchEvent(new Event('tabs:click', { bubbles: true @@ -203,7 +201,7 @@ NexT.utils = { registerCanIUseTag: function() { // Get responsive height passed from iframe. window.addEventListener('message', ({ data }) => { - if ((typeof data === 'string') && data.includes('ciu_embed')) { + if (typeof data === 'string' && data.includes('ciu_embed')) { const featureID = data.split(':')[1]; const height = data.split(':')[2]; document.querySelector(`iframe[data-feature=${featureID}]`).style.height = parseInt(height, 10) + 5 + 'px'; @@ -237,7 +235,7 @@ NexT.utils = { const navItems = document.querySelectorAll('.post-toc li'); const sections = [...navItems].map(element => { const link = element.querySelector('a.nav-link'); - const target = document.getElementById(decodeURI(link.getAttribute('href')).replace('#', '')); + const target = document.querySelector(decodeURI(link.getAttribute('href'))); // TOC item animation navigate. link.addEventListener('click', event => { event.preventDefault();