aboutsummaryrefslogtreecommitdiffstats
path: root/internal/web/templates/partials/editor.html
diff options
context:
space:
mode:
Diffstat (limited to 'internal/web/templates/partials/editor.html')
-rw-r--r--internal/web/templates/partials/editor.html18
1 files changed, 11 insertions, 7 deletions
diff --git a/internal/web/templates/partials/editor.html b/internal/web/templates/partials/editor.html
index eb2e315..4371624 100644
--- a/internal/web/templates/partials/editor.html
+++ b/internal/web/templates/partials/editor.html
@@ -1,9 +1,9 @@
{{define "editor"}}<textarea name="{{.name}}" id="ed-{{.name}}" rows="{{.rows}}"{{if .tall}} class="editor"{{end}}>{{.value}}</textarea>
<div class="editor-tools">
- <label class="upload">{{t "Insert image"}} <input type="file" name="inline_image" id="ed-{{.name}}-file" accept="image/*"></label>
+ <label class="upload">{{t "Insert file"}} <input type="file" name="inline_file" id="ed-{{.name}}-file"></label>
<span class="upload-status" id="ed-{{.name}}-status"></span>
- <span class="muted small">{{t "…or paste / drop an image into the text."}}</span>
- <noscript><span class="muted small">{{t "The image is added at the end of the text when you save."}}</span></noscript>
+ <span class="muted small">{{t "…or paste / drop a file into the text. Images are shown, other files linked."}}</span>
+ <noscript><span class="muted small">{{t "The file is added at the end of the text when you save."}}</span></noscript>
</div>
{{template "mdhelp"}}
<script>
@@ -22,23 +22,27 @@
var fd = new FormData();
fd.append("_csrf", {{.csrf}});
fd.append("file", file);
- fetch({{.upload}}, { method: "POST", body: fd, credentials: "same-origin", headers: { Accept: "application/json" } })
+ return fetch({{.upload}}, { method: "POST", body: fd, credentials: "same-origin", headers: { Accept: "application/json" } })
.then(function (r) { return r.json().then(function (j) { if (!r.ok || j.error) throw new Error(j.error || {{t "upload failed"}}); return j; }); })
.then(function (j) { insert(j.markdown); st.textContent = {{t "Inserted"}} + " " + j.filename + "."; inp.value = ""; })
.catch(function (err) { st.textContent = {{t "Could not upload:"}} + " " + err.message; });
}
+ function uploadAll(files) { // one after the other, so each lands where the caret is
+ var i = 0;
+ (function next() { if (i < files.length) upload(files[i++]).then(next); })();
+ }
inp.addEventListener("change", function () { if (inp.files && inp.files[0]) upload(inp.files[0]); });
ta.addEventListener("paste", function (ev) {
var items = ev.clipboardData && ev.clipboardData.items;
if (!items) return;
for (var i = 0; i < items.length; i++) {
- if (items[i].kind === "file" && /^image\//.test(items[i].type)) { ev.preventDefault(); upload(items[i].getAsFile()); return; }
+ if (items[i].kind === "file") { ev.preventDefault(); upload(items[i].getAsFile()); return; }
}
});
ta.addEventListener("dragover", function (ev) { ev.preventDefault(); });
ta.addEventListener("drop", function (ev) {
- var f = ev.dataTransfer && ev.dataTransfer.files && ev.dataTransfer.files[0];
- if (f && /^image\//.test(f.type)) { ev.preventDefault(); upload(f); }
+ var fs = ev.dataTransfer && ev.dataTransfer.files;
+ if (fs && fs.length) { ev.preventDefault(); uploadAll(Array.prototype.slice.call(fs)); }
});
})();
</script>{{end}}