Skip to content

Commit

Permalink
Merge pull request #28 from haidarrifki/master
Browse files Browse the repository at this point in the history
Add example todo list
  • Loading branch information
JLambertazzo committed Oct 17, 2021
2 parents 167f975 + e5a1bcd commit 60c8315
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,36 @@ <h3>It's easy to get items from the list!</h3>
</code>
</details>
</div>
<div class="card" id="markedLists">
<h3>Make a simple completed todo list!</h3>
<p>The items that you can set complete.</p>
<details>
<summary>Source Code</summary>
<code>
<pre>const markedLists = new ListExtender({ showDeleteButton: true })</pre>
<pre>markedLists.addAfter('#markedLists p')</pre>
<pre>const dataMarkedList = ['bug fixing', 'implement new feature']</pre>
<pre>markedLists.addFromArray(dataMarkedList)</pre>
<pre>markedLists.element.addEventListener('mouseenter', event => {</pre>
<pre> const children = [...markedLists.element.children]</pre>
<pre> children.forEach(child => {</pre>
<pre> if (child.querySelector('input[type="submit"]')) {</pre>
<pre> child.querySelector('input[type="submit"]').value = 'DONE'</pre>
<pre> child.querySelector('input[type="submit"]').style.visibility = 'visible'</pre>
<pre> child.querySelector('input[type="submit"]').style.background = 'green'</pre>
<pre> }</pre>
<pre> })</pre>
<pre>})</pre>
<pre>markedLists.element.addEventListener('mousedown', event => {</pre>
<pre> if (event.target.tagName === 'INPUT' && event.target.getAttribute('type') === 'submit') { </pre>
<pre> let ulElement = event.target.parentElement</pre>
<pre> markedLists.element.insertBefore(ulElement, markedLists.element.children[0])</pre>
<pre> ulElement.style['text-decoration'] = 'line-through'</pre>
<pre> }</pre>
<pre>})</pre>
</code>
</details>
</div>
</div>
</body>
</html>
24 changes: 24 additions & 0 deletions js/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,27 @@ const handleGetItems = event => {
const data = getItems.getData()
p.appendChild(document.createTextNode(`The items given in the list are: ${data.toString()}`))
}

const markedLists = new ListExtender({ showDeleteButton: true })
markedLists.addAfter('#markedLists p')
const dataMarkedList = ['bug fixing', 'implement new feature']
markedLists.addFromArray(dataMarkedList)
markedLists.element.addEventListener('mouseenter', event => {
const children = [...markedLists.element.children]
children.forEach(child => {
if (child.querySelector('input[type="submit"]')) {
child.querySelector('input[type="submit"]').value = 'DONE'
child.querySelector('input[type="submit"]').style.visibility = 'visible'
child.querySelector('input[type="submit"]').style.background = 'green'
}
})
})
markedLists.element.addEventListener('mousedown', event => {
if (event.target.tagName === 'INPUT' && event.target.getAttribute('type') === 'submit') {
let ulElement = event.target.parentElement
// let index = parseInt(ulElement.attributes[0].value) === 1 ? 0 : ulElement.attributes[0].value
// console.log(index)
markedLists.element.insertBefore(ulElement, markedLists.element.children[0])
ulElement.style['text-decoration'] = 'line-through'
}
})

0 comments on commit 60c8315

Please sign in to comment.