Mercurial Hosting > freedit
annotate 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 |
rev | line source |
---|---|
9 | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | |
3 local ipairs = Luan.ipairs or error() | |
18 | 4 local Time = require "luan:Time.luan" |
5 local time_now = Time.now or error() | |
9 | 6 local Io = require "luan:Io.luan" |
7 local Http = require "luan:http/Http.luan" | |
8 local Shared = require "site:/lib/Shared.luan" | |
9 local head = Shared.head or error() | |
10 local header = Shared.header or error() | |
11 local footer = Shared.footer or error() | |
33
4fdc4ec0050b
upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents:
32
diff
changeset
|
12 local get_url_from_file = Shared.get_url_from_file or error() |
9 | 13 local Forum = require "site:/lib/Forum.luan" |
14 local forum_title = Forum.title or error() | |
15 local Db = require "site:/lib/Db.luan" | |
16 local Post = require "site:/lib/Post.luan" | |
12 | 17 local Bbcode = require "site:/lib/Bbcode.luan" |
18 local bbcode_to_html = Bbcode.to_html or error() | |
16 | 19 local User = require "site:/lib/User.luan" |
9 | 20 |
11 | 21 |
16 | 22 local function deletePost() |
23 %><a href="javascript:" onclick="deletePost(parentNode)">delete</a><% | |
24 end | |
25 | |
9 | 26 return function() |
27 local root_id = Http.request.parameters.root or error() | |
28 local docs, total_hits = Db.search("post_root_id:"..root_id,1,1000,{sort="id"}) | |
29 local posts = Post.from_docs(docs) | |
30 local subject_html = posts[1].subject_html | |
16 | 31 local user = User.current() |
32 local user_name = user and user.name | |
18 | 33 local now = time_now() |
9 | 34 Io.stdout = Http.response.text_writer() |
35 %> | |
36 <!doctype html> | |
37 <html> | |
38 <head> | |
39 <% head() %> | |
40 <title><%=forum_title%>: <%=subject_html%></title> | |
41 <style> | |
18 | 42 div[author] { |
43 margin-bottom: 6px; | |
44 font-size: 10px; | |
45 } | |
46 div[author] img { | |
47 width: 28px; | |
48 vertical-align: middle; | |
49 border-radius: 50%; | |
50 } | |
51 div[author] a { | |
52 font-weight: bold; | |
53 } | |
54 span[ago] { | |
55 color: #888; | |
56 } | |
15 | 57 [message] { |
9 | 58 white-space: pre-wrap; |
26 | 59 line-height: 1.4; |
9 | 60 } |
25
66fd3784e60e
back to textarea for bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
21
diff
changeset
|
61 textarea { |
66fd3784e60e
back to textarea for bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
21
diff
changeset
|
62 width: 100%; |
66fd3784e60e
back to textarea for bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
21
diff
changeset
|
63 xmax-width: 450px; |
66fd3784e60e
back to textarea for bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
21
diff
changeset
|
64 height: 100px; |
66fd3784e60e
back to textarea for bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
21
diff
changeset
|
65 } |
66fd3784e60e
back to textarea for bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
21
diff
changeset
|
66 </style> |
15 | 67 <script> |
19 | 68 function getPostDiv(node) { |
69 do { | |
70 if( node.getAttribute('post') ) | |
71 return node; | |
72 } while( node = node.parentNode ); | |
73 } | |
74 | |
32 | 75 function cancelEdit(src) { |
76 let postDiv = getPostDiv(src); | |
15 | 77 postDiv.querySelector('[output]').style.display = 'block'; |
78 postDiv.querySelector('[edit]').innerHTML = ''; | |
79 } | |
32 | 80 function saveEdit(src) { |
81 let postDiv = getPostDiv(src); | |
19 | 82 let post = postDiv.getAttribute('post'); |
25
66fd3784e60e
back to textarea for bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
21
diff
changeset
|
83 let text = postDiv.querySelector('textarea').value; |
15 | 84 let postData = 'post=' + post + '&text=' + encodeURIComponent(text); |
85 ajax("save_edit.js",postData); | |
86 } | |
16 | 87 |
33
4fdc4ec0050b
upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents:
32
diff
changeset
|
88 function upload(input) { |
4fdc4ec0050b
upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents:
32
diff
changeset
|
89 let postDiv = getPostDiv(input); |
4fdc4ec0050b
upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents:
32
diff
changeset
|
90 let post = postDiv.getAttribute('post'); |
4fdc4ec0050b
upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents:
32
diff
changeset
|
91 let file = input.files[0]; |
4fdc4ec0050b
upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents:
32
diff
changeset
|
92 ajax("/upload_bbcode.js?post="+post,file); |
32 | 93 } |
94 | |
16 | 95 function deletePost(span) { |
96 span.innerHTML = document.querySelector('[hidden][delete]').innerHTML; | |
97 } | |
98 function deleteNo(span) { | |
99 span.innerHTML = document.querySelector('[hidden][undelete]').innerHTML; | |
100 } | |
101 function deleteYes(span) { | |
19 | 102 let post = getPostDiv(span).getAttribute('post'); |
16 | 103 ajax( '/delete.js?post=' + post ); |
104 } | |
18 | 105 |
106 function init() { | |
107 let spans = document.querySelectorAll('span[ago]'); | |
108 for( let i=0; i<spans.length; i++ ) { | |
109 let span = spans[i]; | |
110 let date = span.getAttribute('date'); | |
111 date = parseInt(date); | |
112 span.title = new Date(date).toLocaleString(); | |
113 } | |
114 } | |
15 | 115 </script> |
9 | 116 </head> |
18 | 117 <body onload="init()"> |
9 | 118 <% header() %> |
119 <div content> | |
120 <h1><%=subject_html%></h1> | |
16 | 121 <% for _, post in ipairs(posts) do |
122 if post.is_deleted then | |
123 continue | |
124 end | |
125 %> | |
9 | 126 <hr> |
15 | 127 <div post="<%=post.id%>"> |
18 | 128 <div author> |
129 <img src="/images/profile.png"> | |
130 <a href="/whatever"><%= post.author_name %></a> | |
131 <span ago date="<%=post.date%>"><% post.ago(now) %> ago</span> | |
132 </div> | |
15 | 133 <div output> |
134 <% bbcode_to_html(post.content) %> | |
135 <p> | |
136 <a href="/reply.html?parent=<%=post.id%>">reply</a> | |
16 | 137 <% if post.author_name == user_name then %> |
15 | 138 - <a href="javascript:ajax('/edit.js?post=<%=post.id%>')">edit</a> |
19 | 139 - <span delete><%deletePost()%></span> |
16 | 140 <% end %> |
15 | 141 </p> |
142 </div> | |
143 <div edit></div> | |
144 </div> | |
9 | 145 <% end %> |
146 </div> | |
147 <% footer() %> | |
16 | 148 <span hidden delete>Delete? <a href="javascript:" onclick="deleteYes(parentNode)">yes</a> / <a href="javascript:" onclick="deleteNo(parentNode)">no</a></span> |
149 <span hidden undelete><%deletePost()%></span> | |
19 | 150 <div hidden edit> |
25
66fd3784e60e
back to textarea for bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents:
21
diff
changeset
|
151 <textarea></textarea> |
19 | 152 <p> |
33
4fdc4ec0050b
upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents:
32
diff
changeset
|
153 <label clickable |
4fdc4ec0050b
upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents:
32
diff
changeset
|
154 ><input type=file onchange="upload(this)" |
4fdc4ec0050b
upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents:
32
diff
changeset
|
155 ><span inline_button>upload</span> |
4fdc4ec0050b
upload with uploadcare
Franklin Schmidt <fschmidt@gmail.com>
parents:
32
diff
changeset
|
156 </label> |
19 | 157 <button onclick="saveEdit(this)">save</button> |
158 <button onclick="cancelEdit(this)">cancel</button> | |
159 </p> | |
160 </div> | |
9 | 161 </body> |
162 </html> | |
163 <% | |
164 end |