-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPageHtmlJS_Couleurs.h
More file actions
321 lines (271 loc) · 9.63 KB
/
Copy pathPageHtmlJS_Couleurs.h
File metadata and controls
321 lines (271 loc) · 9.63 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
//****************************************************
// Page HTML et Javascript - Gestion des couleurs *
//****************************************************
const char *CouleursHtml = R"====(
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Colors</title>
<link rel="stylesheet" href="/commun.css">
<style>
.Zone {
width: 100%;
border: 1px solid grey;
border-radius: 10px;
margin-top: 10px;
background-color: rgba(30,30,30,0.3);
}
.boldT {
text-align: left;
font-weight: bold;
padding: 10px;
}
.form {
margin: auto;
padding: 10px;
display: table;
text-align:left;
width:100%;
}
.ligne {
display: table-row;
margin-top: 5px;
}
.ligneB {
font-weight: bold;
}
.ligne div {
display: table-cell;
margin: 5px;
text-align: left;
font-size: 20px;
height: 25px;
}
.liste {
display:flex;
justify-content:center;
text-align:left;
}
#onglets2 {
display:block;
}
.Bparametres { border: inset 10px azure; }
.Bcouleurs { border: inset 4px azure; }
.les_boutons {
display:flex;
justify-content:space-between;
}
</style>
</head>
<body onload="Init();">
<div id="lesOnglets"></div>
<h2>Choix des couleurs</h2>
<div class="Zone">
<div class="form" id="colors"></div>
</div>
<br>
<div class="les_boutons">
<input class="bouton" type="button" value="Couleurs par défaut"
onclick="SendValues(false);">
<input class="bouton" type="button" value="Sauvegarder"
onclick="SendValues(true);">
</div>
<br>
<script>
var BordsInverse = [".Bparametres", ".Bcouleurs"];
function Init() {
SetHautBas();
SetCurseurs();
LoadParaFixe();
}
function SetCurseurs() {
let S = "<div class='ligne ligneB'><div>Champ</div><div>Texte</div><div>Fond / Courbe</div><div>Bordure</div></div>";
for (let i = 0; i < Koul.length; i++) {
S += "<div class='ligne'>";
S += "<div>" + Koul[i][0] + "</div>";
S += "<div><input type='color' id='text_color" + i + "' value='#000000' onchange='readCouleur();'></div>";
S += "<div><input type='color' id='bg_color" + i + "' value='#000000' onchange='readCouleur();'></div>";
S += "<div><input type='color' id='bord_color" + i + "' value='#000000' onchange='readCouleur();'></div>";
S += "</div>";
}
GH("colors", S);
}
function readCouleur() {
for (let i = 0; i < Koul.length; i++) {
if (Koul[i][1]) Koul[i][1] = GID("text_color" + i).value.substring(1);
if (Koul[i][3]) Koul[i][3] = GID("bg_color" + i).value.substring(1);
if (Koul[i][5]) Koul[i][5] = GID("bord_color" + i).value.substring(1);
}
CoulPage();
setCouleur();
}
function CoulPage() {
setColorQuery("body", "#" + Koul[0][1]);
document.body.style.background =
"linear-gradient(#" + Koul[0][5] + ",#" + Koul[0][3] + ",#" + Koul[0][5] + ")";
}
function SendValues(update) {
let S = "?couleurs=";
if(update){
for (let i = 0; i < Koul.length; i++) {
if (Koul[i][1]) S += Koul[i][1];
if (Koul[i][3]) S += Koul[i][3];
if (Koul[i][5]) S += Koul[i][5];
}
}
const xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
location.reload();
}
};
xhttp.open("GET", "/CouleurUpdate" + S, true);
xhttp.send();
}
function SetParaFixe() {
GID("Bwifi").style.display = (F.ESP32_Type != 10) ? "inline-block" : "none";
Set_Couleurs();
}
</script>
<br>
<div id="pied"></div>
<script src="/ParaCommunJS"></script>
<script src="/CommunCouleurJS"></script>
</body>
</html>
)====";
const char *CommunCouleurJS = R"====(
let Koul = []; // Couleurs courantes
let Coul_Page, Coul_Bout, Coul_W, Coul_VA, Coul_Wh, Coul_Tab, Coul_Graphe, Coul_Temp, Coul_Ouvre;
//------------------------------------------------------
// Etabli les couleurs
//------------------------------------------------------
function Set_Couleurs() {
let Retour = F.Couleurs;
if (Retour !== "") {
let L = Retour.length;
let j = 0;
for (let i = 0; i < Koul.length; i++) {
if (Koul[i][1] && j + 6 <= L) { Koul[i][1] = Retour.substring(j, j + 6); j += 6; }
if (Koul[i][3] && j + 6 <= L) { Koul[i][3] = Retour.substring(j, j + 6); j += 6; }
if (Koul[i][5] && j + 6 <= L) { Koul[i][5] = Retour.substring(j, j + 6); j += 6; }
}
}
setCouleur();
}
//------------------------------------------------------
// Applique les couleurs partout dans la page
//------------------------------------------------------
function setCouleur() {
for (let i = 0; i < Koul.length; i++) {
// --- TEXTE ---
if (Koul[i][1]) {
let tc = GID("text_color" + i);
if (tc) tc.value = "#" + Koul[i][1];
if (Koul[i][2]) {
for (let j = 0; j < Koul[i][2].length; j++) {
setColorQuery(Koul[i][2][j], "#" + Koul[i][1]);
}
}
} else {
if (GID("text_color" + i))
GID("text_color" + i).style.display = "none";
}
// --- FOND ---
if (Koul[i][3]) {
let bg = GID("bg_color" + i);
if (bg) bg.value = "#" + Koul[i][3];
if (Koul[i][4]) {
for (let j = 0; j < Koul[i][4].length; j++) {
setBgColorQuery(Koul[i][4][j], "#" + Koul[i][3]);
}
}
} else {
if (GID("bg_color" + i))
GID("bg_color" + i).style.display = "none";
}
// --- BORDURE ---
if (Koul[i][5]) {
let bd = GID("bord_color" + i);
if (bd) bd.value = "#" + Koul[i][5];
if (Koul[i][6]) {
for (let j = 0; j < Koul[i][6].length; j++) {
setBoColorQuery(Koul[i][6][j], "#" + Koul[i][5]);
}
}
} else {
if (GID("bord_color" + i))
GID("bord_color" + i).style.display = "none";
}
}
//------------------------------------------------------
// Inversion bordures (éclaircir)
//------------------------------------------------------
for (let i = 0; i < BordsInverse.length; i++) {
let liste = document.querySelectorAll(BordsInverse[i]);
for (let j = 0; j < liste.length; j++) {
let rgb = liste[j].style.borderColor;
if (!rgb || rgb.indexOf("(") < 0) continue;
rgb = rgb.substring(rgb.indexOf("(") + 1, rgb.indexOf(")"));
let tmp = rgb.split(",");
if (tmp.length < 3) continue;
let hexColor = "#";
for (let k = 0; k < 3; k++) {
let c = Math.min(255, Math.floor(tmp[k] * 1.8));
let H = ("00" + c.toString(16)).slice(-2);
hexColor += H;
}
liste[j].style.borderColor = hexColor;
}
}
}
//------------------------------------------------------
function setColorQuery(S, C) {
document.querySelectorAll(S).forEach(e => e.style.color = C);
}
function setBgColorQuery(S, C) {
document.querySelectorAll(S).forEach(e => e.style.background = C);
}
function setBoColorQuery(S, C) {
document.querySelectorAll(S).forEach(e => e.style.borderColor = C);
}
//------------------------------------------------------
// Valeurs par défaut
//------------------------------------------------------
function CouleurDefaut(){
let Coul=[];
//Format: nom,CoulTexte,QueryTexte,CoulFond,QueryFond,CoulBorder,QueryBorder
Coul_Page = Coul.length;
Coul.push(["Page","*",,"*",,"*",]);
Coul_Bout = Coul.length;
Coul.push(["Boutons haut des pages","*",["a:visited","a:link"],"*",[".Bonglet",".Bonglet2"],"*",[".Bonglet",".Bonglet2"]]);
Coul.push(["Champs de saisie","*",["input","select"],"*",["input","select"],"*",["input","select"]]);
Coul_Tab = Coul.length;
Coul.push(["Tableaux","*",[".tableau",".grid-container1",".grid-container2",".grid-container2M"],"*",[".tableau"],"*",[".tableau"]]);
Coul_W = Coul.length;
Coul.push(["Puissance Active en W",,,"*",[".W"],,]);
Coul_VA = Coul.length;
Coul.push(["Puissance Apparente en VA",,,"*",[".VA"],,]);
Coul_Wh = Coul.length;
Coul.push(["Energie Active en Wh",,,"*",[".Wh"],,]);
Coul.push(["Volt V",,,"*",[".V"],,]);
Coul.push(["Ampère A",,,"*",[".A"],,]);
Coul.push(["Cosinus Phi",,,"*",[".phi"],,]);
Coul.push(["Hertz et divers",,,"*",[".Hz",".Enph"],,]);
Coul_Graphe = Coul.length;
Coul.push(["Graphes","*",,"*",,"*",]);
Coul_Temp = Coul.length;
Coul.push(["Temperature Canal 0",,,"*",,,]);
Coul.push(["Temperature Canal 1",,,"*",,,]);
Coul.push(["Temperature Canal 2",,,"*",,,]);
Coul.push(["Temperature Canal 3",,,"*",,,]);
Coul_Ouvre = Coul.length;
Coul.push(["Ouverture SSR/Triac 0",,,"*",,,]);
Coul.push(["Ouverture SSR/Triac 1",,,"*",,,]);
Coul.push(["Ouverture SSR/Triac 2",,,"*",,,]);
Coul.push(["Ouverture SSR/Triac 3",,,"*",,,]);
Koul=Coul.slice(); //copie de travail
}
CouleurDefaut(); // initialisation couleurs courantes
)====";