-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainWindow.html
47 lines (43 loc) · 1.27 KB
/
mainWindow.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>ShoppingList</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
</head>
<body>
<nav>
<div class="nav-wrapper">
<a class="brand-logo center">ShoppingList</a>
</div>
</nav>
<ul></ul>
</body>
<script>
const electron = require('electron');
const {ipcRenderer} = electron;
const ul = document.querySelector('ul');
// Handle Add Item menu action
ipcRenderer.on('item:add', (event, item) => {
ul.className = 'collection';
const li = document.createElement('li');
li.className = 'collection-item';
const text = document.createTextNode(item);
li.appendChild(text);
ul.appendChild(li);
});
// Handle Clear Items menu action
ipcRenderer.on('item:clear', ( ) => {
ul.innerHTML = '';
ul.className = '';
});
// Handle remove single item with double-click on list item
ul.addEventListener('dblclick', removeItem);
function removeItem(event) {
event.target.remove(); // event.target -> list item
if (ul.childElementCount == 0) {
ul.className = '';
}
}
</script>
</html>