1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-19 15:43:45 +02:00
RPGnotes/static/js/markdown.js

61 lines
2 KiB
JavaScript
Raw Normal View History

2021-08-28 19:52:07 +02:00
/**
* Copyright (C) 2020 Lukas Winkler
*
* @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
*
*/
document.addEventListener('DOMContentLoaded', function () {
2022-07-04 00:35:01 +02:00
const csrftoken = document.querySelector('[name=csrfmiddlewaretoken]').value;
2021-08-28 19:52:07 +02:00
const ids = ["id_description_md"];
ids.forEach(function (id) {
const element = document.getElementById(id);
if (!element) {
return
}
const easyMDE = new EasyMDE({
element: element,
forceSync: true, // for "required" to work
spellChecker: false,
nativeSpellcheck: true,
autoDownloadFontAwesome: false,
autosave: {
delay: 1000,
submit_delay: 5000,
timeFormat: {
locale: 'de-AT',
format: {
year: 'numeric',
month: 'long',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
},
},
2022-07-04 00:35:01 +02:00
},
inputStyle: "contenteditable",
status: ["lines", "words", "cursor", "saveStatus"],
2021-08-28 19:52:07 +02:00
});
2022-07-04 00:35:01 +02:00
window.editor = easyMDE
setInterval(function () {
const content = easyMDE.value();
fetch("/api/draft/save", {
method: "POST",
body: JSON.stringify({
"draft_md": content
}),
headers: {'X-CSRFToken': csrftoken},
})
.then(response => response.json())
.then(data => {
easyMDE.updateStatusBar("saveStatus", data.message)
setTimeout(e => easyMDE.updateStatusBar("saveStatus", ""), 5000)
}).catch(e => {
easyMDE.updateStatusBar("saveStatus", "error saving draft")
})
}, 1000 * 30)
2021-08-28 19:52:07 +02:00
});
});