annotate src/edit.js.luan @ 61:389e5d8e5f8a default tip

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 06 Dec 2022 13:37:25 -0700
parents 8b5b1bce7d6b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Html = require "luan:Html.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local html_encode = Html.encode or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Parsers = require "luan:Parsers.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local json_string = Parsers.json_string or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Io = require "luan:Io.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Http = require "luan:http/Http.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Post = require "site:/lib/Post.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 return function()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local post = Http.request.parameters.post or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 post = Post.get_by_id(post) or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 Io.stdout = Http.response.text_writer()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 %>
33
4fdc4ec0050b upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
17 let postDiv = document.querySelector('[post="<%=post.id%>"]');
4fdc4ec0050b upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
18 postDiv.querySelector('[output]').style.display = 'none';
46
289718f121e4 use bbcode editor
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
19 bbcodeCreate( postDiv.querySelector('[edit]'), {
289718f121e4 use bbcode editor
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
20 content: <%= json_string(html_encode(post.content)) %>,
60
8b5b1bce7d6b bcode menus
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
21 buttons: {
8b5b1bce7d6b bcode menus
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
22 Save: saveEdit,
8b5b1bce7d6b bcode menus
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
23 Cancel: cancelEdit,
8b5b1bce7d6b bcode menus
Franklin Schmidt <fschmidt@gmail.com>
parents: 46
diff changeset
24 }
46
289718f121e4 use bbcode editor
Franklin Schmidt <fschmidt@gmail.com>
parents: 42
diff changeset
25 } );
33
4fdc4ec0050b upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
26 let textarea = postDiv.querySelector('textarea');
4fdc4ec0050b upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents: 25
diff changeset
27 textarea.focus();
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 <%
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 end