diff src/edit.js.luan @ 19:da006d1c1eba

use contentEditable
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 13 Jul 2022 08:47:13 -0600
parents 94e26bffd4fb
children 66fd3784e60e
line wrap: on
line diff
--- a/src/edit.js.luan	Mon Jul 11 12:14:05 2022 -0600
+++ b/src/edit.js.luan	Wed Jul 13 08:47:13 2022 -0600
@@ -5,30 +5,20 @@
 local Parsers = require "luan:Parsers.luan"
 local json_string = Parsers.json_string or error()
 local Io = require "luan:Io.luan"
-local output_of = Io.output_of or error()
 local Http = require "luan:http/Http.luan"
 local Post = require "site:/lib/Post.luan"
 
 
-local function form(post)
-%>
-					<p><textarea name=content><%=html_encode(post.content)%></textarea></p>
-					<p>
-						<a href="javascript:saveEdit('<%= post.id %>')">save</a>
-						<a href="javascript:cancelEdit('<%= post.id %>')">cancel</a>
-					</p>
-<%
-end
-
 return function()
 	local post = Http.request.parameters.post or error()
 	post = Post.get_by_id(post) or error()
-	local html = output_of(function() form(post) end)
 	Io.stdout = Http.response.text_writer()
 %>
 let postDiv = document.querySelector('[post="<%=post.id%>"]');
 postDiv.querySelector('[output]').style.display = 'none';
-postDiv.querySelector('[edit]').innerHTML = <%= json_string(html) %>;
-postDiv.querySelector('textarea').focus();
+postDiv.querySelector('[edit]').innerHTML = document.querySelector('[hidden][edit]').innerHTML;
+let contentEditable = postDiv.querySelector('[contentEditable]');
+contentEditable.innerHTML = <%= json_string(html_encode(post.content)) %>;
+contentEditable.focus();
 <%
 end