update todo.html - keep it simple

This commit is contained in:
estebanrfp 2020-04-07 18:55:57 +02:00
parent ce78d7a4c9
commit 60a62d867c

View File

@ -1,53 +1,60 @@
<html> <html>
<body> <body>
<h1>Thoughts</h1> <h1>Thoughts</h1>
<form id="form"> <form id="form">
<input id="input"> <input id="input">
<button>Add</button> <button>Add</button>
</form> </form>
<ul id="parentList"></ul> <ul id="parentList"></ul>
<!-- <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script> <script src="../../../gun/gun.js"></script>
<link href="style.css" rel="stylesheet">
<script> <script>
var gun = Gun().get('thoughts'); const gun = Gun().get('thoughts')
document.getElementById('form').addEventListener('submit', function (e) {
e.preventDefault(); // attaches event listener and prevent default form action const parentList = document.getElementById('parentList')
var data = document.getElementById('input').value; const input = document.getElementById('input')
gun.set(data);
document.getElementById('input').value = ""; const dynamicEvent = e => {
}); const target = e.target
gun.map().on(function (thought, id) {
var li = document.getElementById(id) || document.getElementById('parentList').insertAdjacentHTML('beforeend', '<li id =' + id + '> ' + thought + '</li>'); gun.get(target.id).put(null)
var $ = function (selector) {
return document.querySelector(selector); target.innerHTML = document.getElementById(target.innerHTML)
};
// attach the event listener to the selected li items if (target.innerHTML === ' null' || target.innerHTML === ' ' || target.innerHTML === '') {
var links = $('#parentList').getElementsByTagName('li'); target.style.display = 'none'
for (var i = 0; i < links.length; i++) { } else {
var link = links[i]; target.style.display = 'list-item'
// console.log(link.innerHTML); }
link.ondblclick = dynamicEvent; }
if (link.innerHTML === " null" || link.innerHTML === " " || link.innerHTML === "") {
link.style.display = "none"; gun.map().on((thought, id) => {
} else { parentList.insertAdjacentHTML('beforeend', `<li id =${id}> ${thought}</li>`)
link.style.display = "list-item";
}; const links = parentList.getElementsByTagName('li')
};
}); for (const link of links) {
function dynamicEvent() { if (link.innerHTML === ' null' || link.innerHTML === ' ' || link.innerHTML === '') {
gun.get(this.id).put(null); link.style.display = 'none'
this.innerHTML = document.getElementById(this.id.innerHTML); } else {
if (this.innerHTML === " null" || this.innerHTML === " " || this.innerHTML === "") { link.style.display = 'list-item'
this.style.display = "none"; }
} else { link.ondblclick = dynamicEvent
this.style.display = "list-item"; }
}; })
};
</script> document.getElementById('form').addEventListener('submit', e => {
e.preventDefault()
const data = input.value
gun.set(data)
input.value = ''
})
</script>
</body> </body>
</html> </html>