mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-10-09 21:26:03 +08:00
fix: use compact template in non-destructive way (do not replace the PopupsCompose template if a different wysiwyg is used)
This commit is contained in:
parent
6169f6083f
commit
d6acf55ab2
3 changed files with 40 additions and 17 deletions
|
@ -6,7 +6,7 @@ class CompactComposerPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
NAME = 'Compact Composer',
|
NAME = 'Compact Composer',
|
||||||
AUTHOR = 'Sergey Mosin',
|
AUTHOR = 'Sergey Mosin',
|
||||||
URL = 'https://github.com/the-djmaze/snappymail/pull/1466',
|
URL = 'https://github.com/the-djmaze/snappymail/pull/1466',
|
||||||
VERSION = '1.0.0',
|
VERSION = '1.0.1',
|
||||||
RELEASE = '2024-02-23',
|
RELEASE = '2024-02-23',
|
||||||
REQUIRED = '2.34.0',
|
REQUIRED = '2.34.0',
|
||||||
LICENSE = 'AGPL v3',
|
LICENSE = 'AGPL v3',
|
||||||
|
@ -14,7 +14,7 @@ class CompactComposerPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
|
|
||||||
public function Init(): void
|
public function Init(): void
|
||||||
{
|
{
|
||||||
$this->addTemplate('templates/PopupsCompose.html');
|
$this->addTemplate('templates/PopupsCompactCompose.html');
|
||||||
$this->addCss('css/composer.css');
|
$this->addCss('css/composer.css');
|
||||||
$this->addJs('js/squire-raw.js');
|
$this->addJs('js/squire-raw.js');
|
||||||
$this->addJs('js/parsel.js');
|
$this->addJs('js/parsel.js');
|
||||||
|
|
|
@ -1,16 +1,47 @@
|
||||||
/* eslint max-len: 0 */
|
/* eslint max-len: 0 */
|
||||||
(win => {
|
(win => {
|
||||||
|
|
||||||
addEventListener('rl-view-model.create', e => {
|
const rl = win.rl;
|
||||||
if (e.detail.viewModelTemplateID === 'PopupsCompose') {
|
|
||||||
// There is a better way to do this probably,
|
if (!rl) {
|
||||||
// but we need this for drag and drop to work
|
return;
|
||||||
e.detail.attachmentsArea = e.detail.bodyArea;
|
}
|
||||||
}
|
|
||||||
|
rl.registerWYSIWYG('CompactComposer', (owner, container, onReady) => {
|
||||||
|
const editor = new CompactComposer(container);
|
||||||
|
onReady(editor);
|
||||||
});
|
});
|
||||||
|
|
||||||
const doc = win.document;
|
const doc = win.document;
|
||||||
const rl = win.rl;
|
|
||||||
|
// If a user (or admin) selected the CompactComposer we need to
|
||||||
|
// replace PopupsCompose template with PopupsCompactCompose template.
|
||||||
|
// --
|
||||||
|
// This might break some plugins if they query/change PopupsCompose template
|
||||||
|
// before this code is called. They should instead listen for
|
||||||
|
// 'rl-view-model.create' to work properly.
|
||||||
|
if (rl.settings.get('editorWysiwyg') === 'CompactComposer') {
|
||||||
|
const compactTemplate = doc.getElementById('PopupsCompactCompose');
|
||||||
|
if (!compactTemplate) {
|
||||||
|
console.error('CompactComposer: PopupsCompactCompose template not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const originalTemplate = doc.getElementById('PopupsCompose');
|
||||||
|
if (originalTemplate) {
|
||||||
|
originalTemplate.id = 'PopupsCompose_replaced';
|
||||||
|
} else {
|
||||||
|
console.warn('CompactComposer: PopupsCompose template not found');
|
||||||
|
}
|
||||||
|
compactTemplate.id = 'PopupsCompose';
|
||||||
|
|
||||||
|
addEventListener('rl-view-model.create', e => {
|
||||||
|
if (e.detail.viewModelTemplateID === 'PopupsCompose') {
|
||||||
|
// There is a better way to do this probably,
|
||||||
|
// but we need this for drag and drop to work
|
||||||
|
e.detail.attachmentsArea = e.detail.bodyArea;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const
|
const
|
||||||
removeElements = 'HEAD,LINK,META,NOSCRIPT,SCRIPT,TEMPLATE,TITLE',
|
removeElements = 'HEAD,LINK,META,NOSCRIPT,SCRIPT,TEMPLATE,TITLE',
|
||||||
|
@ -956,12 +987,4 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rl) {
|
|
||||||
rl.registerWYSIWYG('CompactComposer', (owner, container, onReady) => {
|
|
||||||
const editor = new CompactComposer(container);
|
|
||||||
onReady(editor);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
})(window);
|
})(window);
|
||||||
|
|
Loading…
Add table
Reference in a new issue