From 6b1fd1239fdb7bc21a1dd59c6ced2a906c91053c Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Wed, 31 Aug 2016 00:31:51 +0300 Subject: [PATCH] Fix signature adding --- dev/Common/HtmlEditor.js | 17 +++++++++++++ dev/View/Popup/Compose.js | 8 +++--- vendors/ckeditor-plugins/signature/plugin.js | 26 ++++++++++++-------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/dev/Common/HtmlEditor.js b/dev/Common/HtmlEditor.js index 921f626b3..13c64207c 100644 --- a/dev/Common/HtmlEditor.js +++ b/dev/Common/HtmlEditor.js @@ -58,10 +58,23 @@ class HtmlEditor return this.editor ? 'wysiwyg' === this.editor.mode : false; } + /** + * @returns {void} + */ + clearCachedSignature() { + if (this.editor) + { + this.editor.execCommand('insertSignature', { + clearCache: true + }); + } + } + /** * @param {string} signature * @param {bool} html * @param {bool} insertBefore + * @returns {void} */ setSignature(signature, html, insertBefore) { if (this.editor) @@ -163,6 +176,8 @@ class HtmlEditor setHtml(html, focus) { if (this.editor && this.__inited) { + this.clearCachedSignature(); + this.modeToggle(true); html = html.replace(/]*><\/p>/ig, ''); @@ -193,6 +208,8 @@ class HtmlEditor setPlain(plain, focus) { if (this.editor && this.__inited) { + this.clearCachedSignature(); + this.modeToggle(false); if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain) { diff --git a/dev/View/Popup/Compose.js b/dev/View/Popup/Compose.js index d29995c82..952d844da 100644 --- a/dev/View/Popup/Compose.js +++ b/dev/View/Popup/Compose.js @@ -869,13 +869,13 @@ class ComposePopupView extends AbstractViewNext return signature; } - setSignatureFromIdentity(oIdentity) { - if (oIdentity) + setSignatureFromIdentity(identity) { + if (identity) { this.editor((editor) => { let isHtml = false, - signature = oIdentity.signature(); + signature = identity.signature(); if ('' !== signature) { @@ -886,7 +886,7 @@ class ComposePopupView extends AbstractViewNext } } - editor.setSignature(this.converSignature(signature), isHtml, !!oIdentity.signatureInsertBefore()); + editor.setSignature(this.converSignature(signature), isHtml, !!identity.signatureInsertBefore()); }); } } diff --git a/vendors/ckeditor-plugins/signature/plugin.js b/vendors/ckeditor-plugins/signature/plugin.js index 8e604f98a..f7e2fb4be 100644 --- a/vendors/ckeditor-plugins/signature/plugin.js +++ b/vendors/ckeditor-plugins/signature/plugin.js @@ -32,14 +32,14 @@ editor.__previos_signature_is_html = false; } - skipInsert = true; + skipInsert = false; if (isHtml) { var clearSig = clearHtmlLine(editor.__previos_signature); text = text.replace(/([\s\S]*)<\/signature>/igm, function(all){ var c = clearSig === clearHtmlLine(all); - if (c) { - skipInsert = false; + if (!c) { + skipInsert = true; } return c ? '' : all; }); @@ -51,9 +51,9 @@ .replace('' + editor.__previos_signature, '') .replace('' + editor.__previos_signature, ''); - if (textLen > text.length) + if (textLen === text.length) { - skipInsert = false; + skipInsert = true; } } } @@ -81,15 +81,21 @@ CKEDITOR.plugins.add('signature', { init: function(editor) { editor.addCommand('insertSignature', { - modes: { wysiwyg: 1, plain: 1 }, - exec: function (editor, cfg) - { + modes: {wysiwyg: 1, plain: 1}, + exec: function(editor, cfg) { + + if (cfg && cfg.clearCache) + { + editor.__previos_signature = undefined; + editor.__previos_signature_is_html = undefined; + return true; + } + var bIsHtml = false, bInsertBefore = false, sSignature = '', - sResultSignature = '' - ; + sResultSignature = ''; if (cfg) {