mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-02-24 14:57:26 +08:00
Better multiple WYSIWYG registration
This commit is contained in:
parent
80579a3ed0
commit
4dd782014d
1 changed files with 30 additions and 20 deletions
|
@ -598,7 +598,24 @@ export const
|
|||
.replace(/~~~blockquote~~~\s*/g, '<blockquote>')
|
||||
.replace(/\s*~~~\/blockquote~~~/g, '</blockquote>')
|
||||
.replace(/\n/g, '<br>');
|
||||
};
|
||||
},
|
||||
|
||||
WYSIWYGS = ko.observableArray();
|
||||
|
||||
WYSIWYGS.push(['Squire', (owner, container, onReady)=>{
|
||||
let squire = new SquireUI(container);
|
||||
setTimeout(()=>onReady(squire), 1);
|
||||
/*
|
||||
squire.on('blur', () => owner.blurTrigger());
|
||||
squire.on('focus', () => clearTimeout(owner.blurTimer));
|
||||
squire.on('mode', () => {
|
||||
owner.blurTrigger();
|
||||
owner.onModeChange?.(!owner.isPlain());
|
||||
});
|
||||
*/
|
||||
}]);
|
||||
|
||||
rl.registerWYSIWYG = (name, construct) => WYSIWYGS.push([name, construct]);
|
||||
|
||||
export class HtmlEditor {
|
||||
/**
|
||||
|
@ -614,30 +631,23 @@ export class HtmlEditor {
|
|||
this.onModeChange = onModeChange;
|
||||
|
||||
if (element) {
|
||||
let editor;
|
||||
|
||||
onReady = onReady ? [onReady] : [];
|
||||
this.onReady = fn => onReady.push(fn);
|
||||
const readyCallback = () => {
|
||||
// TODO: make 'which' user configurable
|
||||
const which = 'CKEditor4',
|
||||
wysiwyg = WYSIWYGS.find(item => which == item[0])
|
||||
|| WYSIWYGS.find(item => 'Squire' == item[0]);
|
||||
wysiwyg[1](this, element, editor => {
|
||||
this.editor = editor;
|
||||
this.onReady = fn => fn();
|
||||
onReady.forEach(fn => fn());
|
||||
};
|
||||
|
||||
if (rl.createWYSIWYG) {
|
||||
editor = rl.createWYSIWYG(element, readyCallback);
|
||||
}
|
||||
if (!editor) {
|
||||
editor = new SquireUI(element);
|
||||
setTimeout(readyCallback, 1);
|
||||
}
|
||||
|
||||
editor.on('blur', () => this.blurTrigger());
|
||||
editor.on('focus', () => this.blurTimer && clearTimeout(this.blurTimer));
|
||||
editor.on('focus', () => clearTimeout(this.blurTimer));
|
||||
editor.on('mode', () => {
|
||||
this.blurTrigger();
|
||||
this.onModeChange?.(!this.isPlain());
|
||||
});
|
||||
onReady.forEach(fn => fn());
|
||||
this.onReady = fn => fn();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue