Added individual signatures for every identity.

This commit is contained in:
RainLoop Team 2015-02-08 05:11:13 +04:00
parent 996703311b
commit 1119022916
45 changed files with 1353 additions and 337 deletions

View file

@ -53,6 +53,17 @@
if (editor.elementMode === CKEDITOR.ELEMENT_MODE_INLINE)
return;
editor.__plainUtils = {
plainToHtml: function(data) {
return window.rainloop_Utils_plainToHtml ?
window.rainloop_Utils_plainToHtml(data, true) : simplePlainToHtml(data);
},
htmlToPlain: function(data) {
return window.rainloop_Utils_htmlToPlain ?
window.rainloop_Utils_htmlToPlain(data, true) : simpleHtmlToPlain(data);
}
};
var plain = CKEDITOR.plugins.plain;
editor.addMode('plain', function(callback) {
@ -124,9 +135,7 @@
base: CKEDITOR.editable,
proto: {
setData: function(data) {
this.setValue(window.rainloop_Utils_htmlToPlain ?
window.rainloop_Utils_htmlToPlain(data) : simpleHtmlToPlain(data));
this.setValue(this.editor.__plainUtils.htmlToPlain(data));
this.editor.fire('dataReady');
},
setRawData: function(data) {
@ -134,8 +143,7 @@
this.editor.fire('dataReady');
},
getData: function() {
return window.rainloop_Utils_plainToHtml ?
window.rainloop_Utils_plainToHtml(this.getValue(), true) : simplePlainToHtml(this.getValue());
return this.editor.__plainUtils.plainToHtml(this.getValue());
},
getRawData: function() {
return this.getValue();

View file

@ -0,0 +1,97 @@
rl_signature_replacer = function (editor, sText, sSignature, bHtml, bInsertBefore)
{
var
bEmptyText = '' === $.trim(sText),
sNewLine = (bHtml ? '<br />' : "\n"),
sS1 = "\u0002\u0002",
sE1 = "\u0003\u0003",
sSS1 = '---1beg1---',
sEE1 = '---1end1---',
sS2 = "\u0004\u0004",
sE2 = "\u0005\u0005",
sSS2 = '---2beg2---',
sEE2 = '---2end2---'
;
if (!bEmptyText && bHtml)
{
bEmptyText = '' !== $.trim(editor.__plainUtils.htmlToPlain(sText));
}
sText = sText.replace(sS1, sSS1).replace(sS1, sSS1).replace(sS1, sSS1).replace(sS1, sSS1);
sText = sText.replace(sE1, sEE1).replace(sE1, sEE1).replace(sE1, sEE1).replace(sE1, sEE1);
sText = sText.replace(sS2, sSS2).replace(sS2, sSS2).replace(sS2, sSS2).replace(sS2, sSS2);
sText = sText.replace(sE2, sEE2).replace(sE2, sEE2).replace(sE2, sEE2).replace(sE2, sEE2);
if (!/---1beg1---/gm.test(sText))
{
sText = sSS1 + sEE1 + sText;
}
if (!/---2beg2---/gm.test(sText))
{
sText = sText + sSS2 + sEE2;
}
if (bInsertBefore)
{
sText = sText.replace(/---1beg1---[\s\S]*---1end1---/gm, sSS1 + sSignature + sNewLine + sEE1);
sText = sText.replace(/---2beg2---[\s\S]*---2end2---/gm, sSS2 + '' + sEE2);
}
else
{
sText = sText.replace(/---1beg1---[\s\S]*---1end1---/gm, sSS1 + '' + sEE1);
sText = sText.replace(/---2beg2---[\s\S]*---2end2---/gm, sSS2 + (bEmptyText ? '' : sNewLine) + sSignature + sEE2);
}
sText = sText.replace(/---1beg1---/g, sS1);
sText = sText.replace(/---1end1---/g, sE1);
sText = sText.replace(/---2beg2---/g, sS2);
sText = sText.replace(/---2end2---/g, sE2);
return sText;
};
CKEDITOR.plugins.add('signature', {
init: function(editor) {
editor.addCommand('insertSignature', {
modes: { wysiwyg: 1, plain: 1 },
exec: function (editor, cfg) {
var
bIsHtml = false,
bInsertBefore = false,
sSignature = ''
;
if (cfg) {
bIsHtml = undefined === cfg.isHtml ? false : !!cfg.isHtml;
bInsertBefore = undefined === cfg.insertBefore ? false : !!cfg.insertBefore;
sSignature = undefined === cfg.signature ? '' : cfg.signature;
}
try {
if ('plain' === editor.mode && editor.__plain && editor.__plainUtils) {
if (bIsHtml && editor.__plainUtils.htmlToPlain) {
sSignature = editor.__plainUtils.htmlToPlain(sSignature);
}
editor.__plain.setRawData(
rl_signature_replacer(editor,
editor.__plain.getRawData(), sSignature, false, bInsertBefore));
} else {
if (!bIsHtml && editor.__plainUtils && editor.__plainUtils.plainToHtml) {
sSignature = editor.__plainUtils.plainToHtml(sSignature);
}
editor.setData(
rl_signature_replacer(editor,
editor.getData(), sSignature, true, bInsertBefore));
}
} catch (e) {}
}
});
}
});