Prefer object-shorthand

This commit is contained in:
Mimi 2024-05-07 16:52:31 +08:00
parent 659e82b452
commit 524c3693f2
5 changed files with 38 additions and 38 deletions

View File

@ -80,7 +80,7 @@ function groupBy(group, data) {
const templates = { const templates = {
dispatch: function(pictures, group, layout) { dispatch(pictures, group, layout) {
const rule = LAYOUTS[group] ? LAYOUTS[group][layout] : null; const rule = LAYOUTS[group] ? LAYOUTS[group][layout] : null;
return rule ? this.getHTML(groupBy(rule, pictures)) : this.defaults(pictures); return rule ? this.getHTML(groupBy(rule, pictures)) : this.defaults(pictures);
}, },
@ -94,7 +94,7 @@ const templates = {
* *
* @param pictures * @param pictures
*/ */
defaults: function(pictures) { defaults(pictures) {
const ROW_SIZE = 3; const ROW_SIZE = 3;
const rows = pictures.length / ROW_SIZE; const rows = pictures.length / ROW_SIZE;
const pictureArr = []; const pictureArr = [];
@ -106,13 +106,13 @@ const templates = {
return this.getHTML(pictureArr); return this.getHTML(pictureArr);
}, },
getHTML: function(rows) { getHTML(rows) {
return rows.map(row => { return rows.map(row => {
return `<div class="group-picture-row">${this.getColumnHTML(row)}</div>`; return `<div class="group-picture-row">${this.getColumnHTML(row)}</div>`;
}).join(''); }).join('');
}, },
getColumnHTML: function(pictures) { getColumnHTML(pictures) {
return pictures.map(picture => { return pictures.map(picture => {
return `<div class="group-picture-column">${picture}</div>`; return `<div class="group-picture-column">${picture}</div>`;
}).join(''); }).join('');

View File

@ -4,17 +4,17 @@ NexT.motion = {};
NexT.motion.integrator = { NexT.motion.integrator = {
queue: [], queue: [],
init : function() { init() {
this.queue = []; this.queue = [];
return this; return this;
}, },
add: function(fn) { add(fn) {
const sequence = fn(); const sequence = fn();
if (CONFIG.motion.async) this.queue.push(sequence); if (CONFIG.motion.async) this.queue.push(sequence);
else this.queue = this.queue.concat(sequence); else this.queue = this.queue.concat(sequence);
return this; return this;
}, },
bootstrap: function() { bootstrap() {
if (!CONFIG.motion.async) this.queue = [this.queue]; if (!CONFIG.motion.async) this.queue = [this.queue];
this.queue.forEach(sequence => { this.queue.forEach(sequence => {
const timeline = window.anime.timeline({ const timeline = window.anime.timeline({
@ -30,7 +30,7 @@ NexT.motion.integrator = {
}; };
NexT.motion.middleWares = { NexT.motion.middleWares = {
header: function() { header() {
const sequence = []; const sequence = [];
function getMistLineSettings(targets) { function getMistLineSettings(targets) {
@ -73,7 +73,7 @@ NexT.motion.middleWares = {
return sequence; return sequence;
}, },
subMenu: function() { subMenu() {
const subMenuItem = document.querySelectorAll('.sub-menu .menu-item'); const subMenuItem = document.querySelectorAll('.sub-menu .menu-item');
if (subMenuItem.length > 0) { if (subMenuItem.length > 0) {
subMenuItem.forEach(element => { subMenuItem.forEach(element => {
@ -83,7 +83,7 @@ NexT.motion.middleWares = {
return []; return [];
}, },
postList: function() { postList() {
const sequence = []; const sequence = [];
const { post_block, post_header, post_body, coll_header } = CONFIG.motion.transition; const { post_block, post_header, post_body, coll_header } = CONFIG.motion.transition;
@ -114,7 +114,7 @@ NexT.motion.middleWares = {
return sequence; return sequence;
}, },
sidebar: function() { sidebar() {
const sequence = []; const sequence = [];
const sidebar = document.querySelectorAll('.sidebar-inner'); const sidebar = document.querySelectorAll('.sidebar-inner');
const sidebarTransition = CONFIG.motion.transition.sidebar; const sidebarTransition = CONFIG.motion.transition.sidebar;
@ -131,7 +131,7 @@ NexT.motion.middleWares = {
return sequence; return sequence;
}, },
footer: function() { footer() {
return [{ return [{
targets: document.querySelector('.footer'), targets: document.querySelector('.footer'),
opacity: 1 opacity: 1

View File

@ -12,7 +12,7 @@ const pjax = new Pjax({
'.pjax' '.pjax'
], ],
switches: { switches: {
'.post-toc-wrap': function(oldWrap, newWrap) { '.post-toc-wrap'(oldWrap, newWrap) {
if (newWrap.querySelector('.post-toc')) { if (newWrap.querySelector('.post-toc')) {
Pjax.switches.outerHTML.call(this, oldWrap, newWrap); Pjax.switches.outerHTML.call(this, oldWrap, newWrap);
} else { } else {

View File

@ -6,7 +6,7 @@ document.addEventListener('DOMContentLoaded', () => {
const sidebarToggleMotion = { const sidebarToggleMotion = {
mouse: {}, mouse: {},
init : function() { init() {
window.addEventListener('mousedown', this.mousedownHandler.bind(this)); window.addEventListener('mousedown', this.mousedownHandler.bind(this));
window.addEventListener('mouseup', this.mouseupHandler.bind(this)); window.addEventListener('mouseup', this.mouseupHandler.bind(this));
document.querySelector('.sidebar-dimmer').addEventListener('click', this.clickHandler.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:show', this.showSidebar);
window.addEventListener('sidebar:hide', this.hideSidebar); window.addEventListener('sidebar:hide', this.hideSidebar);
}, },
mousedownHandler: function(event) { mousedownHandler(event) {
this.mouse.X = event.pageX; this.mouse.X = event.pageX;
this.mouse.Y = event.pageY; this.mouse.Y = event.pageY;
}, },
mouseupHandler: function(event) { mouseupHandler(event) {
const deltaX = event.pageX - this.mouse.X; const deltaX = event.pageX - this.mouse.X;
const deltaY = event.pageY - this.mouse.Y; const deltaY = event.pageY - this.mouse.Y;
const clickingBlankPart = Math.hypot(deltaX, deltaY) < 20 && event.target.matches('.main'); const clickingBlankPart = Math.hypot(deltaX, deltaY) < 20 && event.target.matches('.main');
@ -27,10 +27,10 @@ document.addEventListener('DOMContentLoaded', () => {
this.hideSidebar(); this.hideSidebar();
} }
}, },
clickHandler: function() { clickHandler() {
document.body.classList.contains('sidebar-active') ? this.hideSidebar() : this.showSidebar(); document.body.classList.contains('sidebar-active') ? this.hideSidebar() : this.showSidebar();
}, },
showSidebar: function() { showSidebar() {
document.body.classList.add('sidebar-active'); document.body.classList.add('sidebar-active');
const animateAction = isRight ? 'fadeInRight' : 'fadeInLeft'; const animateAction = isRight ? 'fadeInRight' : 'fadeInLeft';
document.querySelectorAll('.sidebar .animated').forEach((element, index) => { document.querySelectorAll('.sidebar .animated').forEach((element, index) => {
@ -42,7 +42,7 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
}); });
}, },
hideSidebar: function() { hideSidebar() {
document.body.classList.remove('sidebar-active'); document.body.classList.remove('sidebar-active');
} }
}; };

View File

@ -23,7 +23,7 @@ HTMLElement.prototype.wrap = function(wrapper) {
NexT.utils = { NexT.utils = {
registerExtURL: function() { registerExtURL() {
document.querySelectorAll('span.exturl').forEach(element => { document.querySelectorAll('span.exturl').forEach(element => {
const link = document.createElement('a'); const link = document.createElement('a');
// https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings // 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; const inited = !!element;
let figure = (inited ? element : document).querySelectorAll('figure.highlight'); let figure = (inited ? element : document).querySelectorAll('figure.highlight');
let isHljsWithWrap = true; let isHljsWithWrap = true;
@ -129,7 +129,7 @@ NexT.utils = {
}); });
}, },
wrapTableWithBox: function() { wrapTableWithBox() {
document.querySelectorAll('table').forEach(element => { document.querySelectorAll('table').forEach(element => {
const box = document.createElement('div'); const box = document.createElement('div');
box.className = 'table-container'; box.className = 'table-container';
@ -137,7 +137,7 @@ NexT.utils = {
}); });
}, },
registerVideoIframe: function() { registerVideoIframe() {
document.querySelectorAll('iframe').forEach(element => { document.querySelectorAll('iframe').forEach(element => {
const supported = [ const supported = [
'www.youtube.com', 'www.youtube.com',
@ -159,7 +159,7 @@ NexT.utils = {
}); });
}, },
updateActiveNav: function() { updateActiveNav() {
if (!Array.isArray(NexT.utils.sections)) return; if (!Array.isArray(NexT.utils.sections)) return;
let index = NexT.utils.sections.findIndex(element => { let index = NexT.utils.sections.findIndex(element => {
return element && element.getBoundingClientRect().top > 10; return element && element.getBoundingClientRect().top > 10;
@ -172,7 +172,7 @@ NexT.utils = {
this.activateNavByIndex(index); this.activateNavByIndex(index);
}, },
registerScrollPercent: function() { registerScrollPercent() {
const backToTop = document.querySelector('.back-to-top'); const backToTop = document.querySelector('.back-to-top');
const readingProgressBar = document.querySelector('.reading-progress-bar'); const readingProgressBar = document.querySelector('.reading-progress-bar');
// For init back to top in sidebar if page was scrolled after page refresh. // 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). * Tabs tag listener (without twitter bootstrap).
*/ */
registerTabsTag: function() { registerTabsTag() {
// Binding `nav-tabs` & `tab-content` by real time permalink changing. // Binding `nav-tabs` & `tab-content` by real time permalink changing.
document.querySelectorAll('.tabs ul.nav-tabs .tab').forEach(element => { document.querySelectorAll('.tabs ul.nav-tabs .tab').forEach(element => {
element.addEventListener('click', event => { element.addEventListener('click', event => {
@ -269,7 +269,7 @@ NexT.utils = {
window.dispatchEvent(new Event('tabs:register')); window.dispatchEvent(new Event('tabs:register'));
}, },
registerCanIUseTag: function() { registerCanIUseTag() {
// Get responsive height passed from iframe. // Get responsive height passed from iframe.
window.addEventListener('message', ({ data }) => { window.addEventListener('message', ({ data }) => {
if (typeof data === 'string' && data.includes('ciu_embed')) { if (typeof data === 'string' && data.includes('ciu_embed')) {
@ -280,7 +280,7 @@ NexT.utils = {
}, false); }, false);
}, },
registerActiveMenuItem: function() { registerActiveMenuItem() {
document.querySelectorAll('.menu-item a[href]').forEach(target => { document.querySelectorAll('.menu-item a[href]').forEach(target => {
const isSamePath = target.pathname === location.pathname || target.pathname === location.pathname.replace('index.html', ''); 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); 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'); const selects = document.querySelectorAll('.lang-select');
selects.forEach(sel => { selects.forEach(sel => {
sel.value = CONFIG.page.lang; 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 => { this.sections = [...document.querySelectorAll('.post-toc:not(.placeholder-toc) li a.nav-link')].map(element => {
const target = document.getElementById(decodeURI(element.getAttribute('href')).replace('#', '')); const target = document.getElementById(decodeURI(element.getAttribute('href')).replace('#', ''));
// TOC item animation navigate. // TOC item animation navigate.
@ -325,7 +325,7 @@ NexT.utils = {
this.updateActiveNav(); this.updateActiveNav();
}, },
registerPostReward: function() { registerPostReward() {
const button = document.querySelector('.reward-container button'); const button = document.querySelector('.reward-container button');
if (!button) return; if (!button) return;
button.addEventListener('click', () => { button.addEventListener('click', () => {
@ -333,7 +333,7 @@ NexT.utils = {
}); });
}, },
activateNavByIndex: function(index) { activateNavByIndex(index) {
const nav = document.querySelector('.post-toc:not(.placeholder-toc) .nav'); const nav = document.querySelector('.post-toc:not(.placeholder-toc) .nav');
if (!nav) return; if (!nav) return;
@ -374,7 +374,7 @@ NexT.utils = {
}); });
}, },
updateSidebarPosition: function() { updateSidebarPosition() {
if (window.innerWidth < 1200 || CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') return; if (window.innerWidth < 1200 || CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') return;
// Expand sidebar on post detail page by default, when post has a toc. // Expand sidebar on post detail page by default, when post has a toc.
const hasTOC = document.querySelector('.post-toc:not(.placeholder-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 sidebar = document.querySelector('.sidebar-inner');
const activeClassNames = ['sidebar-toc-active', 'sidebar-overview-active']; const activeClassNames = ['sidebar-toc-active', 'sidebar-overview-active'];
if (sidebar.classList.contains(activeClassNames[index])) return; if (sidebar.classList.contains(activeClassNames[index])) return;
@ -415,7 +415,7 @@ NexT.utils = {
sidebar.classList.replace(activeClassNames[1 - index], activeClassNames[index]); sidebar.classList.replace(activeClassNames[1 - index], activeClassNames[index]);
}, },
updateFooterPosition: function() { updateFooterPosition() {
if (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') return; if (CONFIG.scheme === 'Pisces' || CONFIG.scheme === 'Gemini') return;
function updateFooterPosition() { function updateFooterPosition() {
const footer = document.querySelector('.footer'); const footer = document.querySelector('.footer');
@ -428,7 +428,7 @@ NexT.utils = {
window.addEventListener('scroll', updateFooterPosition, { passive: true }); window.addEventListener('scroll', updateFooterPosition, { passive: true });
}, },
getScript: function(src, options = {}, legacyCondition) { getScript(src, options = {}, legacyCondition) {
if (typeof options === 'function') { if (typeof options === 'function') {
return this.getScript(src, { return this.getScript(src, {
condition: legacyCondition condition: legacyCondition
@ -479,7 +479,7 @@ NexT.utils = {
}); });
}, },
loadComments: function(selector, legacyCallback) { loadComments(selector, legacyCallback) {
if (legacyCallback) { if (legacyCallback) {
return this.loadComments(selector).then(legacyCallback); return this.loadComments(selector).then(legacyCallback);
} }
@ -500,7 +500,7 @@ NexT.utils = {
}); });
}, },
debounce: function(func, wait) { debounce(func, wait) {
let timeout; let timeout;
return function(...args) { return function(...args) {
const context = this; const context = this;