-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (78 loc) · 3.29 KB
/
Copy pathscript.js
File metadata and controls
90 lines (78 loc) · 3.29 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
// HVAC Tool & Parts Checklist
const itemInput = document.getElementById('item-input');
const addItemBtn = document.getElementById('add-item-btn');
const checklist = document.getElementById('checklist');
const checklistStatus = document.getElementById('checklist-status');
const clearListBtn = document.getElementById('clear-list-btn');
/**
* Purpose: Keep the status line in sync with the current state of the
* checklist — either an empty-state message or a live item count.
* Inputs: None directly — reads the current `<li>` children of `checklist`.
* Outputs: Updates the text content of `checklistStatus`. Returns nothing.
* Flow: Count all `<li>` items and how many have the "checked" class.
* If there are no items, show the empty-state message. Otherwise show
* "N items · N packed · N remaining".
*/
function updateChecklistStatus() {
const items = checklist.querySelectorAll('li');
const total = items.length;
checklistStatus.classList.toggle('empty', total === 0);
if (total === 0) {
checklistStatus.textContent = 'No items yet — add a tool or part above.';
return;
}
const packed = checklist.querySelectorAll('li.checked').length;
const remaining = total - packed;
checklistStatus.textContent = `${total} items · ${packed} packed · ${remaining} remaining`;
}
/**
* Purpose: Add whatever the tech typed into the checklist as a new item.
* Inputs: None directly — reads the current value of `itemInput`.
* Outputs: Appends a new checkable `<li>` to `checklist`; clears and
* refocuses `itemInput`. Returns nothing.
* Flow: Trim the input, bail out on empty input, create the `<li>`,
* attach its click-to-check-off listener, append it to the list,
* then reset the input for the next entry.
*/
function addItem() {
const value = itemInput.value.trim();
if (!value) return;
const li = document.createElement('li');
li.textContent = value;
// Purpose: let a tech mark this item as packed/confirmed by clicking it.
// Inputs: click event on this specific <li>.
// Outputs: toggles the "checked" class on this <li> (strikethrough via CSS).
// Flow: each new <li> gets its own listener, so items toggle independently.
li.addEventListener('click', () => {
li.classList.toggle('checked');
updateChecklistStatus();
});
checklist.appendChild(li);
itemInput.value = '';
itemInput.focus();
updateChecklistStatus();
}
/**
* Purpose: Let a tech wipe the current checklist to start a new job,
* after confirming they actually want to.
* Inputs: None directly — reads user response from the browser's
* native confirm() dialog.
* Outputs: If confirmed, removes all `<li>` children from `checklist`
* and resets `checklistStatus` back to the empty state. If
* cancelled, nothing changes. Returns nothing.
* Flow: Show a confirm() dialog. If the user cancels, bail out. If
* confirmed, clear the list's contents and call
* updateChecklistStatus() to reset the status line.
*/
function clearList() {
const confirmed = confirm('Clear all items?');
if (!confirmed) return;
checklist.innerHTML = '';
updateChecklistStatus();
}
addItemBtn.addEventListener('click', addItem);
itemInput.addEventListener('keydown', (e) => {
if (e.key === 'Enter') addItem();
});
clearListBtn.addEventListener('click', clearList);
updateChecklistStatus();