-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSettings.ts
52 lines (40 loc) · 1.53 KB
/
Settings.ts
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
import {Model} from './model';
import {VisibleSwitcher} from './VisibleSwitcher';
import {ViewSwitcher} from './viewSwitcher';
export const setSettings = function (model: Model): void {
const {body} = document;
const btnSwitchSettings = document.getElementById('btn-settings');
const nodeListOfSwitch = body.querySelectorAll<HTMLInputElement>('.js-settings-toggle');
const switcherElmForGraph: HTMLInputElement = document.getElementById('js-view-switch-graph') as HTMLInputElement;
const switcherElmForText: HTMLInputElement = document.getElementById('js-view-switch-text') as HTMLInputElement;
new ViewSwitcher(switcherElmForGraph, 'GRAPH', model);
new ViewSwitcher(switcherElmForText, 'TEXT', model);
const onSettingsChanged = function () {
body.className = `${model.viewType}`;
if (model.visibleSettings) {
body.classList.add('show-settings');
}
if (!model.visibleProps) {
body.classList.add('no-props');
}
if (!model.visibleFileSize) {
body.classList.add('no-fileSize');
}
if (!model.visibleLastUpdated) {
body.classList.add('no-lastUpdated');
}
if (!model.visibleReferenceCount) {
body.classList.add('no-referenceCount');
}
};
nodeListOfSwitch.forEach((node) => {
new VisibleSwitcher(node, model);
});
model.addEventListener(Model.EVENT.SETTING_CHANGED, onSettingsChanged);
if (btnSwitchSettings) {
btnSwitchSettings.addEventListener('click', () => {
model.visibleSettings = !model.visibleSettings;
});
}
onSettingsChanged();
};