Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 74 additions & 62 deletions source/js/next-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,95 @@
NexT.boot = {};

NexT.boot.registerEvents = function() {
try {
NexT.utils.registerScrollPercent();
NexT.utils.registerCanIUseTag();
NexT.utils.updateFooterPosition();

NexT.utils.registerScrollPercent();
NexT.utils.registerCanIUseTag();
NexT.utils.updateFooterPosition();

// Mobile top menu bar.
document.querySelector('.site-nav-toggle .toggle').addEventListener('click', event => {
event.currentTarget.classList.toggle('toggle-close');
const siteNav = document.querySelector('.site-nav');
if (!siteNav) return;
siteNav.style.setProperty('--scroll-height', siteNav.scrollHeight + 'px');
document.body.classList.toggle('site-nav-on');
});
// Mobile top menu bar.
document.querySelector('.site-nav-toggle .toggle').addEventListener('click', event => {
event.currentTarget.classList.toggle('toggle-close');
Comment on lines 5 to +13
Comment on lines 5 to +13
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);
document.querySelectorAll('.sidebar-nav li').forEach((element, index) => {
element.addEventListener('click', () => {
NexT.utils.activateSidebarPanel(index);
});
});
});

window.addEventListener('hashchange', () => {
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('hashchange', () => {
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);
});
window.addEventListener('tabs:click', e => {
NexT.utils.registerCodeblock(e.target);
});
} catch (error) {
console.error('Something went wrong when NexT registering events', error);

Check failure on line 38 in source/js/next-boot.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected console statement. Only these console methods are allowed: warn
Comment thread
wherewhere marked this conversation as resolved.
Outdated
}
};

NexT.boot.refresh = function() {

/**
* Register JS handlers by condition option.
* 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', {
background: 'var(--content-bg-color)'
});
CONFIG.lazyload && window.lozad('.post-body img').observe();
if (CONFIG.pangu) {
// Polyfill for requestIdleCallback if not supported
if (!window.requestIdleCallback) {
window.requestIdleCallback = function(cb) {
cb({
didTimeout : false,
timeRemaining: () => 100
});
};
try {
/**

Check failure on line 44 in source/js/next-boot.js

View workflow job for this annotation

GitHub Actions / linter

Expected line before comment
* Register JS handlers by condition option.
* 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', {
background: 'var(--content-bg-color)'
});
CONFIG.lazyload && window.lozad('.post-body img').observe();
if (CONFIG.pangu) {
// Polyfill for requestIdleCallback if not supported
Comment on lines 42 to +52
if (!window.requestIdleCallback) {
window.requestIdleCallback = function(cb) {
cb({
didTimeout : false,
timeRemaining: () => 100
});
};
}
[...document.getElementsByTagName('main')].forEach(e => window.pangu.spacingNode(e));
Comment on lines +46 to +61
}
[...document.getElementsByTagName('main')].forEach(e => window.pangu.spacingNode(e));
}

CONFIG.exturl && NexT.utils.registerExtURL();
NexT.utils.wrapTableWithBox();
NexT.utils.registerCodeblock();
NexT.utils.registerTabsTag();
NexT.utils.registerActiveMenuItem();
NexT.utils.registerLangSelect();
NexT.utils.registerSidebarTOC();
NexT.utils.registerPostReward();
NexT.utils.registerVideoIframe();
CONFIG.exturl && NexT.utils.registerExtURL();
NexT.utils.wrapTableWithBox();
NexT.utils.registerCodeblock();
NexT.utils.registerTabsTag();
NexT.utils.registerActiveMenuItem();
NexT.utils.registerLangSelect();
NexT.utils.registerSidebarTOC();
NexT.utils.registerPostReward();
NexT.utils.registerVideoIframe();
} catch (error) {
console.error('Something went wrong when NexT refresh', error);

Check failure on line 76 in source/js/next-boot.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected console statement. Only these console methods are allowed: warn
Comment thread
wherewhere marked this conversation as resolved.
Outdated
}
};

NexT.boot.motion = function() {
// Define Motion Sequence & Bootstrap Motion.
if (CONFIG.motion.enable) {
NexT.motion.integrator
.add(NexT.motion.middleWares.header)
.add(NexT.motion.middleWares.sidebar)
.add(NexT.motion.middleWares.postList)
.add(NexT.motion.middleWares.footer)
.bootstrap();
try {
NexT.motion.integrator
.add(NexT.motion.middleWares.header)
.add(NexT.motion.middleWares.sidebar)
.add(NexT.motion.middleWares.postList)
.add(NexT.motion.middleWares.footer)
.bootstrap();
} catch (error) {
console.error('NexT Motion Error, fallback to static mode', error);

Check failure on line 91 in source/js/next-boot.js

View workflow job for this annotation

GitHub Actions / linter

Unexpected console statement. Only these console methods are allowed: warn
document.body.classList.remove("use-motion");

Check failure on line 92 in source/js/next-boot.js

View workflow job for this annotation

GitHub Actions / linter

Strings must use singlequote
Comment thread
wherewhere marked this conversation as resolved.
Outdated
CONFIG.motion.enable = false;
}
Comment thread
wherewhere marked this conversation as resolved.
}
NexT.utils.updateSidebarPosition();
};
Expand Down
Loading