Make #241 backward compatible (#259)

This commit is contained in:
2021-04-30 11:35:58 +08:00 committed by GitHub
parent eefc25de1a
commit e30159875a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}) });
}
}; };