-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainV2.js
183 lines (142 loc) · 3.37 KB
/
mainV2.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
// Declaration and Initialization
var ctrA = parseInt(document.getElementById("n_adultos").innerText, 10);
var ctrC = parseInt(document.getElementById("n_criancas").innerText, 10);
var ctrB = parseInt(document.getElementById("n_bebes").innerText, 10);
disBtn("decC");
disBtn("decB");
var mainStr;
var strA = " Adulto";
var strC = " Criança";
var strB = " Bebé";
// Estado Default
var defShp = document.getElementById("shpDeaf");
var defTxt = document.getElementById("default");
mainStr = ctrA + strA;
defTxt.innerText = mainStr;
defShp.style.borderWidth = "2px";
// Estado Aberto
var openShp = document.getElementById("shpOpen");
var openTxt = document.getElementById("open");
openTxt.innerText = mainStr;
window.addEventListener('click', function(e){
if (openShp.contains(e.target) || document.getElementById("tooltip").contains(e.target)){
openShp.style.borderWidth = "2px";
defShp.style.borderWidth = "1px";
} else{
defShp.style.borderWidth = "2px";
openShp.style.borderWidth = "1px";
defTxt.innerText = mainStr;
}
});
//Increment Buttons
function incA() {
ctrA++;
Update();
}
function incC() {
ctrC++;
Update();
}
function incB() {
ctrB++;
Update();
}
// Decrement Buttons
function decA() {
ctrA--;
Update();
}
function decC() {
ctrC--;
Update();
}
function decB() {
ctrB--;
Update();
}
// Buttons States
function disBtn(btn) {
var btn =document.getElementById(btn);
btn.disabled = true;
btn.style.backgroundColor = "#c5c5c5";
}
function enBtn(btn) {
var btn = document.getElementById(btn);
btn.disabled = false;
btn.style.backgroundColor = "#555555";
}
function disAllBtnInc() {
disBtn("incA");
disBtn("incC");
disBtn("incB");
}
function enAllBtnInc() {
enBtn("incA");
enBtn("incC");
enBtn("incB");
}
// Var Rullers
var MAX_PAX = 9;
var MAX_C = 4;
// Logic
function strSP(str,ctr) {
if (ctr > 1 && str.slice(-1) != "s") {
str += "s";
}else if (ctr == 1 && str.slice(-1) == "s") {
str = str.slice(0, -1);
}
return str;
}
function Update() {
strA = strSP(strA, ctrA);
//Button logic
if (ctrA <= 0) {
disBtn("decA");
mainStr = "";
}else {
enBtn("decA");
mainStr = ctrA + strA;
}
strC = strSP(strC, ctrC);
if (ctrC <= 0) {
disBtn("decC");
mainStr += "";
}else {
enBtn("decC");
mainStr +=", " + ctrC + strC;
}
strB = strSP(strB, ctrB);
if (ctrB <= 0) {
disBtn("decB");
mainStr += "";
}else {
enBtn("decB");
mainStr += ", " + ctrB + strB;
}
document.getElementById("n_adultos").innerHTML=ctrA;
document.getElementById("n_criancas").innerHTML=ctrC;
document.getElementById("n_bebes").innerHTML=ctrB;
openTxt.innerText = mainStr;
var totalPax = ctrA + ctrC + ctrB;
if (totalPax >= MAX_PAX) {
disAllBtnInc();
}else {
enAllBtnInc();
}
if (ctrA <= 0) {
disBtn("incC");
disBtn("incB");
ctrC = 0;
ctrB = 0;
Update ();
}
if (ctrC >= (MAX_C * ctrA) && ctrB == 0) {
disBtn("incC");
disBtn("incB");
ctrC = (MAX_C * ctrA);
Update();
}
if (ctrC >= (2 * ctrA) || ctrB >= ctrA) {
disBtn("incB");
}
}