ysdas
This commit is contained in:
@@ -44,24 +44,20 @@
|
|||||||
try {
|
try {
|
||||||
const wrapper = editor.getWrapper && editor.getWrapper();
|
const wrapper = editor.getWrapper && editor.getWrapper();
|
||||||
if (wrapper && wrapper.find) {
|
if (wrapper && wrapper.find) {
|
||||||
|
const doc = new DOMParser().parseFromString(html, 'text/html');
|
||||||
const candidates = wrapper.find('[data-gjs-type=\"text\"], [data-gjs-type=\"link\"], [data-gjs-type=\"button\"]');
|
const candidates = wrapper.find('[data-gjs-type=\"text\"], [data-gjs-type=\"link\"], [data-gjs-type=\"button\"]');
|
||||||
candidates.forEach((model) => {
|
candidates.forEach((model) => {
|
||||||
const content = model && model.get ? String(model.get('content') || '') : '';
|
const content = model && model.get ? String(model.get('content') || '') : '';
|
||||||
const id = model && (model.getId ? model.getId() : model.get && model.get('id'));
|
const id = model && (model.getId ? model.getId() : model.get && model.get('id'));
|
||||||
const viewEl = model && model.view && model.view.el ? model.view.el : null;
|
|
||||||
const tag = (model && model.get && (model.get('tagName') || model.get('tag')))
|
|
||||||
|| (viewEl && viewEl.tagName)
|
|
||||||
|| 'div';
|
|
||||||
if (!content || !id) return;
|
if (!content || !id) return;
|
||||||
const tagName = String(tag).toLowerCase();
|
const el = doc.getElementById(id);
|
||||||
if (tagName && tagName !== 'div') {
|
if (el) {
|
||||||
const rx = new RegExp(`<${tagName}([^>]*\\\\bid=[\"']${id}[\"'][^>]*)>([\\\\s\\\\S]*?)<\\\\/${tagName}>`, 'i');
|
el.innerHTML = content;
|
||||||
html = html.replace(rx, `<${tagName}$1>${content}</${tagName}>`);
|
|
||||||
} else {
|
|
||||||
const rxAny = new RegExp(`<([a-z0-9-]+)([^>]*\\\\bid=[\"']${id}[\"'][^>]*)>([\\\\s\\\\S]*?)<\\\\/\\1>`, 'i');
|
|
||||||
html = html.replace(rxAny, `<$1$2>${content}</$1>`);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (doc.body && doc.body.innerHTML !== undefined) {
|
||||||
|
html = `<body>${doc.body.innerHTML}</body>`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
return html;
|
return html;
|
||||||
@@ -174,23 +170,14 @@
|
|||||||
const isText = (component.is && component.is('text'))
|
const isText = (component.is && component.is('text'))
|
||||||
|| (component.get && component.get('type') === 'text');
|
|| (component.get && component.get('type') === 'text');
|
||||||
if (isText && component.components) {
|
if (isText && component.components) {
|
||||||
const comps = component.components();
|
try {
|
||||||
if (comps && typeof comps.reset === 'function') {
|
component.components(content);
|
||||||
comps.reset([], { silent: true });
|
} catch {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (component.set) component.set('content', content);
|
if (component.set) component.set('content', content);
|
||||||
} catch {}
|
} catch {}
|
||||||
if (component.view && component.view.el) {
|
|
||||||
component.view.el.innerHTML = content;
|
|
||||||
}
|
|
||||||
if (component.view && typeof component.view.render === 'function') {
|
if (component.view && typeof component.view.render === 'function') {
|
||||||
component.view.render();
|
component.view.render();
|
||||||
try {
|
|
||||||
if (component.view && component.view.el) {
|
|
||||||
component.view.el.innerHTML = content;
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
}
|
}
|
||||||
if (component.trigger) {
|
if (component.trigger) {
|
||||||
component.trigger('change:content');
|
component.trigger('change:content');
|
||||||
|
|||||||
Reference in New Issue
Block a user