-
Notifications
You must be signed in to change notification settings - Fork 1
/
createUI.js
207 lines (205 loc) · 6.99 KB
/
createUI.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
"use strict";
class CreateButton {
constructor(name, position) {
this.name = name;
this.position = position;
this.$imgElement = document.createElement('img');
this.action = undefined;
}
set Icon(icon) {
const iconFileName = icon;
const $imgElement = document.createElement('img');
$imgElement.setAttribute('class', 'buttonIcon');
$imgElement.setAttribute('src', `/icons/${iconFileName}`);
this.$imgElement = $imgElement;
}
get Icon() {
return this.$imgElement;
}
set Action(action) {
this.action = action;
}
get Action() {
return this.action;
}
get HTML() {
const $filterButton = document.createElement('button');
$filterButton.setAttribute('type', 'button');
$filterButton.setAttribute('class', 'filterButton');
$filterButton.setAttribute('id', this.name);
if (this.$imgElement !== undefined) {
$filterButton.appendChild(this.$imgElement);
}
return $filterButton;
}
save() {
const $navbarElement = document.querySelector(`.${this.position}`);
if ($navbarElement === null) {
throw new Error('navbarElement is null, what?');
}
$navbarElement.appendChild(this.HTML);
}
}
class CreateFilterWindow {
constructor(windowTitle) {
this.windowTitle = windowTitle;
}
get filterWindowElement() {
const documentFragment = `
<div class="filterWindow" id="${this.windowTitle}FilterWindow">
<header>
<span>${this.windowTitle}</span>
<button><img src="/icons/x.svg"/></button>
</header>
<div class="filterWindowBody"></div>
<footer></footer>
</div>`;
return document.createRange().createContextualFragment(documentFragment);
}
save() {
const $body = document.querySelector('body');
$body.appendChild(this.filterWindowElement);
}
closeEvent() {
var _a;
const $closeButton = (_a = document
.getElementById(`${this.windowTitle}FilterWindow`)) === null || _a === void 0 ? void 0 : _a.querySelector('button');
$closeButton === null || $closeButton === void 0 ? void 0 : $closeButton.addEventListener('click', (event) => {
var _a;
(_a = event.target) === null || _a === void 0 ? void 0 : _a.parentElement.parentElement.remove();
});
}
}
class CreateInputRange {
constructor(min, max, value) {
this.inputRange = document.createElement('input');
this.inputRange.setAttribute('type', 'range');
this.inputRange.setAttribute('class', 'inputRange');
this.inputRange.setAttribute('min', min);
this.inputRange.setAttribute('max', max);
this.inputRange.setAttribute('value', value);
}
get InputRange() {
return this.inputRange;
}
}
class PageEvents {
generateFilterWindow() {
const buttonList = document.querySelectorAll('.filterButton');
buttonList.forEach(($filterButton) => {
$filterButton.addEventListener('click', () => {
if (document.querySelector(`#${$filterButton.id}FilterWindow`) === null) {
const filterWindow = new CreateFilterWindow($filterButton.id);
filterWindow.save();
filterWindow.closeEvent();
}
});
});
}
moveFilterWindow() {
const $filterWindows = document.querySelectorAll('.filterWindow');
}
}
class StartPage {
loadButtons() {
const buttonList = [
{
name: 'Brightness',
icon: 'brightness.svg',
position: 'leftNavbar',
windowProperties: {
element: 'InputRange',
elementParameters: ['0', '100', '50']
},
action: undefined
},
{
name: 'Contrast',
icon: 'contrast.svg',
position: 'leftNavbar',
windowProperties: {},
action: undefined
},
{
name: 'Sharpness',
icon: 'sharpness.svg',
position: 'leftNavbar',
windowProperties: {},
action: undefined
},
{
name: 'Temperature',
icon: 'temperature.svg',
position: 'rightNavbar',
windowProperties: {},
action: undefined
},
{
name: 'Color',
icon: 'color.svg',
position: 'rightNavbar',
windowProperties: {},
action: undefined
},
{
name: 'Information',
icon: 'information.svg',
position: 'rightNavbar',
windowProperties: {},
action: undefined
}
];
buttonList.forEach((buttonObj) => {
const { name, icon, position, windowProperties, action } = buttonObj;
const $newFilterButton = new CreateButton(name, position);
$newFilterButton.Icon = icon;
$newFilterButton.Action = action;
$newFilterButton.save();
});
}
loadEvents() {
const pageEvents = new PageEvents();
pageEvents.generateFilterWindow();
}
}
// Carregar modulos
(function () {
const { loadButtons, loadEvents } = new StartPage();
loadButtons();
loadEvents();
})();
/* function loadEvents(): void {
const $filterWindow = document.querySelectorAll('.filterWindow') as NodeList;
if ($filterWindow != null) {
$filterWindow.addEventListener('mousedown', () => {
$filterWindow.classList.add('filterWindowMovePointer');
document.addEventListener('mousemove', moveFilterWindow);
});
} else throw new Error('$window is null and not an element');
document.addEventListener('mouseup', () => {
$filterWindow.classList.remove('filterWindowMovePointer');
document.removeEventListener('mousemove', moveFilterWindow);
});
function moveFilterWindow({
movementX,
movementY
}: {
movementX: number;
movementY: number;
}): void {
const { left, top }: { left: string; top: string } =
window.getComputedStyle($filterWindow);
$filterWindow.style.left = `${parseInt(left) + movementX}px`;
$filterWindow.style.top = `${parseInt(top) + movementY}px`;
}
} */
// eventRange() {
// const range = document.querySelector('.range');
// const style = document.createElement('style');
// document.body.appendChild(style);
// range.addEventListener('input', () => {
// const value = range.value;
// const valueBar = (100 * value) / range.max;
// style.textContent = `.range {background: linear-gradient(to right, #1976d2 ${valueBar}%, #a8cbee ${valueBar}%);}`;
// style.textContent += `.currentImage {filter: brightness(${Math.abs(
// value > range.max / 1.5 ? value : value / 4