2015-02-08 09:11:13 +08:00
|
|
|
|
|
|
|
rl_signature_replacer = function (editor, sText, sSignature, bHtml, bInsertBefore)
|
|
|
|
{
|
2015-02-17 20:04:03 +08:00
|
|
|
if (!bHtml)
|
|
|
|
{
|
|
|
|
sText = sText
|
|
|
|
.replace(/\u200C\u200C/g, '\u0002\u0002')
|
|
|
|
.replace(/\u200D\u200D/g, '\u0003\u0003')
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2015-02-08 09:11:13 +08:00
|
|
|
var
|
2015-02-16 09:21:18 +08:00
|
|
|
sTextWithoutSignature = sText
|
2015-02-17 20:04:03 +08:00
|
|
|
.replace(/\u0002\u0002[\s\S]*\u0002\u0002/gm, '')
|
|
|
|
.replace(/\u0003\u0003[\s\S]*\u0003\u0003/gm, ''),
|
2015-02-16 09:21:18 +08:00
|
|
|
bEmptyText = '' === $.trim(sTextWithoutSignature),
|
2015-02-13 01:54:12 +08:00
|
|
|
sNewLine = (bHtml ? '<br />' : "\n")
|
2015-02-08 09:11:13 +08:00
|
|
|
;
|
|
|
|
|
|
|
|
if (!bEmptyText && bHtml)
|
|
|
|
{
|
2015-02-16 09:21:18 +08:00
|
|
|
bEmptyText = '' !== $.trim(editor.__plainUtils.htmlToPlain(sTextWithoutSignature));
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
|
|
|
|
2015-02-13 01:54:12 +08:00
|
|
|
if (!/\u0002\u0002/gm.test(sText))
|
2015-02-08 09:11:13 +08:00
|
|
|
{
|
2015-02-17 20:04:03 +08:00
|
|
|
sText = "\u0002\u0002\u0002\u0002" + sText;
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
|
|
|
|
2015-02-17 20:04:03 +08:00
|
|
|
if (!/\u0003\u0003/gm.test(sText))
|
2015-02-08 09:11:13 +08:00
|
|
|
{
|
2015-02-17 20:04:03 +08:00
|
|
|
sText = sText + "\u0003\u0003\u0003\u0003";
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bInsertBefore)
|
|
|
|
{
|
2015-02-17 20:04:03 +08:00
|
|
|
sText = sText.replace(/\u0002\u0002[\s\S]*\u0002\u0002/gm, "\u0002\u0002" + sSignature + (bEmptyText ? '' : sNewLine) + "\u0002\u0002");
|
|
|
|
sText = sText.replace(/\u0003\u0003[\s\S]*\u0003\u0003/gm, "\u0003\u0003\u0003\u0003");
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-17 20:04:03 +08:00
|
|
|
sText = sText.replace(/\u0002\u0002[\s\S]*\u0002\u0002/gm, "\u0002\u0002\u0002\u0002");
|
|
|
|
sText = sText.replace(/\u0003\u0003[\s\S]*\u0003\u0003/gm, "\u0003\u0003" + (bEmptyText ? '' : sNewLine) + sSignature + "\u0003\u0003");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bHtml)
|
|
|
|
{
|
|
|
|
sText = sText
|
|
|
|
.replace(/\u0002\u0002/g, '\u200C\u200C')
|
|
|
|
.replace(/\u0003\u0003/g, '\u200D\u200D')
|
|
|
|
;
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return sText;
|
|
|
|
};
|
|
|
|
|
|
|
|
CKEDITOR.plugins.add('signature', {
|
|
|
|
init: function(editor) {
|
|
|
|
editor.addCommand('insertSignature', {
|
|
|
|
modes: { wysiwyg: 1, plain: 1 },
|
2015-02-17 20:04:03 +08:00
|
|
|
exec: function (editor, cfg)
|
|
|
|
{
|
2015-02-08 09:11:13 +08:00
|
|
|
|
|
|
|
var
|
|
|
|
bIsHtml = false,
|
|
|
|
bInsertBefore = false,
|
2015-02-17 20:04:03 +08:00
|
|
|
sSignature = '',
|
|
|
|
sResultSignature = ''
|
2015-02-08 09:11:13 +08:00
|
|
|
;
|
|
|
|
|
2015-02-17 20:04:03 +08:00
|
|
|
if (cfg)
|
|
|
|
{
|
2015-02-08 09:11:13 +08:00
|
|
|
bIsHtml = undefined === cfg.isHtml ? false : !!cfg.isHtml;
|
|
|
|
bInsertBefore = undefined === cfg.insertBefore ? false : !!cfg.insertBefore;
|
|
|
|
sSignature = undefined === cfg.signature ? '' : cfg.signature;
|
|
|
|
}
|
|
|
|
|
2015-02-17 20:04:03 +08:00
|
|
|
sResultSignature = sSignature;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ('plain' === editor.mode && editor.__plain && editor.__plainUtils)
|
|
|
|
{
|
|
|
|
if (editor.__plainUtils && editor.__plainUtils.htmlToPlain)
|
|
|
|
{
|
|
|
|
if (bIsHtml)
|
|
|
|
{
|
|
|
|
sResultSignature = editor.__plainUtils.htmlToPlain(sResultSignature);
|
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
editor.__plain.setRawData(
|
|
|
|
rl_signature_replacer(editor,
|
2015-02-17 20:04:03 +08:00
|
|
|
editor.__plain.getRawData(), sResultSignature, false, bInsertBefore));
|
2015-02-08 09:11:13 +08:00
|
|
|
|
2015-02-17 20:04:03 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (editor.__plainUtils && editor.__plainUtils.plainToHtml)
|
|
|
|
{
|
|
|
|
if (!bIsHtml)
|
|
|
|
{
|
|
|
|
sResultSignature = editor.__plainUtils.plainToHtml(sResultSignature);
|
|
|
|
}
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
editor.setData(
|
|
|
|
rl_signature_replacer(editor,
|
2015-02-17 20:04:03 +08:00
|
|
|
editor.getData(), sResultSignature, true, bInsertBefore));
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
2015-02-17 20:04:03 +08:00
|
|
|
}
|
|
|
|
catch (e) {}
|
2015-02-08 09:11:13 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|