Add ctrl-S save shortcut

This commit is contained in:
Tim 2016-09-16 11:22:24 +01:00 committed by GitHub
parent a8a7aeecd6
commit 3bbb32b25a

View File

@ -803,9 +803,7 @@ document.addEventListener("editor", (event) => {
button.addEventListener('click', addFrontMatterItem);
});
document.querySelector('form').addEventListener('submit', (event) => {
event.preventDefault();
let saveContent = function() {
let data = form2js(document.querySelector('form'));
let html = button.changeToLoading();
let request = new XMLHttpRequest();
@ -818,8 +816,24 @@ document.addEventListener("editor", (event) => {
button.changeToDone((request.status != 200), html);
}
}
}
document.querySelector('form').addEventListener('submit', (event) => {
event.preventDefault();
saveContent();
});
window.addEventListener('keydown', (event) => {
if (event.ctrlKey || event.metaKey) {
switch (String.fromCharCode(event.which).toLowerCase()) {
case 's':
event.preventDefault();
saveContent();
break;
}
}
}
return false;
});