diff src/thread.html.luan @ 33:4fdc4ec0050b

upload with uploadcare
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 01 Aug 2022 22:50:16 -0600
parents 72a1b77b4548
children c8d47981c74f
line wrap: on
line diff
--- a/src/thread.html.luan	Fri Jul 29 13:57:20 2022 -0600
+++ b/src/thread.html.luan	Mon Aug 01 22:50:16 2022 -0600
@@ -9,6 +9,7 @@
 local head = Shared.head or error()
 local header = Shared.header or error()
 local footer = Shared.footer or error()
+local get_url_from_file = Shared.get_url_from_file or error()
 local Forum = require "site:/lib/Forum.luan"
 local forum_title = Forum.title or error()
 local Db = require "site:/lib/Db.luan"
@@ -84,11 +85,11 @@
 				ajax("save_edit.js",postData);
 			}
 
-			function upload(src) {
-				let postDiv = getPostDiv(src);
-				let textarea = postDiv.querySelector('textarea');
-				textarea.focus();
-				textarea.setRangeText('xyz',textarea.selectionStart,textarea.selectionEnd,'select');
+			function upload(input) {
+				let postDiv = getPostDiv(input);
+				let post = postDiv.getAttribute('post');
+				let file = input.files[0];
+				ajax("/upload_bbcode.js?post="+post,file);
 			}
 
 			function deletePost(span) {
@@ -149,7 +150,10 @@
 		<div hidden edit>
 			<textarea></textarea>
 			<p>
-				<button onclick="upload(this)">upload</button>
+				<label clickable
+					><input type=file onchange="upload(this)"
+					><span inline_button>upload</span>
+				</label>
 				<button onclick="saveEdit(this)">save</button>
 				<button onclick="cancelEdit(this)">cancel</button>
 			</p>