Added (Ctrl+s) draft force save

This commit is contained in:
Dan Brown 2016-05-28 13:51:07 +01:00
parent f602b088ac
commit 5b9362ab0b
2 changed files with 18 additions and 1 deletions

View File

@ -379,6 +379,15 @@ module.exports = function (ngApp, events) {
saveDraft(); saveDraft();
}; };
// Listen to shortcuts coming via events
$scope.$on('editor-keydown', (event, data) => {
// Save shortcut (ctrl+s)
if (data.keyCode == 83 && (navigator.platform.match("Mac") ? data.metaKey : data.ctrlKey)) {
data.preventDefault();
saveDraft();
}
});
/** /**
* Discard the current draft and grab the current page * Discard the current draft and grab the current page
* content from the system via an AJAX request. * content from the system via an AJAX request.

View File

@ -185,6 +185,10 @@ module.exports = function (ngApp, events) {
scope.mceChange(content); scope.mceChange(content);
}); });
editor.on('keydown', (event) => {
scope.$emit('editor-keydown', event);
});
editor.on('init', (e) => { editor.on('init', (e) => {
scope.mceModel = editor.getContent(); scope.mceModel = editor.getContent();
}); });
@ -305,8 +309,9 @@ module.exports = function (ngApp, events) {
lastScroll = now; lastScroll = now;
}); });
// Insert image shortcut // Editor key-presses
input.keydown(event => { input.keydown(event => {
// Insert image shortcut
if (event.which === 73 && event.ctrlKey && event.shiftKey) { if (event.which === 73 && event.ctrlKey && event.shiftKey) {
event.preventDefault(); event.preventDefault();
var caretPos = input[0].selectionStart; var caretPos = input[0].selectionStart;
@ -316,7 +321,10 @@ module.exports = function (ngApp, events) {
input.focus(); input.focus();
input[0].selectionStart = caretPos + ("![](".length); input[0].selectionStart = caretPos + ("![](".length);
input[0].selectionEnd = caretPos + ('![](http://'.length); input[0].selectionEnd = caretPos + ('![](http://'.length);
return;
} }
// Pass key presses to controller via event
scope.$emit('editor-keydown', event);
}); });
// Insert image from image manager // Insert image from image manager