-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
86 lines (68 loc) · 2.66 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import Quill from 'quill/core';
import Toolbar from 'quill/modules/toolbar';
import Snow from 'quill/themes/snow';
import Bold from 'quill/formats/bold';
import Italic from 'quill/formats/italic';
import Header from 'quill/formats/header';
import ChangeDetector from './lib/ChangeDetector.ts';
import LinkDetector from './lib/links/LinkDetector.ts';
import EmojiDetector from './lib//emoji/EmojiDetector.ts';
Quill.register({
'modules/toolbar': Toolbar,
'themes/snow': Snow,
'formats/bold': Bold,
'formats/italic': Italic,
'formats/header': Header
});
window.quill = new Quill('#editor', {
modules: {
toolbar: true // Snow includes toolbar by default
},
theme: 'snow'
});
if (!~document.location.search.indexOf('disable')){
ChangeDetector.registerEditor(quill);
}
ChangeDetector.registerHandler(LinkDetector);
ChangeDetector.registerHandler(EmojiDetector);
quill.on(Quill.events.SCROLL_OPTIMIZE, () => {
//ChangeDetector.applyPendingListener();
});
/*
quill.on('editor-change', function(eventName, range, oldRange, source) {
if (eventName == 'selection-change') {
ChangeDetector.applyPendingListener();
}
});
*/
quill.on('editor-change', function(eventName, range, oldRange, source) {
//console.log("Editor-change: " + eventName, arguments);
if (eventName == 'selection-change') {
if (range) {
if (range.length == 0) {
console.log('====================================================================');
console.log('--------------------------------------------------------------------');
console.log('[' + source + '] User cursor is on', range.index);
console.log(window.getSelection().getRangeAt(0));
if (range.index == 3){
//debugger;
}
console.log('--------------------------------------------------------------------');
console.log('====================================================================');
} else {
var text = quill.getText(range.index, range.length);
console.log('User has highlighted "' + text + '" in ' + JSON.stringify(range));
}
} else {
console.log('Cursor not in the editor');
}
}
});
quill.setContents([
{ insert: 'Text with :( ;) :), and links www.almost-links.com' },
{ insert: ' and document https://docs.google.com/spreadsheets/d/19khEGozqREIoAN6hd440o4qrzS2ADMVokv8G5FWmWSk/edit#gid=488708073 and more text' }
]);
//window.enableDebug = function (debug){
// window.debug = debug === false ? false : true;
//};
export default Quill;