-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
261 lines (232 loc) · 10.2 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Positive Things Tracker</title>
<style>
.container {
display: flex;
justify-content: space-between;
border: 1px solid #000;
padding: 10px;
margin-top: 20px;
}
.left, .right {
flex: 1;
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.circle {
width: 60px;
height: 60px;
background-color: green;
border-radius: 50%;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
color: white;
position: relative;
}
.circle::before {
content: '★'; /* Star character */
font-size: 54px; /* Slightly smaller than the circle */
color: white;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
/*line-height: 60px; */ /* Same as the circle's height to center vertically */
/* text-align: center; */
/* display: block; */
}
/* New styles for yellow stars in right circles */
#right .circle::before {
color: orange; /* Change star color to yellow for right circles */
}
/* Right circles adjustments */
#right .circle::/*before*/ after {
content: attr(data-number); /* '★'; */ /* Dynamic content for number and star */
color: darkblue; /* number color */
font-family: Arial, sans-serif; /* Ensures consistent font styling */
font-size: 18px; /* Adjusts number size */
position: absolute;
/*top: 50%;
left: 50%;
transform: translate(-50%, -50%); */
z-index: 2; /* Makes sure the number appears above the star */
/* text-align: center;
display: block;
line-height: 60px; */
}
#right .circle {
display: flex;
color: darkblue; /* Number color inside the star */
/*font-size: 18px; */ /* Adjusts number size */
justify-content: center; /* Ensures content is centered */
align-items: center; /* Ensures vertical alignment */
/* position: relative;
} */
.hidden {
display: none;
}
.description-container {
display: flex;
flex-direction: column;
align-items: center;
background: white;
padding: 10px;
border: 1px solid #000;
border-radius: 5px;
position: absolute;
z-index: 1;
/*left: 50%;
transform: translateX(-50%);
bottom: calc(100% + 10px);*/
}
.description-container input {
margin-top: 10px;
padding: 5px;
}
.description-container button {
margin-top: 5px;
padding: 5px 10px;
background-color: green;
color: white;
border: none;
cursor: pointer;
}
#descriptionTable th, #descriptionTable td {
font-size: larger; /* Adjusts the font size */
}
</style>
</head>
<body>
<h1>Notice Positive Things</h1>
<label for="numCircles">Enter a number (3-33):</label>
<input type="number" id="numCircles" name="numCircles" min="3" max="33">
<button onclick="generateCircles()">Generate</button>
<div id="box" class="container hidden">
<div id="left" class="left"></div>
<div id="right" class="right"></div>
</div>
<div id="congrats" class="hidden">
<h2>Congratulations! You noticed all the positive things today!</h2>
</div>
<table id="descriptionTable" border="1" style="width:100%; margin-top: 20px;">
<tr>
<th>Positive things you noticed today</th>
</tr>
</table>
<script>
let currentDescriptionContainer = null;
function generateCircles() {
//const numCircles = document.getElementById('numCircles').value;
const numCircles = parseInt(document.getElementById('numCircles').value, 10); // Ensure value is treated as a number
const leftContainer = document.getElementById('left');
const rightContainer = document.getElementById('right');
const box = document.getElementById('box');
const congrats = document.getElementById('congrats');
// Reset previous content
leftContainer.innerHTML = '';
rightContainer.innerHTML = '';
box.classList.add('hidden');
congrats.classList.add('hidden');
if (numCircles >= 3 && numCircles <= 33) {
for (let i = 0; i < numCircles; i++) {
const circle = document.createElement('div');
circle.classList.add('circle');
//circle.textContent = i + 1;
//circle.innerHTML = '★'; // Sets the content to a white star
//circle.style.color = 'white'; // Changes the text color to white
//circle.style.fontSize = '24px'; // Adjusts the font size to fit the star
circle.setAttribute("data-number", i + 1); // This stores the number as data-number attribute
circle.addEventListener('click', () => describePositiveThing(circle));
leftContainer.appendChild(circle);
}
box.classList.remove('hidden');
}
}
function describePositiveThing(circle) {
// Close any currently open description container
if (currentDescriptionContainer) {
document.body.removeChild(currentDescriptionContainer);
}
const descriptionContainer = document.createElement('div');
descriptionContainer.classList.add('description-container');
const input = document.createElement('input');
input.type = 'text';
input.placeholder = 'Describe a positive thing';
const buttonOk = document.createElement('button');
buttonOk.textContent = 'OK';
buttonOk.disabled = true; // Initially disable the OK button
buttonOk.addEventListener('click', () => moveCircleToRight(circle, descriptionContainer));
const buttonClose = document.createElement('button');
buttonClose.textContent = 'Close';
buttonClose.addEventListener('click', () => {
document.body.removeChild(descriptionContainer);
circle.addEventListener('click', () => describePositiveThing(circle));
});
// Enable OK button only when input is not empty
input.addEventListener('input', () => {
buttonOk.disabled = input.value.trim() === '';
});
input.addEventListener('keypress', function(event) {
if (event.key === 'Enter' && input.value.trim() !== '') {
moveCircleToRight(circle, descriptionContainer);
}
});
descriptionContainer.appendChild(input);
descriptionContainer.appendChild(buttonOk);
descriptionContainer.appendChild(buttonClose);
// Append the description container to the body and position it
document.body.appendChild(descriptionContainer);
const rect = circle.getBoundingClientRect();
descriptionContainer.style.top = `${rect.bottom + window.scrollY}px`;
descriptionContainer.style.left = `${rect.left + window.scrollX}px`;
// Focus the cursor on the input field
input.focus();
// Update current description container
currentDescriptionContainer = descriptionContainer;
// Remove event listener to avoid multiple clicks
circle.removeEventListener('click', () => describePositiveThing(circle));
}
function moveCircleToRight(circle, descriptionContainer) {
const rightContainer = document.getElementById('right');
const leftContainer = document.getElementById('left');
const input = descriptionContainer.querySelector('input');
if (input.value.trim() !== '') {
const description = input.value;
//circle.innerHTML = circle.getAttribute("data-number");
//circle.textContent = document.getElementById('right').children.length + 1;
const newIndex = document.getElementById('right').children.length + 1;
circle.setAttribute('data-number', newIndex); // Set the data-number attribute
circle.innerHTML = ''; // Clears any existing content, necessary only if other content might be set elsewhere
document.body.removeChild(descriptionContainer); // Remove the description container from the DOM
// Move circle to the right container
rightContainer.appendChild(circle);
// Add description to the table with numbering
const table = document.getElementById('descriptionTable');
const rowCount = table.rows.length;
const row = table.insertRow();
const cell1 = row.insertCell(0);
cell1.innerHTML = rowCount + '. ' + description;
// Update the font size
cell1.style.fontSize = 'larger';
if (leftContainer.childElementCount === 0) {
document.getElementById('congrats').classList.remove('hidden');
}
// Reset current description container
currentDescriptionContainer = null;
}
}
document.getElementById('numCircles').addEventListener('keypress', function(event) {
if (event.key === 'Enter') {
generateCircles();
}
});
</script>
</body>
</html>