refactor page loader

This commit is contained in:
evilchili
2025-10-22 19:20:47 -07:00
parent 8fd28cf8b1
commit 6afab2a15c
5 changed files with 239 additions and 101 deletions
@@ -6,6 +6,27 @@ var pageContent = null;
var saveButton = null;
var editorUI = null;
APIv1 = {
put: function(data, callback) {
(async () => {
const raw = await fetch('/_/v1/put/' + window.location.pathname, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
'body': data
}),
});
const res = await raw.json();
if (res['code'] != 200) {
console.error("APIv1 error: ", res)
}
callback(res);
})();
},
};
isReadOnly = function() {
if (editor) {
@@ -53,7 +74,17 @@ makeSaveButton = function() {
button.className = 'actions';
button.innerHTML = 'save';
button.id = 'saveButton';
button.style.border = "1px solid black";
button.addEventListener('click', () => {
APIv1.put({
'body': editorUI.getMarkdown()
}, (res) => {
if (res['code'] == 200) {
button.style.border = "1px solid green";
} else {
button.style.border = "1px solid red";
}
});
});
saveButton = button;
return button;