Mercurial Hosting > freedit
comparison src/thread.html.luan @ 34:c8d47981c74f
upload using ajax
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 02 Aug 2022 20:46:02 -0600 |
parents | 4fdc4ec0050b |
children | 1ce75c5ab0f7 |
comparison
equal
deleted
inserted
replaced
33:4fdc4ec0050b | 34:c8d47981c74f |
---|---|
7 local Http = require "luan:http/Http.luan" | 7 local Http = require "luan:http/Http.luan" |
8 local Shared = require "site:/lib/Shared.luan" | 8 local Shared = require "site:/lib/Shared.luan" |
9 local head = Shared.head or error() | 9 local head = Shared.head or error() |
10 local header = Shared.header or error() | 10 local header = Shared.header or error() |
11 local footer = Shared.footer or error() | 11 local footer = Shared.footer or error() |
12 local get_url_from_file = Shared.get_url_from_file or error() | |
13 local Forum = require "site:/lib/Forum.luan" | 12 local Forum = require "site:/lib/Forum.luan" |
14 local forum_title = Forum.title or error() | 13 local forum_title = Forum.title or error() |
15 local Db = require "site:/lib/Db.luan" | 14 local Db = require "site:/lib/Db.luan" |
16 local Post = require "site:/lib/Post.luan" | 15 local Post = require "site:/lib/Post.luan" |
17 local Bbcode = require "site:/lib/Bbcode.luan" | 16 local Bbcode = require "site:/lib/Bbcode.luan" |
80 function saveEdit(src) { | 79 function saveEdit(src) { |
81 let postDiv = getPostDiv(src); | 80 let postDiv = getPostDiv(src); |
82 let post = postDiv.getAttribute('post'); | 81 let post = postDiv.getAttribute('post'); |
83 let text = postDiv.querySelector('textarea').value; | 82 let text = postDiv.querySelector('textarea').value; |
84 let postData = 'post=' + post + '&text=' + encodeURIComponent(text); | 83 let postData = 'post=' + post + '&text=' + encodeURIComponent(text); |
85 ajax("save_edit.js",postData); | 84 ajax('save_edit.js',postData); |
86 } | 85 } |
87 | 86 |
88 function upload(input) { | 87 function gotFile(input) { |
89 let postDiv = getPostDiv(input); | 88 function uploaded(url,filename) { |
90 let post = postDiv.getAttribute('post'); | 89 let postDiv = getPostDiv(input); |
91 let file = input.files[0]; | 90 let textarea = postDiv.querySelector('textarea'); |
92 ajax("/upload_bbcode.js?post="+post,file); | 91 textarea.focus(); |
92 textarea.setRangeText(url,textarea.selectionStart,textarea.selectionEnd,'select'); | |
93 } | |
94 upload(input,uploaded); | |
93 } | 95 } |
94 | 96 |
95 function deletePost(span) { | 97 function deletePost(span) { |
96 span.innerHTML = document.querySelector('[hidden][delete]').innerHTML; | 98 span.innerHTML = document.querySelector('[hidden][delete]').innerHTML; |
97 } | 99 } |
148 <span hidden delete>Delete? <a href="javascript:" onclick="deleteYes(parentNode)">yes</a> / <a href="javascript:" onclick="deleteNo(parentNode)">no</a></span> | 150 <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> | 151 <span hidden undelete><%deletePost()%></span> |
150 <div hidden edit> | 152 <div hidden edit> |
151 <textarea></textarea> | 153 <textarea></textarea> |
152 <p> | 154 <p> |
153 <label clickable | 155 <input type=file onchange="gotFile(this)"> |
154 ><input type=file onchange="upload(this)" | 156 <button onclick="fileButtonClick(this)">Upload File</button> |
155 ><span inline_button>upload</span> | |
156 </label> | |
157 <button onclick="saveEdit(this)">save</button> | 157 <button onclick="saveEdit(this)">save</button> |
158 <button onclick="cancelEdit(this)">cancel</button> | 158 <button onclick="cancelEdit(this)">cancel</button> |
159 </p> | 159 </p> |
160 </div> | 160 </div> |
161 </body> | 161 </body> |