mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-20 19:02:33 +00:00
parent
eefc25de1a
commit
e30159875a
@ -337,7 +337,13 @@ NexT.utils = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getScript: (url, {
|
getScript: function(url, options = {}, legacyCondition) {
|
||||||
|
if (typeof options === 'function') {
|
||||||
|
return this.getScript(url, {
|
||||||
|
condition: legacyCondition
|
||||||
|
}).then(options);
|
||||||
|
}
|
||||||
|
const {
|
||||||
condition = false,
|
condition = false,
|
||||||
attributes: {
|
attributes: {
|
||||||
id = '',
|
id = '',
|
||||||
@ -348,7 +354,8 @@ NexT.utils = {
|
|||||||
...otherAttributes
|
...otherAttributes
|
||||||
} = {},
|
} = {},
|
||||||
parentNode = null
|
parentNode = null
|
||||||
} = {}) => new Promise((resolve, reject) => {
|
} = options;
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
if (condition) {
|
if (condition) {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
@ -369,9 +376,14 @@ NexT.utils = {
|
|||||||
script.src = url;
|
script.src = url;
|
||||||
(parentNode || document.head).appendChild(script);
|
(parentNode || document.head).appendChild(script);
|
||||||
}
|
}
|
||||||
}),
|
});
|
||||||
|
},
|
||||||
|
|
||||||
loadComments: (selector) => new Promise((resolve) => {
|
loadComments: function(selector, legacyCallback) {
|
||||||
|
if (legacyCallback) {
|
||||||
|
return this.loadComments(selector).then(legacyCallback);
|
||||||
|
}
|
||||||
|
return new Promise((resolve) => {
|
||||||
const element = document.querySelector(selector);
|
const element = document.querySelector(selector);
|
||||||
if (!CONFIG.comments.lazyload || !element) {
|
if (!CONFIG.comments.lazyload || !element) {
|
||||||
resolve();
|
resolve();
|
||||||
@ -385,5 +397,6 @@ NexT.utils = {
|
|||||||
observer.disconnect();
|
observer.disconnect();
|
||||||
});
|
});
|
||||||
intersectionObserver.observe(element);
|
intersectionObserver.observe(element);
|
||||||
})
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user