-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainWindow.html
59 lines (50 loc) · 1.8 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
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="en">
<head>
<title>Shopping List</title>
<!-- MaterializeCSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
</head>
<body>
<nav>
<div class="nav-wrapper">
<a class="brand-logo center">Shopping List</a>
</div>
</nav>
<ul></ul>
<script>
const electron = require("electron");
const {ipcRenderer} = electron;
const ul = document.querySelector("ul");
// Add new item
// Catch 'item:add' value from main.js's ipcMain
ipcRenderer.on('item:add', function(event, item){
// add materialzeCSS collection class to the ul
ul.className = 'collection';
// Create li
const li = document.createElement('li');
// Add collection-item CSS class to the li
li.className = 'collection-item';
const itemText = document.createTextNode(item); // creat TextNode
li.appendChild(itemText); // Add TextNode to li
ul.appendChild(li); // Add li to the ul
});
// Clear items => Catch 'item:clear'
ipcRenderer.on('item:clear', function(){
ul.innerHTML = '';
// remove css class applied on ul when there are no list items
ul.className = '';
});
// Remove the double clicked item
ul.addEventListener('dblclick', removeItem);
function removeItem(event){
// Remove the double clicked item from DOM
event.target.remove();
// If there are no li's, clear out collection css class in ul
if(ul.children.length === 0){
ul.className = '';
}
}
</script>
</body>
</html>