new text editor: tinyMCE

This commit is contained in:
2020-02-24 21:37:14 +01:00
parent abcb059355
commit 3fd854ddf1
15 changed files with 425 additions and 145 deletions

View File

@@ -354,6 +354,7 @@ function CATC(asGlobals)
//Officially a new page
var bFirstPage = (sCurrPage == '');
self.vars('page', sNextPage);
self.setPageTitle('');
//Update Page Title
var sDetail = asHash.items[0] || '';
@@ -430,103 +431,4 @@ function CATC(asGlobals)
this.getTemplateItem = function(sItemName) {
return $('.template-items').find('.'+sItemName).clone();
}
}
Quill.register({'modules/better-table': quillBetterTable}, true);
class Editor {
constructor(sEditorId, bReadOnly) {
this.keystrokes = 0;
this.readOnly = bReadOnly || false;
this.sCursorPos = '';
//DOM Elements
this.$Editor = $(sEditorId);
this.onKeyStroke = function() {};
this.oQuill = new Quill(sEditorId, {
theme: 'snow',
placeholder: 'Notes',
readOnly: bReadOnly,
modules: {
table: false,
'better-table': {
operationMenu: {
items: {
mergeCells: false,
unmergeCells: false
}
}
},
keyboard: {
bindings: quillBetterTable.keyboardBindings
},
toolbar: [
['bold', 'italic', 'underline', 'strike'],
//['blockquote', 'code-block'],
[{ 'color': [] }, { 'background': [] }],
[{ 'header': 1 }, { 'header': 2 }, 'blockquote'],
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
//[{ 'script': 'sub'}, { 'script': 'super' }],
//[{ 'indent': '-1'}, { 'indent': '+1' }],
//[{ 'direction': 'rtl' }],
//[{ 'size': ['small', false, 'large', 'huge'] }],
//[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
//[{ 'font': [] }],
[{ 'align': [] }],
['table'],
['link', 'image'],
['clean']
]
}
});
var oToolbar = this.oQuill.getModule('toolbar');
oToolbar.addHandler('table', () => {
let tableModule = this.oQuill.getModule('better-table');
tableModule.insertTable(3, 3);
});
this._initEvents();
this._postInit();
}
_initEvents() {
//Key strokes
this.$Editor.keydown((e) => {
if($.inArray(e.which, [13, 37, 38, 39, 40]) == -1) this.onKeyStroke(e);
});
//On text modification
this.oQuill.on('text-change', (delta, oldDelta, sSource) => {this._incKeyStrokes();});
}
_postInit(iPage) {
if(!this.readOnly) this.oQuill.focus();
}
_incKeyStrokes() {
this.keystrokes += 1;
}
getContent() {
return this.oQuill.getContents().ops;
}
setContent(asOps) {
this.oQuill.setContents(asOps);
this._postInit();
}
isEmpty() {
const rEmpty = /^(<p>(<br>|<br\/>|<br\s\/>|\s+|)<\/p>|)$/gm;
return rEmpty.test(this.oQuill.getText().trim());
}
quill2Html(asDelta) {
var tempCont = document.createElement('div');
(new Quill(tempCont)).setContents(asDelta);
return tempCont.getElementsByClassName('ql-editor')[0].innerHTML;
}
}