surwiki/templates/article_revision.html

83 lines
2 KiB
HTML
Raw Normal View History

2017-09-01 17:34:24 +03:00
<header>
2017-08-20 23:17:16 +03:00
<h1>{{title}}</h1>
2017-09-01 17:34:24 +03:00
</header>
<article>
2017-09-02 16:32:59 +03:00
<div class="rendered">
{{{rendered}}}
</div>
<div class="editor">
<form action="" method="POST">
<input type=hidden name=revision value="{{revision}}">
<textarea autocomplete=off name=body>{{raw}}</textarea>
<textarea autocomplete=off class="shadow-control"></textarea>
<div class="editor-controls">
2017-09-02 16:32:59 +03:00
<button type=submit>Save</button>
</div>
2017-09-02 16:32:59 +03:00
</form>
</div>
2017-09-01 17:34:24 +03:00
</article>
<footer>
2017-09-02 16:32:59 +03:00
<p><a id="openEditor" href="?editor=true">Edit</a></p>
2017-09-01 17:34:24 +03:00
<dl>
<dt>Article ID</dt>
<dd>{{article_id}}</dd>
<dt>Revision</dt>
<dd>{{revision}}</dd>
<dt>Last updated</dt>
<dd>{{created}}</dd>
</dl>
</footer>
2017-09-02 16:32:59 +03:00
<script>
function autosizeTextarea(textarea, shadow) {
shadow.value = textarea.value;
shadow.style.width = textarea.clientWidth + "px";
shadow.style.height = "auto";
textarea.style.height = shadow.scrollHeight + "px";
}
2017-09-02 16:32:59 +03:00
function openEditor() {
const rendered = document.querySelector(".rendered");
const editor = document.querySelector(".editor");
const textarea = editor.querySelector('textarea[name="body"]');
const shadow = editor.querySelector('textarea.shadow-control');
2017-09-02 16:32:59 +03:00
editor.style.display = "block";
autosizeTextarea(textarea, shadow);
textarea.addEventListener('input', () => autosizeTextarea(textarea, shadow));
window.addEventListener('resize', () => autosizeTextarea(textarea, shadow));
rendered.style.display = "none";
2017-09-02 16:32:59 +03:00
const form = editor.querySelector("form");
form.addEventListener("submit", async function (ev) {
ev.preventDefault();
ev.stopPropagation();
const response = await fetch(
form.getAttribute("action"),
{
method: 'PUT',
body: new FormData(form),
}
);
});
textarea.focus();
2017-09-02 16:32:59 +03:00
}
document
.getElementById("openEditor")
.addEventListener("click", function (ev) {
ev.preventDefault();
ev.stopPropagation();
openEditor();
})
</script>