comparison src/thread.html.luan @ 46:289718f121e4

use bbcode editor
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 14 Nov 2022 18:43:38 -0700
parents 96f0c3d65698
children f225e82b2bf8
comparison
equal deleted inserted replaced
45:2d4f00755092 46:289718f121e4
34 <html> 34 <html>
35 <head> 35 <head>
36 <% head() %> 36 <% head() %>
37 <title><%=forum_title%>: <%=subject_html%></title> 37 <title><%=forum_title%>: <%=subject_html%></title>
38 <style> 38 <style>
39 @import "/bbcode/bbcode.css";
40
39 div[author] { 41 div[author] {
40 margin-bottom: 6px; 42 margin-bottom: 6px;
41 font-size: 10px; 43 font-size: 10px;
42 } 44 }
43 div[author] img { 45 div[author] img {
52 color: #888; 54 color: #888;
53 } 55 }
54 [message] { 56 [message] {
55 white-space: pre-wrap; 57 white-space: pre-wrap;
56 line-height: 1.4; 58 line-height: 1.4;
57 }
58 textarea {
59 width: 100%;
60 xmax-width: 450px;
61 xheight: 100px;
62 } 59 }
63 <% if user_name == nil then %> 60 <% if user_name == nil then %>
64 [logged_in] { 61 [logged_in] {
65 display: none; 62 display: none;
66 } 63 }
78 } 75 }
79 body[thread_size="1"] div[post]:first-of-type [delete_opton] { 76 body[thread_size="1"] div[post]:first-of-type [delete_opton] {
80 display: initial; 77 display: initial;
81 } 78 }
82 </style> 79 </style>
80 <script src="/bbcode/bbcode.js"></script>
83 <script> 81 <script>
84 function getPostDiv(node) { 82 function getPostDiv(node) {
85 do { 83 do {
86 if( node.getAttribute('post') ) 84 if( node.getAttribute('post') )
87 return node; 85 return node;
88 } while( node = node.parentNode ); 86 } while( node = node.parentNode );
89 } 87 }
90 88
91 function cancelEdit(src) { 89 function cancelEdit(event) {
92 let postDiv = getPostDiv(src); 90 let postDiv = getPostDiv(event.target);
93 postDiv.querySelector('[output]').style.display = 'block'; 91 postDiv.querySelector('[output]').style.display = 'block';
94 postDiv.querySelector('[edit]').innerHTML = ''; 92 postDiv.querySelector('[edit]').innerHTML = '';
95 } 93 }
96 function saveEdit(src) { 94 function saveEdit(event) {
97 let postDiv = getPostDiv(src); 95 let postDiv = getPostDiv(event.target);
98 let post = postDiv.getAttribute('post'); 96 let post = postDiv.getAttribute('post');
99 let text = postDiv.querySelector('textarea').value; 97 let text = postDiv.querySelector('textarea').value;
100 cancelEdit(src); 98 cancelEdit(event);
101 let postData = 'post=' + post + '&text=' + encodeURIComponent(text); 99 let postData = 'post=' + post + '&text=' + encodeURIComponent(text);
102 ajax('save_edit.js',postData); 100 ajax('save_edit.js',postData);
103 } 101 }
104 function updated(postId,html) { 102 function updated(postId,html) {
105 let postDiv = document.querySelector('[post="'+postId+'"]'); 103 let postDiv = document.querySelector('[post="'+postId+'"]');
139 function deleteYes(span) { 137 function deleteYes(span) {
140 let post = getPostDiv(span).getAttribute('post'); 138 let post = getPostDiv(span).getAttribute('post');
141 ajax( '/delete.js?post=' + post ); 139 ajax( '/delete.js?post=' + post );
142 } 140 }
143 function deleted(postId,thread_size) { 141 function deleted(postId,thread_size) {
142 if( thread_size === 0 ) {
143 location = '/';
144 return;
145 }
144 let postDiv = document.querySelector('[post="'+postId+'"]'); 146 let postDiv = document.querySelector('[post="'+postId+'"]');
145 if(!postDiv) 147 if(!postDiv)
146 return 148 return
147 postDiv.outerHTML = ''; 149 postDiv.outerHTML = '';
148 document.body.setAttribute('thread_size',thread_size); 150 document.body.setAttribute('thread_size',thread_size);
171 <% for _, post in ipairs(posts) do 173 <% for _, post in ipairs(posts) do
172 show_post(post,now) 174 show_post(post,now)
173 end %> 175 end %>
174 <div post=new logged_in> 176 <div post=new logged_in>
175 <hr> 177 <hr>
176 <textarea oninput="fixTextarea(this)"></textarea> 178 <div editor></div>
177 <p>
178 <input type=file onchange="upload(this,uploaded)">
179 <button onclick="fileButtonClick(this)">Upload File</button>
180 <button onclick="newPost()">save</button>
181 </p>
182 </div> 179 </div>
183 </div> 180 </div>
184 <% footer() %> 181 <% footer() %>
185 182
186 <span hidden delete>Delete? <a href="javascript:" onclick="deleteYes(parentNode)">yes</a> / <a href="javascript:" onclick="deleteNo(parentNode)">no</a></span> 183 <span hidden delete>Delete? <a href="javascript:" onclick="deleteYes(parentNode)">yes</a> / <a href="javascript:" onclick="deleteNo(parentNode)">no</a></span>
187 <span hidden undelete><%delete_post()%></span> 184 <span hidden undelete><%delete_post()%></span>
188 <div hidden edit>
189 <textarea oninput="fixTextarea(this)"></textarea>
190 <p>
191 <input type=file onchange="upload(this,uploaded)">
192 <button onclick="fileButtonClick(this)">Upload File</button>
193 <button onclick="saveEdit(this)">save</button>
194 <button onclick="cancelEdit(this)">cancel</button>
195 </p>
196 </div>
197 </body> 185 </body>
186 <script>
187 bbcodeCreate('div[post="new"] div[editor]',{
188 save: newPost
189 });
190 </script>
198 </html> 191 </html>
199 <% 192 <%
200 end 193 end