Add fallback if NexT.boot.motion is failed (#953)

Co-authored-by: Mimi <1119186082@qq.com>
This commit is contained in:
where where 2026-06-23 11:31:11 +08:00 committed by GitHub
parent 8aa84d79f9
commit 1746ed135c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 86 additions and 70 deletions

View File

@ -3,7 +3,7 @@
NexT.boot = {}; NexT.boot = {};
NexT.boot.registerEvents = function() { NexT.boot.registerEvents = function() {
try {
NexT.utils.registerScrollPercent(); NexT.utils.registerScrollPercent();
NexT.utils.registerCanIUseTag(); NexT.utils.registerCanIUseTag();
NexT.utils.updateFooterPosition(); NexT.utils.updateFooterPosition();
@ -34,14 +34,15 @@ NexT.boot.registerEvents = function() {
window.addEventListener('tabs:click', e => { window.addEventListener('tabs:click', e => {
NexT.utils.registerCodeblock(e.target); 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.prism && window.Prism.highlightAll();
CONFIG.mediumzoom && window.mediumZoom('.post-body :not(a) > img, .post-body > img', { CONFIG.mediumzoom && window.mediumZoom('.post-body :not(a) > img, .post-body > img', {
background: 'var(--content-bg-color)' background: 'var(--content-bg-color)'
@ -69,17 +70,26 @@ NexT.boot.refresh = function() {
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) {
try {
NexT.motion.integrator NexT.motion.integrator
.add(NexT.motion.middleWares.header) .add(NexT.motion.middleWares.header)
.add(NexT.motion.middleWares.sidebar) .add(NexT.motion.middleWares.sidebar)
.add(NexT.motion.middleWares.postList) .add(NexT.motion.middleWares.postList)
.add(NexT.motion.middleWares.footer) .add(NexT.motion.middleWares.footer)
.bootstrap(); .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();
}; };

View File

@ -34,6 +34,7 @@ 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) {
try {
NexT.motion.integrator NexT.motion.integrator
.init() .init()
.add(NexT.motion.middleWares.subMenu) .add(NexT.motion.middleWares.subMenu)
@ -41,6 +42,11 @@ document.addEventListener('pjax:success', () => {
.add(NexT.motion.middleWares.sidebar) .add(NexT.motion.middleWares.sidebar)
.add(NexT.motion.middleWares.postList) .add(NexT.motion.middleWares.postList)
.bootstrap(); .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)');