⚡ 🔥 Refactor struct & code for loading 3rd scripts.
This commit is contained in:
@@ -31,6 +31,15 @@ NexT.plugins.share.register = function() {
|
||||
};
|
||||
}
|
||||
|
||||
// Defined other plugin & add register event
|
||||
NexT.plugins.others = {}
|
||||
NexT.plugins.others.register = function() {
|
||||
for(var o in NexT.plugins.others) {
|
||||
if (o === 'register') continue;
|
||||
eval('NexT.plugins.others.'+o)();
|
||||
};
|
||||
}
|
||||
|
||||
// Add event to register all third party plugins
|
||||
NexT.plugins.register = function() {
|
||||
for(var p in NexT.plugins) {
|
||||
|
||||
16
assets/js/third-party/others/lawidget.js
vendored
Normal file
16
assets/js/third-party/others/lawidget.js
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/* 51La sidebar data widget */
|
||||
NexT.plugins.others.lawidget = function() {
|
||||
const element = '#siteinfo-card-widget';
|
||||
const lawt_js = NexT.CONFIG.lawidget.js.replace('laId', NexT.CONFIG.lawidget.id);
|
||||
|
||||
NexT.utils.lazyLoadComponent(element, function () {
|
||||
NexT.utils.getScript(lawt_js,{
|
||||
attributes: {
|
||||
id: 'LA-DATA-WIDGET',
|
||||
crossorigin: 'anonymous',
|
||||
charset: 'UTF-8',
|
||||
defer: true
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
38
assets/js/third-party/others/math.js
vendored
Normal file
38
assets/js/third-party/others/math.js
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/* Math render plugin */
|
||||
NexT.plugins.others.math = function() {
|
||||
const render = NexT.CONFIG.page.math.render;
|
||||
|
||||
if (render === 'mathjax') {
|
||||
const render_js = NexT.utils.getCDNResource(NexT.CONFIG.page.math.js);
|
||||
NexT.utils.getScript(render_js, function(){
|
||||
window.MathJax = {
|
||||
tex: {
|
||||
inlineMath: [["$", "$"]],
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (render === 'katex') {
|
||||
const render_css = NexT.utils.getCDNResource(NexT.CONFIG.page.math.css);
|
||||
NexT.utils.getStyle(render_css);
|
||||
const render_js_list = NexT.CONFIG.page.math.js;
|
||||
render_js_list.forEach(js => {
|
||||
const js_loader = NexT.utils.getScript(NexT.utils.getCDNResource(js));
|
||||
if(js.name === 'auto-render') {
|
||||
js_loader.then(function(){
|
||||
renderMathInElement(document.body, {
|
||||
delimiters: [
|
||||
{left: '$$', right: '$$', display: true},
|
||||
{left: '$', right: '$', display: false},
|
||||
{left: '\\(', right: '\\)', display: false},
|
||||
{left: '\\[', right: '\\]', display: true}
|
||||
],
|
||||
|
||||
throwOnError : false
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
15
assets/js/third-party/others/mermaid.js
vendored
Normal file
15
assets/js/third-party/others/mermaid.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
/* Mermaid plugin */
|
||||
NexT.plugins.others.mermaid = function() {
|
||||
const mermaid_js = NexT.utils.getCDNResource(NexT.CONFIG.page.mermaid.js);
|
||||
|
||||
NexT.utils.getScript(mermaid_js, function(){
|
||||
mermaid.initialize({
|
||||
sequence: {
|
||||
showSequenceNumbers: true,
|
||||
actorMargin: 50,
|
||||
diagramMarginX:10,
|
||||
diagramMarginY:10
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
9
assets/js/third-party/others/translate.js
vendored
Normal file
9
assets/js/third-party/others/translate.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
/* Google translate plugin */
|
||||
NexT.plugins.others.translate = function() {
|
||||
const element = '#gtranslate';
|
||||
if (!NexT.utils.checkDOMExist(element)) return;
|
||||
NexT.utils.lazyLoadComponent(element, function() {
|
||||
window.translateelement_styles='/css/google-translate.min.css';
|
||||
NexT.utils.getScript('/js/third-party/google-translate.min.js');
|
||||
});
|
||||
}
|
||||
@@ -179,9 +179,10 @@ NexT.utils = {
|
||||
|
||||
getCDNResource: function (res) {
|
||||
let { plugins, router } = NexT.CONFIG.vendor;
|
||||
let { name, version, file, alias } = res;
|
||||
let { name, version, file, alias, alias_name } = res;
|
||||
|
||||
let npm_name = name;
|
||||
if (alias_name) npm_name = alias_name;
|
||||
let res_src = '';
|
||||
switch (plugins) {
|
||||
case 'cdnjs':
|
||||
@@ -522,7 +523,6 @@ NexT.utils = {
|
||||
link.setAttribute('href', src);
|
||||
|
||||
const head = (parent || document.head);
|
||||
console.log(head)
|
||||
if (position === 'before') {
|
||||
head.prepend(link);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user