mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-18 18:33:42 +00:00
Prefer object-shorthand
This commit is contained in:
parent
659e82b452
commit
524c3693f2
@ -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 `<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('');
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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');
|
||||
}
|
||||
};
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user