1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | const EventEmitter = require('events').EventEmitter
|
8 | const inherits = require('inherits')
|
9 | const extend = require('just-extend')
|
10 |
|
11 | module.exports = Custom
|
12 | inherits(Custom, EventEmitter)
|
13 |
|
14 | function Custom (opts) {
|
15 | if (!(this instanceof Custom)) return new Custom(opts);
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | this.update(opts);
|
26 | }
|
27 |
|
28 | Custom.prototype.update = function (opts) {
|
29 | extend(this, opts);
|
30 | var el = this.content;
|
31 | if (this.content instanceof Function) {
|
32 | el = this.content(this);
|
33 | if (!el) return;
|
34 |
|
35 | if (typeof el === 'string') {
|
36 | this.container.innerHTML = el;
|
37 | }
|
38 | else if (!this.container.contains(el)) {
|
39 | this.container.appendChild(el);
|
40 | }
|
41 | }
|
42 | else if (typeof this.content === 'string') {
|
43 | this.container.innerHTML = el;
|
44 | }
|
45 | else if (this.content instanceof Element && (!this.container.contains(el))) {
|
46 | this.container.appendChild(el);
|
47 | }
|
48 | else {
|
49 |
|
50 |
|
51 | }
|
52 | }; |
\ | No newline at end of file |