mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-06-23 12:31:14 +00:00
Add fallback if NexT.boot.motion is failed (#953)
Co-authored-by: Mimi <1119186082@qq.com>
This commit is contained in:
parent
8aa84d79f9
commit
1746ed135c
@ -3,83 +3,93 @@
|
|||||||
NexT.boot = {};
|
NexT.boot = {};
|
||||||
|
|
||||||
NexT.boot.registerEvents = function() {
|
NexT.boot.registerEvents = function() {
|
||||||
|
try {
|
||||||
|
NexT.utils.registerScrollPercent();
|
||||||
|
NexT.utils.registerCanIUseTag();
|
||||||
|
NexT.utils.updateFooterPosition();
|
||||||
|
|
||||||
NexT.utils.registerScrollPercent();
|
// Mobile top menu bar.
|
||||||
NexT.utils.registerCanIUseTag();
|
document.querySelector('.site-nav-toggle .toggle').addEventListener('click', event => {
|
||||||
NexT.utils.updateFooterPosition();
|
event.currentTarget.classList.toggle('toggle-close');
|
||||||
|
const siteNav = document.querySelector('.site-nav');
|
||||||
// Mobile top menu bar.
|
if (!siteNav) return;
|
||||||
document.querySelector('.site-nav-toggle .toggle').addEventListener('click', event => {
|
siteNav.style.setProperty('--scroll-height', siteNav.scrollHeight + 'px');
|
||||||
event.currentTarget.classList.toggle('toggle-close');
|
document.body.classList.toggle('site-nav-on');
|
||||||
const siteNav = document.querySelector('.site-nav');
|
|
||||||
if (!siteNav) return;
|
|
||||||
siteNav.style.setProperty('--scroll-height', siteNav.scrollHeight + 'px');
|
|
||||||
document.body.classList.toggle('site-nav-on');
|
|
||||||
});
|
|
||||||
|
|
||||||
document.querySelectorAll('.sidebar-nav li').forEach((element, index) => {
|
|
||||||
element.addEventListener('click', () => {
|
|
||||||
NexT.utils.activateSidebarPanel(index);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
window.addEventListener('hashchange', () => {
|
document.querySelectorAll('.sidebar-nav li').forEach((element, index) => {
|
||||||
const tHash = location.hash;
|
element.addEventListener('click', () => {
|
||||||
if (tHash !== '' && !tHash.match(/%\S{2}/)) {
|
NexT.utils.activateSidebarPanel(index);
|
||||||
const target = document.querySelector(`.tabs ul.nav-tabs li a[href="${tHash}"]`);
|
});
|
||||||
target?.click();
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
window.addEventListener('tabs:click', e => {
|
window.addEventListener('hashchange', () => {
|
||||||
NexT.utils.registerCodeblock(e.target);
|
const tHash = location.hash;
|
||||||
});
|
if (tHash !== '' && !tHash.match(/%\S{2}/)) {
|
||||||
|
const target = document.querySelector(`.tabs ul.nav-tabs li a[href="${tHash}"]`);
|
||||||
|
target?.click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('tabs:click', e => {
|
||||||
|
NexT.utils.registerCodeblock(e.target);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Something went wrong while NexT registering events', error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
NexT.boot.refresh = function() {
|
NexT.boot.refresh = function() {
|
||||||
|
try {
|
||||||
/**
|
// Register JS handlers by condition option.
|
||||||
* Register JS handlers by condition option.
|
// Need to add config option in Front-End at 'scripts/helpers/next-config.js' file.
|
||||||
* Need to add config option in Front-End at 'scripts/helpers/next-config.js' file.
|
CONFIG.prism && window.Prism.highlightAll();
|
||||||
*/
|
CONFIG.mediumzoom && window.mediumZoom('.post-body :not(a) > img, .post-body > img', {
|
||||||
CONFIG.prism && window.Prism.highlightAll();
|
background: 'var(--content-bg-color)'
|
||||||
CONFIG.mediumzoom && window.mediumZoom('.post-body :not(a) > img, .post-body > img', {
|
});
|
||||||
background: 'var(--content-bg-color)'
|
CONFIG.lazyload && window.lozad('.post-body img').observe();
|
||||||
});
|
if (CONFIG.pangu) {
|
||||||
CONFIG.lazyload && window.lozad('.post-body img').observe();
|
// Polyfill for requestIdleCallback if not supported
|
||||||
if (CONFIG.pangu) {
|
if (!window.requestIdleCallback) {
|
||||||
// Polyfill for requestIdleCallback if not supported
|
window.requestIdleCallback = function(cb) {
|
||||||
if (!window.requestIdleCallback) {
|
cb({
|
||||||
window.requestIdleCallback = function(cb) {
|
didTimeout : false,
|
||||||
cb({
|
timeRemaining: () => 100
|
||||||
didTimeout : false,
|
});
|
||||||
timeRemaining: () => 100
|
};
|
||||||
});
|
}
|
||||||
};
|
[...document.getElementsByTagName('main')].forEach(e => window.pangu.spacingNode(e));
|
||||||
}
|
}
|
||||||
[...document.getElementsByTagName('main')].forEach(e => window.pangu.spacingNode(e));
|
|
||||||
}
|
|
||||||
|
|
||||||
CONFIG.exturl && NexT.utils.registerExtURL();
|
CONFIG.exturl && NexT.utils.registerExtURL();
|
||||||
NexT.utils.wrapTableWithBox();
|
NexT.utils.wrapTableWithBox();
|
||||||
NexT.utils.registerCodeblock();
|
NexT.utils.registerCodeblock();
|
||||||
NexT.utils.registerTabsTag();
|
NexT.utils.registerTabsTag();
|
||||||
NexT.utils.registerActiveMenuItem();
|
NexT.utils.registerActiveMenuItem();
|
||||||
NexT.utils.registerLangSelect();
|
NexT.utils.registerLangSelect();
|
||||||
NexT.utils.registerSidebarTOC();
|
NexT.utils.registerSidebarTOC();
|
||||||
NexT.utils.registerPostReward();
|
NexT.utils.registerPostReward();
|
||||||
NexT.utils.registerVideoIframe();
|
NexT.utils.registerVideoIframe();
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Something went wrong during NexT refresh', error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
NexT.boot.motion = function() {
|
NexT.boot.motion = function() {
|
||||||
// Define Motion Sequence & Bootstrap Motion.
|
// Define Motion Sequence & Bootstrap Motion.
|
||||||
if (CONFIG.motion.enable) {
|
if (CONFIG.motion.enable) {
|
||||||
NexT.motion.integrator
|
try {
|
||||||
.add(NexT.motion.middleWares.header)
|
NexT.motion.integrator
|
||||||
.add(NexT.motion.middleWares.sidebar)
|
.add(NexT.motion.middleWares.header)
|
||||||
.add(NexT.motion.middleWares.postList)
|
.add(NexT.motion.middleWares.sidebar)
|
||||||
.add(NexT.motion.middleWares.footer)
|
.add(NexT.motion.middleWares.postList)
|
||||||
.bootstrap();
|
.add(NexT.motion.middleWares.footer)
|
||||||
|
.bootstrap();
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('NexT Motion Error, fallback to static mode', error);
|
||||||
|
document.body.classList.remove('use-motion');
|
||||||
|
CONFIG.motion.enable = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
NexT.utils.updateSidebarPosition();
|
NexT.utils.updateSidebarPosition();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -34,13 +34,19 @@ document.addEventListener('pjax:success', () => {
|
|||||||
NexT.boot.refresh();
|
NexT.boot.refresh();
|
||||||
// Define Motion Sequence & Bootstrap Motion.
|
// Define Motion Sequence & Bootstrap Motion.
|
||||||
if (CONFIG.motion.enable) {
|
if (CONFIG.motion.enable) {
|
||||||
NexT.motion.integrator
|
try {
|
||||||
.init()
|
NexT.motion.integrator
|
||||||
.add(NexT.motion.middleWares.subMenu)
|
.init()
|
||||||
// Add sidebar-post-related transition.
|
.add(NexT.motion.middleWares.subMenu)
|
||||||
.add(NexT.motion.middleWares.sidebar)
|
// Add sidebar-post-related transition.
|
||||||
.add(NexT.motion.middleWares.postList)
|
.add(NexT.motion.middleWares.sidebar)
|
||||||
.bootstrap();
|
.add(NexT.motion.middleWares.postList)
|
||||||
|
.bootstrap();
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('NexT Motion Error, fallback to static mode', error);
|
||||||
|
document.body.classList.remove('use-motion');
|
||||||
|
CONFIG.motion.enable = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (CONFIG.sidebar.display !== 'remove') {
|
if (CONFIG.sidebar.display !== 'remove') {
|
||||||
const hasTOC = document.querySelector('.post-toc:not(.placeholder-toc)');
|
const hasTOC = document.querySelector('.post-toc:not(.placeholder-toc)');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user