dsfds
This commit is contained in:
@@ -308,6 +308,87 @@
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('CORE WARN', `textTags Konfiguration fehlgeschlagen: ${e.message}`, 'orange', 'warn');
|
log('CORE WARN', `textTags Konfiguration fehlgeschlagen: ${e.message}`, 'orange', 'warn');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const wrapPlainTextNodes = (el) => {
|
||||||
|
if (!el || !el.ownerDocument) return false;
|
||||||
|
const doc = el.ownerDocument;
|
||||||
|
const walker = doc.createTreeWalker(el, NodeFilter.SHOW_TEXT, null);
|
||||||
|
const toWrap = [];
|
||||||
|
while (walker.nextNode()) {
|
||||||
|
const node = walker.currentNode;
|
||||||
|
if (!node || !node.parentNode) continue;
|
||||||
|
if (node.textContent === '') continue;
|
||||||
|
if (node.parentNode.nodeName && node.parentNode.nodeName.toLowerCase() === 'span') continue;
|
||||||
|
if (node.textContent.trim() === '') continue;
|
||||||
|
toWrap.push(node);
|
||||||
|
}
|
||||||
|
if (!toWrap.length) return false;
|
||||||
|
toWrap.forEach((node) => {
|
||||||
|
const span = doc.createElement('span');
|
||||||
|
span.setAttribute('data-gjs-text', '1');
|
||||||
|
span.textContent = node.textContent || '';
|
||||||
|
node.parentNode.replaceChild(span, node);
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const hasPlainTextNodes = (el) => {
|
||||||
|
if (!el || !el.ownerDocument) return false;
|
||||||
|
const doc = el.ownerDocument;
|
||||||
|
const walker = doc.createTreeWalker(el, NodeFilter.SHOW_TEXT, null);
|
||||||
|
while (walker.nextNode()) {
|
||||||
|
const node = walker.currentNode;
|
||||||
|
if (!node || !node.parentNode) continue;
|
||||||
|
if (node.textContent === '') continue;
|
||||||
|
if (node.parentNode.nodeName && node.parentNode.nodeName.toLowerCase() === 'span') continue;
|
||||||
|
if (node.textContent.trim() === '') continue;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const isTextLike = (cmp) => {
|
||||||
|
const type = cmp && cmp.get ? cmp.get('type') : null;
|
||||||
|
return type === 'text' || type === 'link' || type === 'button';
|
||||||
|
};
|
||||||
|
|
||||||
|
const fixPlainTextContent = (cmp) => {
|
||||||
|
if (!cmp || !cmp.view || !cmp.view.el) return;
|
||||||
|
if (!isTextLike(cmp)) return;
|
||||||
|
const el = cmp.view.el;
|
||||||
|
if (!hasPlainTextNodes(el)) return;
|
||||||
|
if (!wrapPlainTextNodes(el)) return;
|
||||||
|
try {
|
||||||
|
if (typeof cmp.components === 'function') {
|
||||||
|
cmp.components(el.innerHTML);
|
||||||
|
} else if (typeof cmp.set === 'function') {
|
||||||
|
cmp.set('content', el.innerHTML);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
log('CORE WARN', `Plain-Text Fix fehlgeschlagen: ${err.message}`, 'orange', 'warn');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ed.on('rte:disable', (cmp) => {
|
||||||
|
if (ed.__bridgeFixPlainText) return;
|
||||||
|
ed.__bridgeFixPlainText = true;
|
||||||
|
try {
|
||||||
|
fixPlainTextContent(cmp);
|
||||||
|
} finally {
|
||||||
|
ed.__bridgeFixPlainText = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ed.on('component:update', (cmp) => {
|
||||||
|
if (ed.__bridgeFixPlainText) return;
|
||||||
|
if (!isTextLike(cmp)) return;
|
||||||
|
ed.__bridgeFixPlainText = true;
|
||||||
|
try {
|
||||||
|
fixPlainTextContent(cmp);
|
||||||
|
} finally {
|
||||||
|
ed.__bridgeFixPlainText = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
window.__gjs = ed;
|
window.__gjs = ed;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user