mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-02 14:07:04 +03:00
prettier --write
This commit is contained in:
parent
450528ff00
commit
8a0be3212d
164 changed files with 7053 additions and 9008 deletions
|
|
@ -1,13 +1,11 @@
|
|||
|
||||
import window from 'window';
|
||||
import _ from '_';
|
||||
import $ from '$';
|
||||
import {htmlEditorDefaultConfig, htmlEditorLangsMap} from 'Common/Globals';
|
||||
import {EventKeyCode, Magics} from 'Common/Enums';
|
||||
import { htmlEditorDefaultConfig, htmlEditorLangsMap } from 'Common/Globals';
|
||||
import { EventKeyCode, Magics } from 'Common/Enums';
|
||||
import * as Settings from 'Storage/Settings';
|
||||
|
||||
class HtmlEditor
|
||||
{
|
||||
class HtmlEditor {
|
||||
editor;
|
||||
blurTimer = 0;
|
||||
|
||||
|
|
@ -29,8 +27,7 @@ class HtmlEditor
|
|||
* @param {Function=} onReady
|
||||
* @param {Function=} onModeChange
|
||||
*/
|
||||
constructor(element, onBlur = null, onReady = null, onModeChange = null)
|
||||
{
|
||||
constructor(element, onBlur = null, onReady = null, onModeChange = null) {
|
||||
this.onBlur = onBlur;
|
||||
this.onReady = onReady;
|
||||
this.onModeChange = onModeChange;
|
||||
|
|
@ -44,15 +41,13 @@ class HtmlEditor
|
|||
}
|
||||
|
||||
runOnBlur() {
|
||||
if (this.onBlur)
|
||||
{
|
||||
if (this.onBlur) {
|
||||
this.onBlur();
|
||||
}
|
||||
}
|
||||
|
||||
blurTrigger() {
|
||||
if (this.onBlur)
|
||||
{
|
||||
if (this.onBlur) {
|
||||
window.clearTimeout(this.blurTimer);
|
||||
this.blurTimer = window.setTimeout(() => {
|
||||
this.runOnBlur();
|
||||
|
|
@ -61,8 +56,7 @@ class HtmlEditor
|
|||
}
|
||||
|
||||
focusTrigger() {
|
||||
if (this.onBlur)
|
||||
{
|
||||
if (this.onBlur) {
|
||||
window.clearTimeout(this.blurTimer);
|
||||
}
|
||||
}
|
||||
|
|
@ -78,8 +72,7 @@ class HtmlEditor
|
|||
* @returns {void}
|
||||
*/
|
||||
clearCachedSignature() {
|
||||
if (this.editor)
|
||||
{
|
||||
if (this.editor) {
|
||||
this.editor.execCommand('insertSignature', {
|
||||
clearCache: true
|
||||
});
|
||||
|
|
@ -93,8 +86,7 @@ class HtmlEditor
|
|||
* @returns {void}
|
||||
*/
|
||||
setSignature(signature, html, insertBefore = false) {
|
||||
if (this.editor)
|
||||
{
|
||||
if (this.editor) {
|
||||
this.editor.execCommand('insertSignature', {
|
||||
isHtml: html,
|
||||
insertBefore: insertBefore,
|
||||
|
|
@ -111,8 +103,7 @@ class HtmlEditor
|
|||
}
|
||||
|
||||
resetDirty() {
|
||||
if (this.editor)
|
||||
{
|
||||
if (this.editor) {
|
||||
this.editor.resetDirty();
|
||||
}
|
||||
}
|
||||
|
|
@ -122,24 +113,19 @@ class HtmlEditor
|
|||
* @returns {string}
|
||||
*/
|
||||
getData(wrapIsHtml = false) {
|
||||
|
||||
let result = '';
|
||||
if (this.editor)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain)
|
||||
{
|
||||
if (this.editor) {
|
||||
try {
|
||||
if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain) {
|
||||
result = this.editor.__plain.getRawData();
|
||||
} else {
|
||||
result = wrapIsHtml
|
||||
? '<div data-html-editor-font-wrapper="true" style="font-family: arial, sans-serif; font-size: 13px;">' +
|
||||
this.editor.getData() +
|
||||
'</div>'
|
||||
: this.editor.getData();
|
||||
}
|
||||
else
|
||||
{
|
||||
result = wrapIsHtml ?
|
||||
'<div data-html-editor-font-wrapper="true" style="font-family: arial, sans-serif; font-size: 13px;">' +
|
||||
this.editor.getData() + '</div>' : this.editor.getData();
|
||||
}
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -154,271 +140,217 @@ class HtmlEditor
|
|||
}
|
||||
|
||||
modeToggle(plain, resize) {
|
||||
if (this.editor)
|
||||
{
|
||||
if (this.editor) {
|
||||
try {
|
||||
if (plain)
|
||||
{
|
||||
if ('plain' === this.editor.mode)
|
||||
{
|
||||
if (plain) {
|
||||
if ('plain' === this.editor.mode) {
|
||||
this.editor.setMode('wysiwyg');
|
||||
}
|
||||
}
|
||||
else if ('wysiwyg' === this.editor.mode)
|
||||
{
|
||||
} else if ('wysiwyg' === this.editor.mode) {
|
||||
this.editor.setMode('plain');
|
||||
}
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
if (resize)
|
||||
{
|
||||
if (resize) {
|
||||
this.resize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setHtmlOrPlain(text, focus) {
|
||||
if (':HTML:' === text.substr(0, 6))
|
||||
{
|
||||
if (':HTML:' === text.substr(0, 6)) {
|
||||
this.setHtml(text.substr(6), focus);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this.setPlain(text, focus);
|
||||
}
|
||||
}
|
||||
|
||||
setHtml(html, focus) {
|
||||
if (this.editor && this.__inited)
|
||||
{
|
||||
if (this.editor && this.__inited) {
|
||||
this.clearCachedSignature();
|
||||
|
||||
this.modeToggle(true);
|
||||
|
||||
html = html.replace(/<p[^>]*><\/p>/ig, '');
|
||||
html = html.replace(/<p[^>]*><\/p>/gi, '');
|
||||
|
||||
try {
|
||||
this.editor.setData(html);
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
if (focus)
|
||||
{
|
||||
if (focus) {
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
replaceHtml(find, replaceHtml) {
|
||||
if (this.editor && this.__inited && 'wysiwyg' === this.editor.mode)
|
||||
{
|
||||
if (this.editor && this.__inited && 'wysiwyg' === this.editor.mode) {
|
||||
try {
|
||||
this.editor.setData(this.editor.getData().replace(find, replaceHtml));
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
}
|
||||
}
|
||||
|
||||
setPlain(plain, focus) {
|
||||
if (this.editor && this.__inited)
|
||||
{
|
||||
if (this.editor && this.__inited) {
|
||||
this.clearCachedSignature();
|
||||
|
||||
this.modeToggle(false);
|
||||
if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain)
|
||||
{
|
||||
if ('plain' === this.editor.mode && this.editor.plugins.plain && this.editor.__plain) {
|
||||
this.editor.__plain.setRawData(plain);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
try {
|
||||
this.editor.setData(plain);
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
}
|
||||
|
||||
if (focus)
|
||||
{
|
||||
if (focus) {
|
||||
this.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init() {
|
||||
if (this.element && !this.editor)
|
||||
{
|
||||
const
|
||||
initFunc = () => {
|
||||
if (this.element && !this.editor) {
|
||||
const initFunc = () => {
|
||||
const config = htmlEditorDefaultConfig,
|
||||
language = Settings.settingsGet('Language'),
|
||||
allowSource = !!Settings.appSettingsGet('allowHtmlEditorSourceButton'),
|
||||
biti = !!Settings.appSettingsGet('allowHtmlEditorBitiButtons');
|
||||
|
||||
const
|
||||
config = htmlEditorDefaultConfig,
|
||||
language = Settings.settingsGet('Language'),
|
||||
allowSource = !!Settings.appSettingsGet('allowHtmlEditorSourceButton'),
|
||||
biti = !!Settings.appSettingsGet('allowHtmlEditorBitiButtons');
|
||||
if ((allowSource || !biti) && !config.toolbarGroups.__cfgInited) {
|
||||
config.toolbarGroups.__cfgInited = true;
|
||||
|
||||
if ((allowSource || !biti) && !config.toolbarGroups.__cfgInited)
|
||||
{
|
||||
config.toolbarGroups.__cfgInited = true;
|
||||
|
||||
if (allowSource)
|
||||
{
|
||||
config.removeButtons = config.removeButtons.replace(',Source', '');
|
||||
}
|
||||
|
||||
if (!biti)
|
||||
{
|
||||
config.removePlugins += (config.removePlugins ? ',' : '') + 'bidi';
|
||||
}
|
||||
if (allowSource) {
|
||||
config.removeButtons = config.removeButtons.replace(',Source', '');
|
||||
}
|
||||
|
||||
config.enterMode = window.CKEDITOR.ENTER_BR;
|
||||
config.shiftEnterMode = window.CKEDITOR.ENTER_P;
|
||||
if (!biti) {
|
||||
config.removePlugins += (config.removePlugins ? ',' : '') + 'bidi';
|
||||
}
|
||||
}
|
||||
|
||||
config.language = htmlEditorLangsMap[(language || 'en').toLowerCase()] || 'en';
|
||||
if (window.CKEDITOR.env)
|
||||
{
|
||||
window.CKEDITOR.env.isCompatible = true;
|
||||
config.enterMode = window.CKEDITOR.ENTER_BR;
|
||||
config.shiftEnterMode = window.CKEDITOR.ENTER_P;
|
||||
|
||||
config.language = htmlEditorLangsMap[(language || 'en').toLowerCase()] || 'en';
|
||||
if (window.CKEDITOR.env) {
|
||||
window.CKEDITOR.env.isCompatible = true;
|
||||
}
|
||||
|
||||
this.editor = window.CKEDITOR.appendTo(this.element, config);
|
||||
|
||||
this.editor.on('key', (event) => {
|
||||
if (event && event.data && EventKeyCode.Tab === event.data.keyCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.editor = window.CKEDITOR.appendTo(this.element, config);
|
||||
return true;
|
||||
});
|
||||
|
||||
this.editor.on('key', (event) => {
|
||||
if (event && event.data && EventKeyCode.Tab === event.data.keyCode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
this.editor.on('blur', () => {
|
||||
this.blurTrigger();
|
||||
});
|
||||
|
||||
return true;
|
||||
});
|
||||
this.editor.on('mode', () => {
|
||||
this.blurTrigger();
|
||||
if (this.onModeChange) {
|
||||
this.onModeChange('plain' !== this.editor.mode);
|
||||
}
|
||||
});
|
||||
|
||||
this.editor.on('blur', () => {
|
||||
this.blurTrigger();
|
||||
});
|
||||
this.editor.on('focus', () => {
|
||||
this.focusTrigger();
|
||||
});
|
||||
|
||||
this.editor.on('mode', () => {
|
||||
this.blurTrigger();
|
||||
if (this.onModeChange)
|
||||
{
|
||||
this.onModeChange('plain' !== this.editor.mode);
|
||||
}
|
||||
});
|
||||
if (window.FileReader) {
|
||||
this.editor.on('drop', (event) => {
|
||||
if (0 < event.data.dataTransfer.getFilesCount()) {
|
||||
const file = event.data.dataTransfer.getFile(0);
|
||||
if (file && window.FileReader && event.data.dataTransfer.id && file.type && file.type.match(/^image/i)) {
|
||||
const id = event.data.dataTransfer.id,
|
||||
imageId = `[img=${id}]`,
|
||||
reader = new window.FileReader();
|
||||
|
||||
this.editor.on('focus', () => {
|
||||
this.focusTrigger();
|
||||
});
|
||||
reader.onloadend = () => {
|
||||
if (reader.result) {
|
||||
this.replaceHtml(imageId, `<img src="${reader.result}" />`);
|
||||
}
|
||||
};
|
||||
|
||||
if (window.FileReader)
|
||||
{
|
||||
this.editor.on('drop', (event) => {
|
||||
if (0 < event.data.dataTransfer.getFilesCount())
|
||||
{
|
||||
const file = event.data.dataTransfer.getFile(0);
|
||||
if (file && window.FileReader && event.data.dataTransfer.id &&
|
||||
file.type && file.type.match(/^image/i))
|
||||
{
|
||||
const
|
||||
id = event.data.dataTransfer.id,
|
||||
imageId = `[img=${id}]`,
|
||||
reader = new window.FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
|
||||
reader.onloadend = () => {
|
||||
if (reader.result)
|
||||
{
|
||||
this.replaceHtml(imageId, `<img src="${reader.result}" />`);
|
||||
}
|
||||
};
|
||||
|
||||
reader.readAsDataURL(file);
|
||||
|
||||
event.data.dataTransfer.setData('text/html', imageId);
|
||||
}
|
||||
event.data.dataTransfer.setData('text/html', imageId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.editor.on('instanceReady', () => {
|
||||
if (this.editor.removeMenuItem) {
|
||||
this.editor.removeMenuItem('cut');
|
||||
this.editor.removeMenuItem('copy');
|
||||
this.editor.removeMenuItem('paste');
|
||||
}
|
||||
|
||||
this.editor.on('instanceReady', () => {
|
||||
this.__resizable = true;
|
||||
this.__inited = true;
|
||||
|
||||
if (this.editor.removeMenuItem)
|
||||
{
|
||||
this.editor.removeMenuItem('cut');
|
||||
this.editor.removeMenuItem('copy');
|
||||
this.editor.removeMenuItem('paste');
|
||||
}
|
||||
this.resize();
|
||||
|
||||
this.__resizable = true;
|
||||
this.__inited = true;
|
||||
if (this.onReady) {
|
||||
this.onReady();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.resize();
|
||||
|
||||
if (this.onReady)
|
||||
{
|
||||
this.onReady();
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
if (window.CKEDITOR)
|
||||
{
|
||||
if (window.CKEDITOR) {
|
||||
initFunc();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
window.__initEditor = initFunc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
focus() {
|
||||
if (this.editor)
|
||||
{
|
||||
if (this.editor) {
|
||||
try {
|
||||
this.editor.focus();
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
}
|
||||
}
|
||||
|
||||
hasFocus() {
|
||||
if (this.editor)
|
||||
{
|
||||
if (this.editor) {
|
||||
try {
|
||||
return !!this.editor.focusManager.hasFocus;
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
blur() {
|
||||
if (this.editor)
|
||||
{
|
||||
if (this.editor) {
|
||||
try {
|
||||
this.editor.focusManager.blur(true);
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
}
|
||||
}
|
||||
|
||||
resizeEditor() {
|
||||
if (this.editor && this.__resizable)
|
||||
{
|
||||
if (this.editor && this.__resizable) {
|
||||
try {
|
||||
this.editor.resize(this.$element.width(), this.$element.innerHeight());
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
}
|
||||
}
|
||||
|
||||
setReadOnly(value) {
|
||||
if (this.editor)
|
||||
{
|
||||
if (this.editor) {
|
||||
try {
|
||||
this.editor.setReadOnly(!!value);
|
||||
}
|
||||
catch (e) {} // eslint-disable-line no-empty
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -427,4 +359,4 @@ class HtmlEditor
|
|||
}
|
||||
}
|
||||
|
||||
export {HtmlEditor, HtmlEditor as default};
|
||||
export { HtmlEditor, HtmlEditor as default };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue