(text = '')
| 16 | } |
| 17 | |
| 18 | const addNewNote = (text = '') =>{ |
| 19 | |
| 20 | const note = document.createElement('div'); |
| 21 | note.classList.add('note'); |
| 22 | |
| 23 | const htmlData =` |
| 24 | <div class="operation"> |
| 25 | <button class="edit"><i class="fas fa-edit"></i></button> |
| 26 | <button class="delete"><i class="fas fa-trash-alt"></i></i></button> |
| 27 | </div> |
| 28 | |
| 29 | <div class="main ${text ? "" : "hidden"}"></div> |
| 30 | <textarea class="" ${text ? "hidden" : ""}></textarea> `; |
| 31 | |
| 32 | note.insertAdjacentHTML('afterbegin',htmlData); |
| 33 | console.log(note); |
| 34 | |
| 35 | const editButton = note.querySelector('.edit'); |
| 36 | const delButton = note.querySelector('.delete'); |
| 37 | const maindiv = note.querySelector('.main'); |
| 38 | const textArea = note.querySelector('textarea'); |
| 39 | |
| 40 | // deleting note |
| 41 | delButton.addEventListener('click', () =>{ |
| 42 | note.remove(); |
| 43 | updateLSData(); |
| 44 | }); |
| 45 | |
| 46 | // edit button |
| 47 | textArea.value = text; |
| 48 | maindiv.innerHTML = text; |
| 49 | |
| 50 | |
| 51 | editButton.addEventListener('click', () =>{ |
| 52 | maindiv.classList.toggle('hidden'); |
| 53 | textArea.classList.toggle('hidden'); |
| 54 | }) |
| 55 | |
| 56 | textArea.addEventListener('change', (event) => { |
| 57 | const value = event.target.value; |
| 58 | // console.log(value); |
| 59 | maindiv.innerHTML = value; |
| 60 | |
| 61 | updateLSData(); |
| 62 | }) |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | document.body.appendChild(note); |
| 68 | |
| 69 | } |
| 70 | |
| 71 | // gettin json data |
| 72 |
no test coverage detected