diff --git a/dev/Common/Html.js b/dev/Common/Html.js index 8e9b36018..19c1a1864 100644 --- a/dev/Common/Html.js +++ b/dev/Common/Html.js @@ -66,7 +66,14 @@ class HtmlEditor { * @returns {boolean} */ isHtml() { - return this.editor ? 'plain' !== this.editor.mode : false; + return this.editor ? !this.isPlain() : false; + } + + /** + * @returns {boolean} + */ + isPlain() { + return this.editor ? 'plain' === this.editor.mode : false; } /** @@ -100,7 +107,7 @@ class HtmlEditor { let result = ''; if (this.editor) { try { - if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain) { + if (this.isPlain() && this.editor.plugins.plain && this.editor.__plain) { result = this.editor.__plain.getRawData(); } else { result = wrapIsHtml @@ -123,59 +130,45 @@ class HtmlEditor { return (this.isHtml() ? ':HTML:' : '') + this.getData(wrapIsHtml); } - modeToggle(plain) { - if (this.editor) { - try { - if (plain) { - if ('plain' === this.editor.mode) { - this.editor.setMode('wysiwyg'); - } - } else if ('wysiwyg' === this.editor.mode) { - this.editor.setMode('plain'); - } - } catch (e) {} // eslint-disable-line no-empty - } + modeWysiwyg() { + try { + this.editor && this.editor.setMode('wysiwyg'); + } catch (e) { console.error(e); } + } + modePlain() { + try { + this.editor && this.editor.setMode('plain'); + } catch (e) { console.error(e); } } - setHtmlOrPlain(text, focus) { + setHtmlOrPlain(text) { if (':HTML:' === text.substr(0, 6)) { - this.setHtml(text.substr(6), focus); + this.setHtml(text.substr(6)); } else { - this.setPlain(text, focus); + this.setPlain(text); } } - setHtml(html, focus) { + setData(mode, data) { if (this.editor && this.__inited) { this.clearCachedSignature(); - - this.modeToggle(true); - - html = html.replace(/
]*><\/p>/gi, ''); - try { - this.editor.setData(html); - } catch (e) {} // eslint-disable-line no-empty - - focus && this.focus(); + this.editor.setMode(mode); + if (this.isPlain() && this.editor.plugins.plain && this.editor.__plain) { + this.editor.__plain.setRawData(data); + } else { + this.editor.setData(data); + } + } catch (e) { console.error(e); } } } - setPlain(plain, focus) { - if (this.editor && this.__inited) { - this.clearCachedSignature(); + setHtml(html) { + this.setData('wysiwyg', html/*.replace(/
]*><\/p>/gi, '')*/);
+ }
- this.modeToggle(false);
- if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain) {
- this.editor.__plain.setRawData(plain);
- } else {
- try {
- this.editor.setData(plain);
- } catch (e) {} // eslint-disable-line no-empty
- }
-
- focus && this.focus();
- }
+ setPlain(txt) {
+ this.setData('plain', txt);
}
init() {
@@ -208,7 +201,7 @@ class HtmlEditor {
this.editor.on('focus', () => this.blurTimer && clearTimeout(this.blurTimer));
this.editor.on('mode', () => {
this.blurTrigger();
- this.onModeChange && this.onModeChange('plain' !== this.editor.mode);
+ this.onModeChange && this.onModeChange(!this.isPlain());
});
}
}
@@ -234,8 +227,8 @@ class HtmlEditor {
} catch (e) {} // eslint-disable-line no-empty
}
- clear(focus) {
- this.setHtml('', focus);
+ clear() {
+ this.setHtml('');
}
}
diff --git a/dev/Common/UtilsUser.js b/dev/Common/UtilsUser.js
index 8a0d29b74..925bed9d0 100644
--- a/dev/Common/UtilsUser.js
+++ b/dev/Common/UtilsUser.js
@@ -85,7 +85,7 @@ export function htmlToPlain(html) {
args && 1 < args.length
? args[1]
.toString()
- .replace(/[\n]/gm, '
')
+ .replace(/[\n]/gm, '
')
.replace(/[\r]/gm, '')
: '',
fixAttibuteValue = (...args) => (args && 1 < args.length ? '' + args[1] + encodeHtml(args[2]) : ''),
@@ -204,7 +204,7 @@ export function plainToHtml(plain) {
.replace(/')
.replace(/[\s]*~~~\/blockquote~~~/g, '')
- .replace(/\n/g, '
');
+ .replace(/\n/g, '
');
}
rl.Utils = {
diff --git a/dev/External/CKEditor.js b/dev/External/CKEditor.js
index 580309831..a0c4b791b 100644
--- a/dev/External/CKEditor.js
+++ b/dev/External/CKEditor.js
@@ -85,7 +85,7 @@ export function createCKEditor(element)
reader.onloadend = () => {
if (reader.result && 'wysiwyg' === editor.mode) {
try {
- editor.setData(editor.getData().replace(imageId, ``));
+ editor.setData(editor.getData().replace(imageId, `
`));
} catch (e) {} // eslint-disable-line no-empty
}
};
diff --git a/dev/External/SquireUI.js b/dev/External/SquireUI.js
index f024121e1..4466cac14 100644
--- a/dev/External/SquireUI.js
+++ b/dev/External/SquireUI.js
@@ -491,20 +491,20 @@ class SquireUI
}
setMode(mode) {
- let cl = this.container.classList;
- cl.remove('squire-mode-'+this.mode);
- if ('plain' == mode) {
- let html = this.squire.getHTML();
- this.plain.value = rl.Utils.htmlToPlain(html, true).trim();
- } else {
- let plain = this.plain.value;
- this.setData(rl.Utils.plainToHtml(plain, true));
- mode = 'wysiwyg';
+ if (this.mode != mode) {
+ let cl = this.container.classList;
+ cl.remove('squire-mode-'+this.mode);
+ if ('plain' == mode) {
+ this.plain.value = rl.Utils.htmlToPlain(this.squire.getHTML(), true).trim();
+ } else {
+ this.setData(rl.Utils.plainToHtml(this.plain.value, true));
+ mode = 'wysiwyg';
+ }
+ this.mode = mode; // 'wysiwyg' or 'plain'
+ cl.add('squire-mode-'+mode);
+ this.onModeChange && this.onModeChange();
+ setTimeout(()=>this.focus(),1);
}
- this.mode = mode; // 'wysiwyg' or 'plain'
- cl.add('squire-mode-'+mode);
- this.onModeChange && this.onModeChange();
- setTimeout(()=>this.focus(),1);
}
// CKeditor gimmicks used by HtmlEditor
@@ -551,6 +551,7 @@ class SquireUI
}
setData(html) {
+// this.plain.value = html;
this.squire.setHTML(trimLines(html));
}
diff --git a/dev/Html/PreviewMessage.html b/dev/Html/PreviewMessage.html
index dc982e2d9..7632cf6fe 100644
--- a/dev/Html/PreviewMessage.html
+++ b/dev/Html/PreviewMessage.html
@@ -1,7 +1,7 @@