Use script to control comments container show.

This commit is contained in:
凡梦星尘
2022-07-22 18:35:04 +08:00
parent 31f6e21671
commit d42375820d
11 changed files with 97 additions and 95 deletions

View File

@@ -34,7 +34,20 @@ NexT.boot.registerEvents = function() {
NexT.boot.refresh = function() {
if (!NexT.CONFIG.page.isPage) return;
/**
NexT.utils.registerSidebarTOC();
NexT.utils.replacePostCRLink();
NexT.utils.registerCopyCode();
NexT.utils.registerPostReward();
if(NexT.CONFIG.page.comments) {
NexT.utils.initCommontesDispaly();
NexT.utils.registerCommonSwitch();
} else {
NexT.utils.hideCommontes();
}
//TODO
/**
* Register JS handlers by condition option.
* Need to add config option in Front-End at 'scripts/helpers/next-config.js' file.
*/
@@ -44,16 +57,9 @@ NexT.boot.refresh = function() {
});*/
// NexT.CONFIG.lazyload && window.lozad('.post-body img').observe();
// NexT.CONFIG.pangu && window.pangu.spacingPage();
NexT.utils.replacePostCRLink();
NexT.utils.initCommontesDispaly();
NexT.CONFIG.copybtn && NexT.utils.registerCopyCode();
/*NexT.utils.registerTabsTag();
NexT.utils.registerActiveMenuItem();
NexT.utils.registerLangSelect();*/
NexT.utils.registerSidebarTOC();
NexT.utils.registerPostReward();
NexT.utils.registerCommonSwitch();
/*NexT.utils.wrapTableWithBox();
NexT.utils.registerVideoIframe();*/

View File

@@ -2,18 +2,18 @@ document.addEventListener('DOMContentLoaded', () => {
const element = '.artalk-container';
if (!NexT.CONFIG.page.comments
|| !NexT.CONFIG.page.artalk
|| !NexT.CONFIG.artalk
|| !NexT.utils.checkDOMExist(element)) return;
const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.page.artalk.css);
const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.artalk.css);
NexT.utils.getStyle(artalk_css, null);
const artalk_js = NexT.utils.getCDNResource(NexT.CONFIG.page.artalk.js);
const artalk_js = NexT.utils.getCDNResource(NexT.CONFIG.artalk.js);
const {
site,
placeholder,
server,
} = NexT.CONFIG.page.artalk.cfg;
} = NexT.CONFIG.artalk.cfg;
NexT.utils.loadComments(element)
.then(() => NexT.utils.getScript(artalk_js, {
@@ -22,11 +22,11 @@ document.addEventListener('DOMContentLoaded', () => {
new Artalk({
el : element,
pageKey : NexT.CONFIG.page.permalink,
pageTitle : NexT.CONFIG.page.title,
pageKey : NexT.CONFIG.permalink,
pageTitle : NexT.CONFIG.title,
server : server,
site : site,
locale : NexT.CONFIG.page.lang,
locale : NexT.CONFIG.lang,
placeholder : placeholder,
darkMode : 'auto'
});

View File

@@ -2,7 +2,7 @@ document.addEventListener('DOMContentLoaded', () => {
const element = '.giscus-container';
if (!NexT.CONFIG.page.comments
|| !NexT.CONFIG.page.giscus
|| !NexT.CONFIG.giscus
|| !NexT.utils.checkDOMExist(element)) return;
const {
@@ -14,11 +14,11 @@ document.addEventListener('DOMContentLoaded', () => {
reactions,
repo,
repoid,
theme } = NexT.CONFIG.page.giscus.cfg;
theme } = NexT.CONFIG.giscus.cfg;
NexT.utils.loadComments(element)
.then(() => NexT.utils.getScript(NexT.CONFIG.page.giscus.js, {
.then(() => NexT.utils.getScript(NexT.CONFIG.giscus.js, {
attributes: {
'async' : true,
'crossorigin' : 'anonymous',
@@ -31,7 +31,7 @@ document.addEventListener('DOMContentLoaded', () => {
'data-emit-metadata' : emit ? 1:0,
'data-input-position' : inputposition,
'data-theme' : theme,
'data-lang' : NexT.CONFIG.page.lang,
'data-lang' : NexT.CONFIG.lang,
'data-loading' : 'lazy'
},
parentNode: document.querySelector(element)

View File

@@ -2,11 +2,11 @@ document.addEventListener('DOMContentLoaded', () => {
const element = '#lv-container';
if (!NexT.CONFIG.page.comments
|| !NexT.CONFIG.page.livere
|| !NexT.CONFIG.livere
|| !NexT.utils.checkDOMExist(element)) return;
NexT.utils.loadComments(element).then(() => {
NexT.utils.getScript(NexT.CONFIG.page.livere.js, {
NexT.utils.getScript(NexT.CONFIG.livere.js, {
attributes: {
async: true
},

View File

@@ -2,17 +2,17 @@ document.addEventListener('DOMContentLoaded', () => {
const element = '.utterances-container';
if (!NexT.CONFIG.page.comments
|| !NexT.CONFIG.page.utterances
|| !NexT.CONFIG.utterances
|| !NexT.utils.checkDOMExist(element)) return;
const {
repo,
issueterm,
label,
theme } = NexT.CONFIG.page.utterances.cfg;
theme } = NexT.CONFIG.utterances.cfg;
NexT.utils.loadComments(element)
.then(() => NexT.utils.getScript(NexT.CONFIG.page.utterances.js, {
.then(() => NexT.utils.getScript(NexT.CONFIG.utterances.js, {
attributes: {
'async' : true,
'crossorigin' : 'anonymous',

View File

@@ -2,7 +2,7 @@ document.addEventListener('DOMContentLoaded', () => {
const element = '.waline-container';
if (!NexT.CONFIG.page.comments
|| !NexT.CONFIG.page.waline
|| !NexT.CONFIG.waline
|| !NexT.utils.checkDOMExist(element)) return;
const {
@@ -13,13 +13,13 @@ document.addEventListener('DOMContentLoaded', () => {
requiredmeta,
serverurl,
wordlimit
} = NexT.CONFIG.page.waline.cfg;
} = NexT.CONFIG.waline.cfg;
const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.css);
const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.waline.css);
NexT.utils.getStyle(waline_css, null);
const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.js);
const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.waline.js);
const locale = {
placeholder: placeholder
@@ -39,7 +39,7 @@ document.addEventListener('DOMContentLoaded', () => {
wordLimit : wordlimit,
requiredMeta : requiredmeta,
serverURL : serverurl,
lang : NexT.CONFIG.page.lang,
lang : NexT.CONFIG.lang,
dark : "auto"
});

View File

@@ -1,9 +1,9 @@
document.addEventListener('DOMContentLoaded', () => {
const element = '.addthis_inline_share_toolbox';
if (!NexT.CONFIG.page.addthis || !NexT.utils.checkDOMExist(element)) return;
if (!NexT.CONFIG.addthis || !NexT.utils.checkDOMExist(element)) return;
const addthis_js = NexT.CONFIG.page.addthis.js + '?pubid=' + NexT.CONFIG.page.addthis.cfg.pubid;
const addthis_js = NexT.CONFIG.addthis.js + '?pubid=' + NexT.CONFIG.addthis.cfg.pubid;
NexT.utils.loadComments(element).then(() => {
NexT.utils.getScript(addthis_js, {

View File

@@ -63,6 +63,8 @@ NexT.utils = {
* One-click copy code support.
*/
registerCopyCode: function() {
if (!NexT.CONFIG.copybtn) return;
let figure = document.querySelectorAll('.highlight pre');
if (figure.length === 0 || !NexT.CONFIG.copybtn) return;
figure.forEach(element => {
@@ -277,7 +279,7 @@ NexT.utils = {
});
},
initCommontesDispaly: function(){
initCommontesDispaly: function(){
const comms = document.querySelectorAll('.comment-wrap > div');
if (comms.length<=1) return;
comms.forEach(function(item){
@@ -302,6 +304,10 @@ NexT.utils = {
});
},
hideCommontes:function() {
document.querySelector('.post-comments').style.display = 'none';
},
hiddeLodingCmp: function(selector) {
const loadding = document.querySelector(selector).previousElementSibling;
loadding.style.display = 'none';