💥 Tweak for moments theme

This commit is contained in:
zhbaor 2022-12-31 22:20:24 +08:00
parent 38b0fd865d
commit c49c8a8a91
8 changed files with 45 additions and 172 deletions

View file

@ -685,7 +685,7 @@
const REG_BD_HALF_START = `${REG_BD_HALF_OPEN}${REG_BD_HALF_CLOSE}`;
class Heti {
constructor (rootSelector) {
constructor (rootDocument, rootSelector) {
let supportLookBehind = true;
try {
@ -695,6 +695,7 @@
supportLookBehind = false;
}
this.rootDocument = rootDocument;
this.rootSelector = rootSelector || '.heti';
this.REG_FULL = new RegExp(supportLookBehind ? REG_CJK_FULL : REG_CJK_FULL_WITHOUT_LOOKBEHIND, 'g');
this.REG_START = new RegExp(REG_CJK_START, 'g');
@ -722,8 +723,8 @@
forceContext: this.funcForceContext,
filterElements: this.funcFilterElements,
};
const getWrapper = function (elementName, classList, text) {
const $$r = document.createElement(elementName);
const getWrapper = (elementName, classList, text) => {
const $$r = this.rootDocument.createElement(elementName);
$$r.className = classList;
$$r.textContent = text.trim();
return $$r
@ -768,14 +769,18 @@
autoSpacing () {
const callback = () => {
const $$rootList = document.querySelectorAll(this.rootSelector);
const $$rootList = this.rootDocument.querySelectorAll(this.rootSelector);
for (let $$root of $$rootList) {
this.spacingElement($$root);
}
};
if (document.readyState === 'complete') setTimeout(callback);
else document.addEventListener('DOMContentLoaded', callback);
if (this.rootDocument == document) {
if (this.rootDocument.readyState === 'complete') setTimeout(callback);
else this.rootDocument.addEventListener('DOMContentLoaded', callback);
} else {
callback();
}
}
}