Skip to content

Commit

Permalink
Finish the waline3 component develop.
Browse files Browse the repository at this point in the history
  • Loading branch information
elkan1788 committed Aug 3, 2024
2 parents 1076ba9 + 27ca39f commit 77da27a
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 72 deletions.
4 changes: 0 additions & 4 deletions assets/js/third-party/comments/waline.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ NexT.plugins.comments.waline = function() {
|| !NexT.utils.checkDOMExist(element)) return;

const {
comment,
emoji,
imguploader,
pageview,
placeholder,
sofa,
requiredmeta,
Expand Down Expand Up @@ -39,8 +37,6 @@ NexT.plugins.comments.waline = function() {
Waline.init({
locale,
el : element,
pageview : pageview,
comment : comment,
emoji : emoji,
imageUploader : imguploader,
wordLimit : wordlimit,
Expand Down
59 changes: 59 additions & 0 deletions assets/js/third-party/comments/waline3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* Waline3 comment plugin */
NexT.plugins.comments.waline3 = function () {
const element = '.waline3-container';
if (!NexT.CONFIG.waline3
|| !NexT.utils.checkDOMExist(element)) return;

const {
emoji,
search,
imguploader,
placeholder,
sofa,
requiredmeta,
serverurl,
wordlimit,
reaction,
reactiontext,
reactiontitle
} = NexT.CONFIG.waline3.cfg;

const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.waline3.js);

NexT.utils.lazyLoadComponent(element, () => {

const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.waline3.css);
NexT.utils.getStyle(waline_css, 'before');

let waline_script = `
let locale = {
placeholder : '${placeholder}',
sofa : '${sofa}',
reactionTitle : '${reactiontitle}'
};
let recatt = ${JSON.stringify(reactiontext)}
recatt.forEach(function(value, index){
locale['reaction'+index] = value;
});
import('${waline_js}').then((Waline) => {
Waline.init({
locale,
el : '${element}',
emoji : ${emoji},
search : ${search},
imageUploader : ${imguploader},
wordLimit : ${wordlimit},
requiredMeta : ${JSON.stringify(requiredmeta)},
reaction : ${reaction},
serverURL : '${serverurl}',
});
NexT.utils.hiddeLodingCmp('${element}');
});
`;

NexT.utils.getScript(null, { module: true, textContent: waline_script });
});
}
67 changes: 51 additions & 16 deletions assets/js/third-party/others/counter.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,66 @@
/* Page's view & comment counter plugin */
NexT.plugins.others.counter = function() {
let pageview_js = undefined;
let comment_js = undefined;
NexT.plugins.others.counter = function () {
let pageview_js = undefined;
let comment_js = undefined;

const post_meta = NexT.CONFIG.postmeta;
const post_meta = NexT.CONFIG.postmeta;

const views = post_meta.views;
if(views != undefined && views.enable) {
if (views.plugin == 'waline') {
pageview_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.js[0]);
NexT.utils.getScript(pageview_js, function(){
const views = post_meta.views;
if (views != undefined && views.enable) {
let pageview_el = '#pageview-count';

switch (views.plugin) {
case 'waline':
pageview_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.pagecnt);
NexT.utils.getScript(pageview_js, function () {
Waline.pageviewCount({
selector : pageview_el,
serverURL: NexT.CONFIG.waline.cfg.serverurl
});
});
}
break;
case 'waline3':
pageview_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline3.pagecnt);

let pageview_script = `
import('${pageview_js}').then((Waline) => {
Waline.pageviewCount({
selector : '${pageview_el}',
serverURL: '${NexT.CONFIG.waline3.cfg.serverurl}'
})
});
`;
NexT.utils.getScript(null, { module: true, textContent: pageview_script });
break;
}

const comments = post_meta.comments;
if (comments != undefined && comments.enable) {
if (comments.plugin == 'waline') {
comment_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.js[1]);
NexT.utils.getScript(comment_js, function(){
}

const comments = post_meta.comments;
if (comments != undefined && comments.enable) {
let comments_el = '#comments-count';
switch (comments.plugin) {
case 'waline':
comment_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.commentcnt);
NexT.utils.getScript(comment_js, function () {
Waline.commentCount({
selector : comments_el,
serverURL: NexT.CONFIG.waline.cfg.serverurl
});
});
}
break;
case 'waline3':
comment_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline3.commentcnt);
let comment_script = `
import('${comment_js}').then((Waline) => {
Waline.commentCount({
selector : '${comments_el}',
serverURL: '${NexT.CONFIG.waline3.cfg.serverurl}'
})
});
`;
NexT.utils.getScript(null, { module: true, textContent: comment_script });
break;
}
}
}
76 changes: 42 additions & 34 deletions assets/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ HTMLElement.prototype.wrap = function (wrapper) {
};

NexT.utils = {
registerMenuClick: function() {
registerMenuClick: function () {
const pMenus = document.querySelectorAll('.main-menu > li > a.menus-parent');
pMenus.forEach(function(item) {
pMenus.forEach(function (item) {
const icon = item.querySelector('span > i');
var ul = item.nextElementSibling;
item.addEventListener('click', function(e) {
var ul = item.nextElementSibling;

item.addEventListener('click', function (e) {
e.preventDefault();

ul.classList.toggle('expand');
if (ul.classList.contains('expand')) {
icon.className = 'fa fa-angle-down';
Expand All @@ -30,17 +30,17 @@ NexT.utils = {
}
});
},
registerImageLoadEvent: function() {
registerImageLoadEvent: function () {
const images = document.querySelectorAll('.sidebar img, .post-block img, .vendors-list img');

const callback = (entries) => {
entries.forEach(item => {
if (item.intersectionRatio > 0) {
let ele = item.target;
let imgSrc = ele.getAttribute('data-src');
if (imgSrc) {
let img = new Image();
img.addEventListener('load', function() {
img.addEventListener('load', function () {
ele.src = imgSrc;
}, false);
ele.src = imgSrc;
Expand All @@ -50,23 +50,23 @@ NexT.utils = {
}
})
};

const observer = new IntersectionObserver(callback);
images.forEach(img => {
observer.observe(img);
});
},

registerImageViewer: function() {
registerImageViewer: function () {
const post_body = document.querySelector('.post-body');
if (post_body) {
new Viewer(post_body,{ navbar:2, toolbar:2 });
new Viewer(post_body, { navbar: 2, toolbar: 2 });
}
},

registerToolButtons: function () {
const buttons = document.querySelector('.tool-buttons');

const scrollbar_buttons = buttons.querySelectorAll('div:not(#toggle-theme)');
scrollbar_buttons.forEach(button => {
let targetId = button.id;
Expand All @@ -86,12 +86,12 @@ NexT.utils = {

slidScrollBarAnime: function (targetId, easing = 'linear', duration = 500) {
const targetObj = document.getElementById(targetId);

window.anime({
targets: document.scrollingElement,
duration: duration,
easing: easing,
scrollTop: targetId == '' || !targetObj ? 0 : targetObj.getBoundingClientRect().top + window.scrollY
scrollTop: targetId == '' || !targetObj ? 0 : targetObj.getBoundingClientRect().top + window.scrollY
});
},

Expand Down Expand Up @@ -147,8 +147,8 @@ NexT.utils = {
}
},

fmtLaWidget: function(){
setTimeout(function(){
fmtLaWidget: function () {
setTimeout(function () {
const laWidget = document.querySelectorAll('#la-siteinfo-widget span');
if (laWidget.length > 0) {
const valIds = [0, 2, 4, 6];
Expand All @@ -162,16 +162,16 @@ NexT.utils = {
},

fmtBusuanzi: function () {
setTimeout(function(){
const bszUV = document.getElementById('busuanzi_value_site_uv');
setTimeout(function () {
const bszUV = document.getElementById('busuanzi_value_site_uv');
if (bszUV) {
bszUV.innerText = NexT.utils.numberFormat(bszUV.innerText);
}
const bszPV = document.getElementById('busuanzi_value_site_pv');
if (bszPV) {
bszPV.innerText = NexT.utils.numberFormat(bszPV.innerText);
}
}, 800);
}, 800);
},

numberFormat: function (number) {
Expand Down Expand Up @@ -244,14 +244,14 @@ NexT.utils = {

let router = NexT.CONFIG.vendor.router;
let { name, version, file, alias, alias_name } = res;

let res_src = '';

switch (router.type) {
case "modern":
if (alias_name) name = alias_name;
let alias_file = file.replace(/^(dist|lib|source|\/js|)\/(browser\/|)/, '');
if (alias_file.indexOf('min') == -1) {
if (alias_file.indexOf('min') == -1) {
alias_file = alias_file.replace(/\.js$/, '.min.js');
}
res_src = `${router.url}/${name}/${version}/${alias_file}`;
Expand Down Expand Up @@ -512,7 +512,7 @@ NexT.utils = {
hideComments: function () {
let postComments = document.querySelector('.post-comments');
if (postComments !== null) {
postComments.style.display = 'none';
postComments.style.display = 'none';
}
},

Expand Down Expand Up @@ -587,7 +587,7 @@ NexT.utils = {
});
},

getStyle: function (src, position='after', parent) {
getStyle: function (src, position = 'after', parent) {
const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
Expand All @@ -607,8 +607,11 @@ NexT.utils = {
condition: legacyCondition
}).then(options);
}

const {
condition = false,
module = false,
textContent = undefined,
attributes: {
id = '',
async = false,
Expand All @@ -628,6 +631,8 @@ NexT.utils = {

if (id) script.id = id;
if (crossOrigin) script.crossOrigin = crossOrigin;
if (module) script.type = 'module';
if (textContent != undefined) script.textContent = textContent;
script.async = async;
script.defer = defer;
Object.assign(script.dataset, dataset);
Expand All @@ -638,22 +643,25 @@ NexT.utils = {
script.onload = resolve;
script.onerror = reject;

if (typeof src === 'object') {
const { url, integrity } = src;
script.src = url;
if (integrity) {
script.integrity = integrity;
script.crossOrigin = 'anonymous';
if (src != null && src != undefined) {
if (typeof src === 'object') {
const { url, integrity } = src;
script.src = url;
if (integrity) {
script.integrity = integrity;
script.crossOrigin = 'anonymous';
}
} else {
script.src = src;
}
} else {
script.src = src;
}

(parentNode || document.head).appendChild(script);
}
});
},

lazyLoadComponent: function(selector, legacyCallback) {
lazyLoadComponent: function (selector, legacyCallback) {
if (legacyCallback) {
return this.lazyLoadComponent(selector).then(legacyCallback);
}
Expand Down
Loading

0 comments on commit 77da27a

Please sign in to comment.