Mercurial Hosting > chat
comparison src/chat.js @ 38:436216d17a1b
fix edit and delete
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Tue, 12 Nov 2024 21:53:03 -0700 |
| parents | 27c41f22d2a9 |
| children | 471b13e6ce2c |
comparison
equal
deleted
inserted
replaced
| 37:cfd1f92c264f | 38:436216d17a1b |
|---|---|
| 94 ajax(`delete_chat.js?chat=${currentChatId}`); | 94 ajax(`delete_chat.js?chat=${currentChatId}`); |
| 95 } | 95 } |
| 96 | 96 |
| 97 let currentPostId; | 97 let currentPostId; |
| 98 | 98 |
| 99 function deletePost(postId) { | 99 function getPostId(el) { |
| 100 currentPostId = postId; | 100 while(true) { |
| 101 let postId = el.getAttribute('post'); | |
| 102 if( postId ) | |
| 103 return postId; | |
| 104 el = el.parentNode; | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 function deletePost(el) { | |
| 109 currentPostId = getPostId(el); | |
| 101 let dialog = document.querySelector('dialog[delete_post]'); | 110 let dialog = document.querySelector('dialog[delete_post]'); |
| 102 openModal(dialog); | 111 openModal(dialog); |
| 103 } | 112 } |
| 104 | 113 |
| 105 function doDeletePost(el) { | 114 function doDeletePost(el) { |
| 111 let div = document.querySelector(`div[post="${postId}"]`); | 120 let div = document.querySelector(`div[post="${postId}"]`); |
| 112 if( div ) | 121 if( div ) |
| 113 div.outerHTML = ''; | 122 div.outerHTML = ''; |
| 114 } | 123 } |
| 115 | 124 |
| 116 function editPost(postId) { | 125 function editPost(el) { |
| 117 ajax(`edit_post.js?post=${postId}`); | 126 ajax(`edit_post.js?post=${getPostId(el)}`); |
| 118 } | 127 } |
| 119 | 128 |
| 120 function openEditPost(postId,text) { | 129 function openEditPost(postId,text) { |
| 121 currentPostId = postId; | 130 currentPostId = postId; |
| 122 let dialog = document.querySelector('dialog[edit_post]'); | 131 let dialog = document.querySelector('dialog[edit_post]'); |
