adasd
This commit is contained in:
@@ -157,6 +157,30 @@
|
||||
}
|
||||
};
|
||||
|
||||
const insertPlaceholderIntoSelection = (rteInstance, html) => {
|
||||
const doc = rteInstance && rteInstance.doc
|
||||
? rteInstance.doc
|
||||
: (rteInstance && rteInstance.el && rteInstance.el.ownerDocument) || document;
|
||||
if (!doc) return false;
|
||||
const sel = doc.getSelection && doc.getSelection();
|
||||
if (!sel || !sel.rangeCount) return false;
|
||||
const range = sel.getRangeAt(0);
|
||||
if (!range) return false;
|
||||
|
||||
range.deleteContents();
|
||||
const temp = doc.createElement('div');
|
||||
temp.innerHTML = html;
|
||||
const fragment = doc.createDocumentFragment();
|
||||
while (temp.firstChild) {
|
||||
fragment.appendChild(temp.firstChild);
|
||||
}
|
||||
range.insertNode(fragment);
|
||||
range.collapse(false);
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
return true;
|
||||
};
|
||||
|
||||
const openPlaceholderModal = (editor, component, opts = {}) => {
|
||||
if (!editor) return;
|
||||
const modal = editor.Modal;
|
||||
@@ -431,10 +455,15 @@
|
||||
openPlaceholderModal(editor, null, {
|
||||
onSubmit: (payload) => {
|
||||
const html = buildPlaceholderHTML(payload);
|
||||
if (rteInstance && typeof rteInstance.insertHTML === 'function') {
|
||||
let inserted = false;
|
||||
if (insertPlaceholderIntoSelection(rteInstance, html)) {
|
||||
inserted = true;
|
||||
} else if (rteInstance && typeof rteInstance.insertHTML === 'function') {
|
||||
rteInstance.insertHTML(html);
|
||||
inserted = true;
|
||||
} else if (typeof document !== 'undefined' && document.execCommand) {
|
||||
document.execCommand('insertHTML', false, html);
|
||||
inserted = true;
|
||||
} else {
|
||||
log('PLACEHOLDER ERROR', 'Placeholder konnte nicht eingefügt werden (kein RTE).', 'red', 'error');
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user