comparison src/chat.js @ 24:af41be2dcdec

add edit_post
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 05 Nov 2024 19:45:08 -0700
parents c54c806fcc6e
children 809193524522
comparison
equal deleted inserted replaced
23:c54c806fcc6e 24:af41be2dcdec
48 function addPost() { 48 function addPost() {
49 let textarea = document.querySelector('div[input] textarea'); 49 let textarea = document.querySelector('div[input] textarea');
50 let text = textarea.value; 50 let text = textarea.value;
51 if( text.trim() === '' ) 51 if( text.trim() === '' )
52 return; 52 return;
53 ajax(`add_post.js?chat=${currentChatId}&content=${encodeURIComponent(text)}`); 53 ajax(`add_post.js?chat=${currentChatId}`,`content=${encodeURIComponent(text)}`);
54 textarea.value = ''; 54 textarea.value = '';
55 } 55 }
56 56
57 function textareaKey(event) { 57 function textareaKey(event) {
58 if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) { 58 if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) {
99 99
100 function deleted(postId) { 100 function deleted(postId) {
101 let div = document.querySelector(`div[post="${postId}"]`); 101 let div = document.querySelector(`div[post="${postId}"]`);
102 if( div ) 102 if( div )
103 div.outerHTML = ''; 103 div.outerHTML = '';
104 }
105
106 function editPost(postId) {
107 ajax(`edit_post.js?post=${postId}`);
108 }
109
110 function openEditPost(postId,text) {
111 currentPostId = postId;
112 let dialog = document.querySelector('dialog[edit_post]');
113 let textarea = dialog.querySelector('textarea');
114 textarea.value = text;
115 openModal(dialog);
116 }
117
118 function savePost(el) {
119 let text = document.querySelector('dialog[edit_post] textarea').value;
120 closeModal(el);
121 ajax(`save_post.js?post=${currentPostId}`,`content=${encodeURIComponent(text)}`);
122 }
123
124 function edited(postId,html) {
125 let div = document.querySelector(`div[post="${postId}"]`);
126 if( div ) {
127 div.outerHTML = html;
128 fixPosts();
129 }
104 } 130 }
105 131
106 function added(html) { 132 function added(html) {
107 let input = document.querySelector('div[input]'); 133 let input = document.querySelector('div[input]');
108 input.insertAdjacentHTML('beforebegin',html); 134 input.insertAdjacentHTML('beforebegin',html);