forked from slab/quill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme.js
48 lines (41 loc) · 1.22 KB
/
theme.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
import Emitter from './emitter';
import extend from 'extend';
import logger from './logger';
let debug = logger('[quill:theme]');
class Theme {
constructor(quill, options) {
this.quill = quill;
this.options = options;
this.modules = {};
this.quill.once(Emitter.events.READY, this.init.bind(this));
}
init() {
Object.keys(this.options.modules).forEach((name) => {
if (this.modules[name] == null) {
this.addModule(name);
}
});
}
addModule(name) {
let moduleClass = Theme.modules[name];
if (moduleClass == null) {
return debug.error(`Cannot load ${name} module. Are you sure you registered it?`);
}
let options = this.options.modules[name];
if (options === true) { // Allow addModule('module', true)
options = {};
} else if (typeof options !== 'object' && !(options instanceof HTMLElement)) {
// Allow addModule('toolbar', '#toolbar');
options = { container: options };
}
options = extend(true, {}, moduleClass.DEFAULTS || {}, options);
this.modules[name] = new moduleClass(this.quill, options);
return this.modules[name];
}
}
Theme.DEFAULTS = {};
Theme.themes = {
'default': Theme
};
Theme.modules = {};
export default Theme;