-
Notifications
You must be signed in to change notification settings - Fork 69
/
ToggleMode.js
96 lines (72 loc) · 2.11 KB
/
ToggleMode.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
87
88
89
90
91
92
93
94
95
96
import {
domify,
classes as domClasses,
event as domEvent,
query as domQuery
} from 'min-dom';
import {
TOGGLE_MODE_EVENT
} from '../../../util/EventHelper';
import {
ToggleOffIcon,
ToggleOnIcon
} from '../../../icons';
export default function ToggleMode(
eventBus, canvas, selection,
contextPad) {
this._eventBus = eventBus;
this._canvas = canvas;
this._selection = selection;
this._contextPad = contextPad;
this._active = false;
eventBus.on('import.parse.start', () => {
if (this._active) {
this.toggleMode(false);
eventBus.once('import.done', () => {
this.toggleMode(true);
});
}
});
eventBus.on('diagram.init', () => {
this._canvasParent = this._canvas.getContainer().parentNode;
this._palette = domQuery('.djs-palette', this._canvas.getContainer());
this._init();
});
}
ToggleMode.prototype._init = function() {
this._container = domify(`
<div class="bts-toggle-mode">
Token Simulation <span class="bts-toggle">${ ToggleOffIcon() }</span>
</div>
`);
domEvent.bind(this._container, 'click', () => this.toggleMode());
this._canvas.getContainer().appendChild(this._container);
};
ToggleMode.prototype.toggleMode = function(active = !this._active) {
if (active === this._active) {
return;
}
if (active) {
this._container.innerHTML = `Token Simulation <span class="bts-toggle">${ ToggleOnIcon() }</span>`;
domClasses(this._canvasParent).add('simulation');
domClasses(this._palette).add('hidden');
} else {
this._container.innerHTML = `Token Simulation <span class="bts-toggle">${ ToggleOffIcon() }</span>`;
domClasses(this._canvasParent).remove('simulation');
domClasses(this._palette).remove('hidden');
const elements = this._selection.get();
if (elements.length === 1) {
this._contextPad.open(elements[0]);
}
}
this._eventBus.fire(TOGGLE_MODE_EVENT, {
active
});
this._active = active;
};
ToggleMode.$inject = [
'eventBus',
'canvas',
'selection',
'contextPad'
];