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}}">
|
2017-09-04 14:47:12 +03:00
|
|
|
<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>
|
2017-09-04 14:47:12 +03:00
|
|
|
</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>
|
2017-09-04 14:47:12 +03:00
|
|
|
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");
|
2017-09-04 14:47:12 +03:00
|
|
|
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";
|
|
|
|
|
2017-09-04 14:47:12 +03:00
|
|
|
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),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2017-09-04 14:47:12 +03:00
|
|
|
|
|
|
|
textarea.focus();
|
2017-09-02 16:32:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
document
|
|
|
|
.getElementById("openEditor")
|
|
|
|
.addEventListener("click", function (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
|
|
|
openEditor();
|
|
|
|
})
|
|
|
|
</script>
|