+indentation

This commit is contained in:
estebanrfp 2020-04-07 19:17:00 +02:00
parent 60a62d867c
commit 964b1c9fcf

View File

@ -1,60 +1,57 @@
<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="../../../gun/gun.js"></script> <script src="../../../gun/gun.js"></script>
<script> <script>
const gun = Gun().get('thoughts') const gun = Gun().get('thoughts')
const parentList = document.getElementById('parentList') const parentList = document.getElementById('parentList')
const input = document.getElementById('input') const input = document.getElementById('input')
const dynamicEvent = e => { const dynamicEvent = e => {
const target = e.target const target = e.target
gun.get(target.id).put(null) gun.get(target.id).put(null)
target.innerHTML = document.getElementById(target.innerHTML) target.innerHTML = document.getElementById(target.innerHTML)
if (target.innerHTML === ' null' || target.innerHTML === ' ' || target.innerHTML === '') { if (target.innerHTML === ' null' || target.innerHTML === ' ' || target.innerHTML === '') {
target.style.display = 'none' target.style.display = 'none'
} else { } else {
target.style.display = 'list-item' target.style.display = 'list-item'
} }
} }
gun.map().on((thought, id) => { gun.map().on((thought, id) => {
parentList.insertAdjacentHTML('beforeend', `<li id =${id}> ${thought}</li>`) parentList.insertAdjacentHTML('beforeend', `<li id =${id}> ${thought}</li>`)
const links = parentList.getElementsByTagName('li') const links = parentList.getElementsByTagName('li')
for (const link of links) { for (const link of links) {
if (link.innerHTML === ' null' || link.innerHTML === ' ' || link.innerHTML === '') { if (link.innerHTML === ' null' || link.innerHTML === ' ' || link.innerHTML === '') {
link.style.display = 'none' link.style.display = 'none'
} else { } else {
link.style.display = 'list-item' link.style.display = 'list-item'
} }
link.ondblclick = dynamicEvent link.ondblclick = dynamicEvent
} }
}) })
document.getElementById('form').addEventListener('submit', e => { document.getElementById('form').addEventListener('submit', e => {
e.preventDefault() e.preventDefault()
const data = input.value const data = input.value
gun.set(data) gun.set(data)
input.value = '' input.value = ''
}) })
</script>
</script>
</body> </body>
</html> </html>