snappymail/dev/External/CKEditor.js

103 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-09-23 17:20:00 +08:00
const config = {
title: false,
stylesSet: false,
customConfig: '',
contentsCss: '',
toolbarGroups: [
2020-09-23 17:20:00 +08:00
{ name: 'spec' },
{ name: 'styles' },
{ name: 'basicstyles', groups: ['basicstyles', 'cleanup', 'bidi'] },
{ name: 'colors' },
{ name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align'] },
{ name: 'links' },
{ name: 'insert' },
{ name: 'document', groups: ['mode', 'document', 'doctools'] },
{ name: 'others' }
],
removePlugins: 'liststyle',
removeButtons: 'Format,Undo,Redo,Cut,Copy,Paste,Anchor,Strike,Subscript,Superscript,Image,SelectAll',
removeDialogTabs: 'link:advanced;link:target;image:advanced;images:advanced',
2020-09-23 17:20:00 +08:00
extraPlugins: 'plain,signature',
2020-09-23 17:20:00 +08:00
allowedContent: true,
extraAllowedContent: true,
2020-09-23 17:20:00 +08:00
fillEmptyBlocks: false,
ignoreEmptyParagraph: true,
disableNativeSpellChecker: false,
2020-09-23 17:20:00 +08:00
colorButton_enableAutomatic: false,
colorButton_enableMore: true,
2020-09-23 17:20:00 +08:00
font_defaultLabel: 'Arial',
fontSize_defaultLabel: '13',
fontSize_sizes: '10/10px;12/12px;13/13px;14/14px;16/16px;18/18px;20/20px;24/24px;28/28px;36/36px;48/48px'
2020-09-23 17:20:00 +08:00
},
htmlEditorLangsMap = {
'ar_sa': 'ar-sa',
'pt_br': 'pt-br',
'zh_cn': 'zh-cn',
};
export function createCKEditor(element)
{
const language = (rl.settings.get('Language') || 'en').toLowerCase(),
noSource = !rl.settings.app('allowHtmlEditorSourceButton'),
noBidi = !rl.settings.app('allowHtmlEditorBitiButtons');
2020-09-23 17:20:00 +08:00
if (!config.__cfgInited) {
config.__cfgInited = true;
2020-09-23 17:20:00 +08:00
if (noSource) {
config.removeButtons += ',Source';
2020-09-23 17:20:00 +08:00
}
if (noBidi) {
config.removePlugins += ',bidi';
2020-09-23 17:20:00 +08:00
}
}
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_P;
config.language = htmlEditorLangsMap[language] || language.substr(0,2);
2020-09-23 17:20:00 +08:00
if (CKEDITOR.env) {
CKEDITOR.env.isCompatible = true;
}
const editor = CKEDITOR.appendTo(element, config);
editor.on('key', event => !(event && event.data && 'Tab' == event.data.key));
if (window.FileReader) {
editor.on('drop', event => {
if (0 < event.data.dataTransfer.getFilesCount()) {
const file = event.data.dataTransfer.getFile(0);
if (file && event.data.dataTransfer.id && file.type && file.type.match(/^image/i)) {
const id = event.data.dataTransfer.id,
imageId = `[img=${id}]`,
reader = new FileReader();
reader.onloadend = () => {
if (reader.result && 'wysiwyg' === editor.mode) {
try {
editor.setData(editor.getData().replace(imageId, `<img src="${reader.result}"/>`));
} catch (e) {} // eslint-disable-line no-empty
2020-09-23 17:20:00 +08:00
}
};
reader.readAsDataURL(file);
event.data.dataTransfer.setData('text/html', imageId);
}
}
});
}
return editor;
}