⚡ Refactoring the comments component js scripts.
This commit is contained in:
24
assets/js/third-party/comments/artalk.js
vendored
24
assets/js/third-party/comments/artalk.js
vendored
@@ -1,13 +1,8 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
NexT.comments.giscus = function() {
|
||||
const element = '.artalk-container';
|
||||
if (!NexT.CONFIG.page.comments
|
||||
|| !NexT.CONFIG.artalk
|
||||
if (!NexT.CONFIG.artalk
|
||||
|| !NexT.utils.checkDOMExist(element)) return;
|
||||
|
||||
const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.artalk.css);
|
||||
NexT.utils.getStyle(artalk_css, null);
|
||||
|
||||
const artalk_js = NexT.utils.getCDNResource(NexT.CONFIG.artalk.js);
|
||||
const {
|
||||
site,
|
||||
@@ -15,10 +10,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
server,
|
||||
} = NexT.CONFIG.artalk.cfg;
|
||||
|
||||
NexT.utils.loadComments(element)
|
||||
.then(() => NexT.utils.getScript(artalk_js, {
|
||||
}))
|
||||
.then(() => {
|
||||
NexT.utils.lazyLoadComponent(element, function() {
|
||||
NexT.utils.getScript(artalk_js, function(){
|
||||
const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.artalk.css);
|
||||
NexT.utils.getStyle(artalk_css);
|
||||
|
||||
new Artalk({
|
||||
el : element,
|
||||
@@ -29,8 +24,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
locale : NexT.CONFIG.lang,
|
||||
placeholder : placeholder,
|
||||
darkMode : 'auto'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
NexT.utils.hiddeLodingCmp(element);
|
||||
NexT.utils.hiddeLodingCmp(element);
|
||||
});
|
||||
});
|
||||
}
|
||||
14
assets/js/third-party/comments/giscus.js
vendored
14
assets/js/third-party/comments/giscus.js
vendored
@@ -1,5 +1,4 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
NexT.comments.giscus = function() {
|
||||
const element = '.giscus-container';
|
||||
if (!NexT.CONFIG.page.comments
|
||||
|| !NexT.CONFIG.giscus
|
||||
@@ -17,8 +16,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
theme } = NexT.CONFIG.giscus.cfg;
|
||||
|
||||
|
||||
NexT.utils.loadComments(element)
|
||||
.then(() => NexT.utils.getScript(NexT.CONFIG.giscus.js, {
|
||||
NexT.utils.lazyLoadComponent(element, function() {
|
||||
NexT.utils.getScript(NexT.CONFIG.giscus.js, {
|
||||
attributes: {
|
||||
'async' : true,
|
||||
'crossorigin' : 'anonymous',
|
||||
@@ -35,7 +34,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
'data-loading' : 'lazy'
|
||||
},
|
||||
parentNode: document.querySelector(element)
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
NexT.utils.hiddeLodingCmp(element);
|
||||
});
|
||||
});
|
||||
}
|
||||
10
assets/js/third-party/comments/livere.js
vendored
10
assets/js/third-party/comments/livere.js
vendored
@@ -1,11 +1,9 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
NexT.comments.giscus = function() {
|
||||
const element = '#lv-container';
|
||||
if (!NexT.CONFIG.page.comments
|
||||
|| !NexT.CONFIG.livere
|
||||
if (!NexT.CONFIG.livere
|
||||
|| !NexT.utils.checkDOMExist(element)) return;
|
||||
|
||||
NexT.utils.loadComments(element).then(() => {
|
||||
NexT.utils.lazyLoadComponent(element, function() {
|
||||
NexT.utils.getScript(NexT.CONFIG.livere.js, {
|
||||
attributes: {
|
||||
async: true
|
||||
@@ -15,4 +13,4 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
NexT.utils.hiddeLodingCmp(element);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
16
assets/js/third-party/comments/utterances.js
vendored
16
assets/js/third-party/comments/utterances.js
vendored
@@ -1,8 +1,6 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
NexT.comments.giscus = function() {
|
||||
const element = '.utterances-container';
|
||||
if (!NexT.CONFIG.page.comments
|
||||
|| !NexT.CONFIG.utterances
|
||||
if (!NexT.CONFIG.utterances
|
||||
|| !NexT.utils.checkDOMExist(element)) return;
|
||||
|
||||
const {
|
||||
@@ -11,17 +9,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
label,
|
||||
theme } = NexT.CONFIG.utterances.cfg;
|
||||
|
||||
NexT.utils.loadComments(element)
|
||||
.then(() => NexT.utils.getScript(NexT.CONFIG.utterances.js, {
|
||||
NexT.utils.lazyLoadComponent(element, function() {
|
||||
NexT.utils.getScript(NexT.CONFIG.utterances.js, {
|
||||
attributes: {
|
||||
'async' : true,
|
||||
'crossorigin' : 'anonymous',
|
||||
'repo' : repo,
|
||||
'issue-term' : issueterm,
|
||||
'label' : label,
|
||||
'theme' : theme
|
||||
},
|
||||
parentNode: document.querySelector(element)
|
||||
}));
|
||||
});
|
||||
|
||||
NexT.utils.hiddeLodingCmp(element);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
21
assets/js/third-party/comments/waline.js
vendored
21
assets/js/third-party/comments/waline.js
vendored
@@ -1,8 +1,6 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
NexT.comments.waline = function() {
|
||||
const element = '.waline-container';
|
||||
if (!NexT.CONFIG.page.comments
|
||||
|| !NexT.CONFIG.waline
|
||||
if (!NexT.CONFIG.waline
|
||||
|| !NexT.utils.checkDOMExist(element)) return;
|
||||
|
||||
const {
|
||||
@@ -19,10 +17,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
reactiontitle
|
||||
} = NexT.CONFIG.waline.cfg;
|
||||
|
||||
|
||||
const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.waline.css);
|
||||
NexT.utils.getStyle(waline_css, null);
|
||||
|
||||
const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.waline.js);
|
||||
|
||||
let locale = {
|
||||
@@ -35,10 +29,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
locale['reaction'+index] = value;
|
||||
});
|
||||
|
||||
NexT.utils.loadComments(element)
|
||||
.then(() => NexT.utils.getScript(waline_js, {
|
||||
}))
|
||||
.then(() => {
|
||||
NexT.utils.lazyLoadComponent(element, function () {
|
||||
NexT.utils.getScript(waline_js, function(){
|
||||
const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.waline.css);
|
||||
NexT.utils.getStyle(waline_css);
|
||||
|
||||
Waline.init({
|
||||
locale,
|
||||
@@ -55,5 +49,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
|
||||
NexT.utils.hiddeLodingCmp(element);
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user