surwiki/templates/article_revision.html

67 lines
1.4 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 name=body>{{raw}}</textarea>
<button type=submit>Save</button>
</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 openEditor() {
const rendered = document.querySelector(".rendered");
const editor = document.querySelector(".editor");
rendered.style.display = "none";
editor.style.display = "block";
const textarea = editor.querySelector("textarea");
textarea.style.height = (textarea.scrollHeight + 60) + "px";
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),
}
);
});
}
document
.getElementById("openEditor")
.addEventListener("click", function (ev) {
ev.preventDefault();
ev.stopPropagation();
openEditor();
})
</script>