Added arrow hotkeys to Draggable and Resizable

Which means better control over the post notes placement for all the
keyboard lovers.
This commit is contained in:
Marcin Kurczewski
2015-02-22 18:56:35 +01:00
parent 90406b1278
commit b416868aa7
4 changed files with 121 additions and 22 deletions

View File

@ -2,6 +2,11 @@ var App = App || {};
App.Util = App.Util || {};
App.Util.Resizable = function(jQuery) {
var KEY_LEFT = 37;
var KEY_UP = 38;
var KEY_RIGHT = 39;
var KEY_DOWN = 40;
function relativeResizeStrategy($element) {
var $parent = $element.parent();
var delta;
@ -51,6 +56,7 @@ App.Util.Resizable = function(jQuery) {
$resizer.mousedown(function(e) {
e.preventDefault();
e.stopPropagation();
$element.focus();
$element.addClass('resizing');
strategy.mouseClicked(e);
@ -65,6 +71,32 @@ App.Util.Resizable = function(jQuery) {
jQuery(window).unbind('mouseup.elemsize');
});
});
$element.keydown(function(e) {
var size = strategy.getSize();
var oldSize = {width: size.width, height: size.height};
if (!e.shiftKey) {
return;
}
var delta = e.ctrlKey ? 10 : 1;
if (e.which === KEY_LEFT) {
size.width -= delta;
} else if (e.which === KEY_RIGHT) {
size.width += delta;
} else if (e.which === KEY_UP) {
size.height -= delta;
} else if (e.which === KEY_DOWN) {
size.height += delta;
}
if (size.width !== oldSize.width || size.height !== oldSize.height) {
e.stopPropagation();
e.stopImmediatePropagation();
e.preventDefault();
strategy.setSize(size.width, size.height);
}
});
}
return {