From 524c3693f21b7fd3d3ee75e7e614afe7217a0d7e Mon Sep 17 00:00:00 2001
From: Mimi <1119186082@qq.com>
Date: Tue, 7 May 2024 16:52:31 +0800
Subject: [PATCH] Prefer object-shorthand
---
scripts/tags/group-pictures.js | 8 +++----
source/js/motion.js | 16 +++++++-------
source/js/pjax.js | 2 +-
source/js/sidebar.js | 12 +++++------
source/js/utils.js | 38 +++++++++++++++++-----------------
5 files changed, 38 insertions(+), 38 deletions(-)
diff --git a/scripts/tags/group-pictures.js b/scripts/tags/group-pictures.js
index d2007dcd5..0a68bb04e 100644
--- a/scripts/tags/group-pictures.js
+++ b/scripts/tags/group-pictures.js
@@ -80,7 +80,7 @@ function groupBy(group, data) {
const templates = {
- dispatch: function(pictures, group, layout) {
+ dispatch(pictures, group, layout) {
const rule = LAYOUTS[group] ? LAYOUTS[group][layout] : null;
return rule ? this.getHTML(groupBy(rule, pictures)) : this.defaults(pictures);
},
@@ -94,7 +94,7 @@ const templates = {
*
* @param pictures
*/
- defaults: function(pictures) {
+ defaults(pictures) {
const ROW_SIZE = 3;
const rows = pictures.length / ROW_SIZE;
const pictureArr = [];
@@ -106,13 +106,13 @@ const templates = {
return this.getHTML(pictureArr);
},
- getHTML: function(rows) {
+ getHTML(rows) {
return rows.map(row => {
return `
${this.getColumnHTML(row)}
`;
}).join('');
},
- getColumnHTML: function(pictures) {
+ getColumnHTML(pictures) {
return pictures.map(picture => {
return `${picture}
`;
}).join('');
diff --git a/source/js/motion.js b/source/js/motion.js
index fb4669d45..87f1d8fda 100644
--- a/source/js/motion.js
+++ b/source/js/motion.js
@@ -4,17 +4,17 @@ NexT.motion = {};
NexT.motion.integrator = {
queue: [],
- init : function() {
+ init() {
this.queue = [];
return this;
},
- add: function(fn) {
+ add(fn) {
const sequence = fn();
if (CONFIG.motion.async) this.queue.push(sequence);
else this.queue = this.queue.concat(sequence);
return this;
},
- bootstrap: function() {
+ bootstrap() {
if (!CONFIG.motion.async) this.queue = [this.queue];
this.queue.forEach(sequence => {
const timeline = window.anime.timeline({
@@ -30,7 +30,7 @@ NexT.motion.integrator = {
};
NexT.motion.middleWares = {
- header: function() {
+ header() {
const sequence = [];
function getMistLineSettings(targets) {
@@ -73,7 +73,7 @@ NexT.motion.middleWares = {
return sequence;
},
- subMenu: function() {
+ subMenu() {
const subMenuItem = document.querySelectorAll('.sub-menu .menu-item');
if (subMenuItem.length > 0) {
subMenuItem.forEach(element => {
@@ -83,7 +83,7 @@ NexT.motion.middleWares = {
return [];
},
- postList: function() {
+ postList() {
const sequence = [];
const { post_block, post_header, post_body, coll_header } = CONFIG.motion.transition;
@@ -114,7 +114,7 @@ NexT.motion.middleWares = {
return sequence;
},
- sidebar: function() {
+ sidebar() {
const sequence = [];
const sidebar = document.querySelectorAll('.sidebar-inner');
const sidebarTransition = CONFIG.motion.transition.sidebar;
@@ -131,7 +131,7 @@ NexT.motion.middleWares = {
return sequence;
},
- footer: function() {
+ footer() {
return [{
targets: document.querySelector('.footer'),
opacity: 1
diff --git a/source/js/pjax.js b/source/js/pjax.js
index eaf266072..a9a9dd384 100644
--- a/source/js/pjax.js
+++ b/source/js/pjax.js
@@ -12,7 +12,7 @@ const pjax = new Pjax({
'.pjax'
],
switches: {
- '.post-toc-wrap': function(oldWrap, newWrap) {
+ '.post-toc-wrap'(oldWrap, newWrap) {
if (newWrap.querySelector('.post-toc')) {
Pjax.switches.outerHTML.call(this, oldWrap, newWrap);
} else {
diff --git a/source/js/sidebar.js b/source/js/sidebar.js
index 6ab3c6b05..3c49861b0 100644
--- a/source/js/sidebar.js
+++ b/source/js/sidebar.js
@@ -6,7 +6,7 @@ document.addEventListener('DOMContentLoaded', () => {
const sidebarToggleMotion = {
mouse: {},
- init : function() {
+ init() {
window.addEventListener('mousedown', this.mousedownHandler.bind(this));
window.addEventListener('mouseup', this.mouseupHandler.bind(this));
document.querySelector('.sidebar-dimmer').addEventListener('click', this.clickHandler.bind(this));
@@ -14,11 +14,11 @@ document.addEventListener('DOMContentLoaded', () => {
window.addEventListener('sidebar:show', this.showSidebar);
window.addEventListener('sidebar:hide', this.hideSidebar);
},
- mousedownHandler: function(event) {
+ mousedownHandler(event) {
this.mouse.X = event.pageX;
this.mouse.Y = event.pageY;
},
- mouseupHandler: function(event) {
+ mouseupHandler(event) {
const deltaX = event.pageX - this.mouse.X;
const deltaY = event.pageY - this.mouse.Y;
const clickingBlankPart = Math.hypot(deltaX, deltaY) < 20 && event.target.matches('.main');
@@ -27,10 +27,10 @@ document.addEventListener('DOMContentLoaded', () => {
this.hideSidebar();
}
},
- clickHandler: function() {
+ clickHandler() {
document.body.classList.contains('sidebar-active') ? this.hideSidebar() : this.showSidebar();
},
- showSidebar: function() {
+ showSidebar() {
document.body.classList.add('sidebar-active');
const animateAction = isRight ? 'fadeInRight' : 'fadeInLeft';
document.querySelectorAll('.sidebar .animated').forEach((element, index) => {
@@ -42,7 +42,7 @@ document.addEventListener('DOMContentLoaded', () => {
});
});
},
- hideSidebar: function() {
+ hideSidebar() {
document.body.classList.remove('sidebar-active');
}
};
diff --git a/source/js/utils.js b/source/js/utils.js
index 2822e7b93..89b88a42a 100644
--- a/source/js/utils.js
+++ b/source/js/utils.js
@@ -23,7 +23,7 @@ HTMLElement.prototype.wrap = function(wrapper) {
NexT.utils = {
- registerExtURL: function() {
+ registerExtURL() {
document.querySelectorAll('span.exturl').forEach(element => {
const link = document.createElement('a');
// https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings
@@ -39,7 +39,7 @@ NexT.utils = {
});
},
- registerCodeblock: function(element) {
+ registerCodeblock(element) {
const inited = !!element;
let figure = (inited ? element : document).querySelectorAll('figure.highlight');
let isHljsWithWrap = true;
@@ -129,7 +129,7 @@ NexT.utils = {
});
},
- wrapTableWithBox: function() {
+ wrapTableWithBox() {
document.querySelectorAll('table').forEach(element => {
const box = document.createElement('div');
box.className = 'table-container';
@@ -137,7 +137,7 @@ NexT.utils = {
});
},
- registerVideoIframe: function() {
+ registerVideoIframe() {
document.querySelectorAll('iframe').forEach(element => {
const supported = [
'www.youtube.com',
@@ -159,7 +159,7 @@ NexT.utils = {
});
},
- updateActiveNav: function() {
+ updateActiveNav() {
if (!Array.isArray(NexT.utils.sections)) return;
let index = NexT.utils.sections.findIndex(element => {
return element && element.getBoundingClientRect().top > 10;
@@ -172,7 +172,7 @@ NexT.utils = {
this.activateNavByIndex(index);
},
- registerScrollPercent: function() {
+ registerScrollPercent() {
const backToTop = document.querySelector('.back-to-top');
const readingProgressBar = document.querySelector('.reading-progress-bar');
// For init back to top in sidebar if page was scrolled after page refresh.
@@ -204,7 +204,7 @@ NexT.utils = {
/**
* Tabs tag listener (without twitter bootstrap).
*/
- registerTabsTag: function() {
+ registerTabsTag() {
// Binding `nav-tabs` & `tab-content` by real time permalink changing.
document.querySelectorAll('.tabs ul.nav-tabs .tab').forEach(element => {
element.addEventListener('click', event => {
@@ -269,7 +269,7 @@ NexT.utils = {
window.dispatchEvent(new Event('tabs:register'));
},
- registerCanIUseTag: function() {
+ registerCanIUseTag() {
// Get responsive height passed from iframe.
window.addEventListener('message', ({ data }) => {
if (typeof data === 'string' && data.includes('ciu_embed')) {
@@ -280,7 +280,7 @@ NexT.utils = {
}, false);
},
- registerActiveMenuItem: function() {
+ registerActiveMenuItem() {
document.querySelectorAll('.menu-item a[href]').forEach(target => {
const isSamePath = target.pathname === location.pathname || target.pathname === location.pathname.replace('index.html', '');
const isSubPath = !CONFIG.root.startsWith(target.pathname) && location.pathname.startsWith(target.pathname);
@@ -288,7 +288,7 @@ NexT.utils = {
});
},
- registerLangSelect: function() {
+ registerLangSelect() {
const selects = document.querySelectorAll('.lang-select');
selects.forEach(sel => {
sel.value = CONFIG.page.lang;
@@ -303,7 +303,7 @@ NexT.utils = {
});
},
- registerSidebarTOC: function() {
+ registerSidebarTOC() {
this.sections = [...document.querySelectorAll('.post-toc:not(.placeholder-toc) li a.nav-link')].map(element => {
const target = document.getElementById(decodeURI(element.getAttribute('href')).replace('#', ''));
// TOC item animation navigate.
@@ -325,7 +325,7 @@ NexT.utils = {
this.updateActiveNav();
},
- registerPostReward: function() {
+ registerPostReward() {
const button = document.querySelector('.reward-container button');
if (!button) return;
button.addEventListener('click', () => {
@@ -333,7 +333,7 @@ NexT.utils = {
});
},
- activateNavByIndex: function(index) {
+ activateNavByIndex(index) {
const nav = document.querySelector('.post-toc:not(.placeholder-toc) .nav');
if (!nav) return;
@@ -374,7 +374,7 @@ NexT.utils = {
});
},
- updateSidebarPosition: function() {
+ updateSidebarPosition() {
if (window.innerWidth < 1200 || CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') return;
// Expand sidebar on post detail page by default, when post has a toc.
const hasTOC = document.querySelector('.post-toc:not(.placeholder-toc)');
@@ -388,7 +388,7 @@ NexT.utils = {
}
},
- activateSidebarPanel: function(index) {
+ activateSidebarPanel(index) {
const sidebar = document.querySelector('.sidebar-inner');
const activeClassNames = ['sidebar-toc-active', 'sidebar-overview-active'];
if (sidebar.classList.contains(activeClassNames[index])) return;
@@ -415,7 +415,7 @@ NexT.utils = {
sidebar.classList.replace(activeClassNames[1 - index], activeClassNames[index]);
},
- updateFooterPosition: function() {
+ updateFooterPosition() {
if (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') return;
function updateFooterPosition() {
const footer = document.querySelector('.footer');
@@ -428,7 +428,7 @@ NexT.utils = {
window.addEventListener('scroll', updateFooterPosition, { passive: true });
},
- getScript: function(src, options = {}, legacyCondition) {
+ getScript(src, options = {}, legacyCondition) {
if (typeof options === 'function') {
return this.getScript(src, {
condition: legacyCondition
@@ -479,7 +479,7 @@ NexT.utils = {
});
},
- loadComments: function(selector, legacyCallback) {
+ loadComments(selector, legacyCallback) {
if (legacyCallback) {
return this.loadComments(selector).then(legacyCallback);
}
@@ -500,7 +500,7 @@ NexT.utils = {
});
},
- debounce: function(func, wait) {
+ debounce(func, wait) {
let timeout;
return function(...args) {
const context = this;