-
Notifications
You must be signed in to change notification settings - Fork 0
/
notepad.html
112 lines (99 loc) · 3.65 KB
/
notepad.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
<html>
<head>
<title>Text Editor</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> -->
<!-- <link rel="stylesheet" href="notepad.css" /> -->
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="css/notepad.css" />
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<!-- <nav>
<div class="nav-wrapper">
<a class="brand-logo center">
Work From Home
</a>
</div>
</nav> -->
<!-- <a class="btn-floating btn-large waves-effect waves-light red"><i class="material-icons">add</i></a>
<div id="heading" contenteditable="false"></div>
<div class="content-wrapper">
<div id="content" contenteditable="true"></div>
<ul class="collection" id="content">
<li class="collection-item" contenteditable="true">Insert here</li>
</ul>
<button class="btn primary">Add Item</button>
</div> -->
<div id="myDIV" class="header">
<!-- <h2>My To Do List</h2> -->
<input type="text" id="myInput" placeholder="Title...">
<!-- <span onclick="newElement()" class="btn primary">Add</span> -->
<a class="btn-floating btn-large waves-effect waves-light red" onclick="newElement()"><i class="material-icons">add</i></a>
</div>
<ul id="myUL">
</ul>
<script>
document.getElementById("myUL").innerHTML = localStorage["list"] || ""; // default text
setInterval(function() {
// fuction that is saving the innerHTML of the div
localStorage["title"] = "List"; // heading div
localStorage["list"] = document.getElementById("myUL").innerHTML; // content div
}, 1000);
// Create a "close" button and append it to each list item
var myNodelist = document.getElementsByTagName("LI");
var i;
for (i = 0; i < myNodelist.length; i++) {
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7");
span.className = "close";
span.appendChild(txt);
myNodelist[i].appendChild(span);
}
// Click on a close button to hide the current list item
var close = document.getElementsByClassName("close");
var i;
for (i = 0; i < close.length; i++) {
close[i].onclick = function() {
var div = this.parentElement;
div.style.display = "none";
}
}
// Add a "checked" symbol when clicking on a list item
var list = document.querySelector('ul');
list.addEventListener('click', function(ev) {
if (ev.target.tagName === 'LI') {
ev.target.classList.toggle('checked');
}
}, false);
// Create a new list item when clicking on the "Add" button
function newElement() {
var li = document.createElement("li");
var inputValue = document.getElementById("myInput").value;
var t = document.createTextNode(inputValue);
li.appendChild(t);
if (inputValue === '') {
alert("You must write something!");
} else {
document.getElementById("myUL").appendChild(li);
}
document.getElementById("myInput").value = "";
var span = document.createElement("SPAN");
var txt = document.createTextNode("\u00D7");
span.className = "close";
span.appendChild(txt);
li.appendChild(span);
for (i = 0; i < close.length; i++) {
close[i].onclick = function() {
var div = this.parentElement;
div.style.display = "none";
}
}
}
</script>
</body>
</html>