Skip to content

Commit

Permalink
Prefer object-shorthand
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed May 7, 2024
1 parent 659e82b commit 524c369
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions scripts/tags/group-pictures.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -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 = [];
Expand All @@ -106,13 +106,13 @@ const templates = {
return this.getHTML(pictureArr);
},

getHTML: function(rows) {
getHTML(rows) {
return rows.map(row => {
return `<div class="group-picture-row">${this.getColumnHTML(row)}</div>`;
}).join('');
},

getColumnHTML: function(pictures) {
getColumnHTML(pictures) {
return pictures.map(picture => {
return `<div class="group-picture-column">${picture}</div>`;
}).join('');
Expand Down
16 changes: 8 additions & 8 deletions source/js/motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -30,7 +30,7 @@ NexT.motion.integrator = {
};

NexT.motion.middleWares = {
header: function() {
header() {
const sequence = [];

function getMistLineSettings(targets) {
Expand Down Expand Up @@ -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 => {
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -131,7 +131,7 @@ NexT.motion.middleWares = {
return sequence;
},

footer: function() {
footer() {
return [{
targets: document.querySelector('.footer'),
opacity: 1
Expand Down
2 changes: 1 addition & 1 deletion source/js/pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions source/js/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ 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));
document.querySelector('.sidebar-toggle').addEventListener('click', this.clickHandler.bind(this));
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');
Expand All @@ -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) => {
Expand All @@ -42,7 +42,7 @@ document.addEventListener('DOMContentLoaded', () => {
});
});
},
hideSidebar: function() {
hideSidebar() {
document.body.classList.remove('sidebar-active');
}
};
Expand Down
38 changes: 19 additions & 19 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -129,15 +129,15 @@ NexT.utils = {
});
},

wrapTableWithBox: function() {
wrapTableWithBox() {
document.querySelectorAll('table').forEach(element => {
const box = document.createElement('div');
box.className = 'table-container';
element.wrap(box);
});
},

registerVideoIframe: function() {
registerVideoIframe() {
document.querySelectorAll('iframe').forEach(element => {
const supported = [
'www.youtube.com',
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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')) {
Expand All @@ -280,15 +280,15 @@ 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);
target.classList.toggle('menu-item-active', target.hostname === location.hostname && (isSamePath || isSubPath));
});
},

registerLangSelect: function() {
registerLangSelect() {
const selects = document.querySelectorAll('.lang-select');
selects.forEach(sel => {
sel.value = CONFIG.page.lang;
Expand All @@ -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.
Expand All @@ -325,15 +325,15 @@ NexT.utils = {
this.updateActiveNav();
},

registerPostReward: function() {
registerPostReward() {
const button = document.querySelector('.reward-container button');
if (!button) return;
button.addEventListener('click', () => {
document.querySelector('.post-reward').classList.toggle('active');
});
},

activateNavByIndex: function(index) {
activateNavByIndex(index) {
const nav = document.querySelector('.post-toc:not(.placeholder-toc) .nav');
if (!nav) return;

Expand Down Expand Up @@ -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)');
Expand All @@ -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;
Expand All @@ -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');
Expand All @@ -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
Expand Down Expand Up @@ -479,7 +479,7 @@ NexT.utils = {
});
},

loadComments: function(selector, legacyCallback) {
loadComments(selector, legacyCallback) {
if (legacyCallback) {
return this.loadComments(selector).then(legacyCallback);
}
Expand All @@ -500,7 +500,7 @@ NexT.utils = {
});
},

debounce: function(func, wait) {
debounce(func, wait) {
let timeout;
return function(...args) {
const context = this;
Expand Down

0 comments on commit 524c369

Please sign in to comment.