refactor page loader
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user