circuitpython/supervisor/shared/web_workflow/static/edit.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-07-25 20:15:43 -04:00
let $editor = document.querySelector("#code_textarea");
2022-07-15 17:25:57 -04:00
let filename = location.hash.substring(1);
let $output_text = document.querySelector("#output_text");
fetch(`/fs/${filename}`)
.then(function (response) {
$output_text.innerText = `Loading Status: ${response.status}`;
return response.status === 200 ? response.text() : "";
})
.then(function (data) {
2022-07-25 20:15:43 -04:00
$editor.value = data;
2022-07-15 17:25:57 -04:00
});
function save() {
$output_text.innerText = "Saving..."
const requestOptions = {
method: 'PUT',
2022-07-25 20:15:43 -04:00
body: $editor.value
2022-07-15 17:25:57 -04:00
};
fetch(`/fs/${filename}`, requestOptions)
.then(function (response) {
$output_text.innerText = `Saving Status: ${response.status}`;
return response.text();
})
.then(function (data) {
console.log("after fetch: " + data);
});
}
document.querySelector("#save_btn").onclick = function () {
console.log("Click Save!");
save();
2022-07-25 20:30:44 -04:00
}
let isCtrl = false;
document.onkeyup=function(e){
if(e.keyCode === 17) isCtrl=false;
}
document.onkeydown=function(e){
if(e.keyCode === 17) isCtrl=true;
if(e.keyCode === 83 && isCtrl === true) {
//ctrl-s pressed
save();
return false;
}
2022-07-26 11:37:33 -04:00
}