diff options
Diffstat (limited to 'internal/web/templates/partials')
| -rw-r--r-- | internal/web/templates/partials/dashnav.html | 2 | ||||
| -rw-r--r-- | internal/web/templates/partials/editor.html | 18 | ||||
| -rw-r--r-- | internal/web/templates/partials/mdhelp.html | 2 |
3 files changed, 13 insertions, 9 deletions
diff --git a/internal/web/templates/partials/dashnav.html b/internal/web/templates/partials/dashnav.html index 65b0ed5..8b44e55 100644 --- a/internal/web/templates/partials/dashnav.html +++ b/internal/web/templates/partials/dashnav.html @@ -23,7 +23,7 @@ <a href="{{$b}}announcements"{{if hasPrefix .Path (print $b "announcements")}} class="active"{{end}}>{{t "Announcements"}}</a> <a href="{{$b}}layout"{{if hasPrefix .Path (print $b "layout")}} class="active"{{end}}>{{t "Layout"}}</a> <a href="{{$b}}design"{{if hasPrefix .Path (print $b "design")}} class="active"{{end}}>{{t "Design"}}</a> - <a href="{{$b}}images"{{if hasPrefix .Path (print $b "images")}} class="active"{{end}}>{{t "Images"}}</a> + <a href="{{$b}}files"{{if hasPrefix .Path (print $b "files")}} class="active"{{end}}>{{t "Files"}}</a> <a href="{{$b}}settings"{{if hasPrefix .Path (print $b "settings")}} class="active"{{end}}>{{t "Settings"}}</a> </span> <a class="view" href="{{.BlogURL}}" target="_blank">{{t "View blog"}} ↗</a> 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}} diff --git a/internal/web/templates/partials/mdhelp.html b/internal/web/templates/partials/mdhelp.html index 748452e..5489510 100644 --- a/internal/web/templates/partials/mdhelp.html +++ b/internal/web/templates/partials/mdhelp.html @@ -2,7 +2,7 @@ <summary>{{t "Formatting cheat-sheet"}}</summary> <table class="cheat"> <tr><td><code># {{t "Heading"}}</code>, <code>## {{t "Smaller heading"}}</code></td><td><code>**{{t "bold"}}**</code>, <code>*{{t "italic"}}*</code></td></tr> - <tr><td><code>[{{t "link text"}}](https://example.org)</code></td><td><code></code> — <em>{{t "Insert image"}}</em> {{t "writes this for you"}}</td></tr> + <tr><td><code>[{{t "link text"}}](https://example.org)</code></td><td><code></code>, <code>[{{t "file name"}}](/media/…)</code> — <em>{{t "Insert file"}}</em> {{t "writes this for you"}}</td></tr> <tr><td><code>- {{t "list item"}}</code> / <code>1. {{t "numbered"}}</code></td><td><code>> {{t "quote"}}</code>, <code>`{{t "code"}}`</code>, <code>---</code> {{t "for a line"}}</td></tr> </table> <p class="muted small">{{t "Blank line = new paragraph. Press Enter once for a line break."}}</p> |
