Fixed bad arrows behavior while editing post notes

This commit is contained in:
Marcin Kurczewski 2015-02-22 19:30:07 +01:00
parent b416868aa7
commit e7ea60f293
3 changed files with 55 additions and 51 deletions

View file

@ -61,8 +61,8 @@ App.Presenters.PostNotesPresenter = function(
$postNote.data('postNote', postNote); $postNote.data('postNote', postNote);
$postNote.find('.text-wrapper').click(postNoteClicked); $postNote.find('.text-wrapper').click(postNoteClicked);
postNote.$element = $postNote; postNote.$element = $postNote;
draggable.makeDraggable($postNote, draggable.relativeDragStrategy); draggable.makeDraggable($postNote, draggable.relativeDragStrategy, true);
resizable.makeResizable($postNote); resizable.makeResizable($postNote, true);
}); });
$form.find('button').click(formSubmitted); $form.find('button').click(formSubmitted);
@ -163,7 +163,7 @@ App.Presenters.PostNotesPresenter = function(
$form.data('postNote', postNote); $form.data('postNote', postNote);
$form.find('textarea').val(postNote.text); $form.find('textarea').val(postNote.text);
$form.show(); $form.show();
draggable.makeDraggable($form, draggable.absoluteDragStrategy); draggable.makeDraggable($form, draggable.absoluteDragStrategy, false);
} }
function hideForm() { function hideForm() {

View file

@ -82,7 +82,7 @@ App.Util.Draggable = function(jQuery) {
}; };
} }
function makeDraggable($element, dragStrategy) { function makeDraggable($element, dragStrategy, enableHotkeys) {
var strategy = dragStrategy($element); var strategy = dragStrategy($element);
$element.data('drag-strategy', strategy); $element.data('drag-strategy', strategy);
@ -108,31 +108,33 @@ App.Util.Draggable = function(jQuery) {
}); });
}); });
$element.keydown(function(e) { if (enableHotkeys) {
var position = strategy.getPosition(); $element.keydown(function(e) {
var oldPosition = {x: position.x, y: position.y}; var position = strategy.getPosition();
if (e.shiftKey) { var oldPosition = {x: position.x, y: position.y};
return; if (e.shiftKey) {
} return;
}
var delta = e.ctrlKey ? 10 : 1; var delta = e.ctrlKey ? 10 : 1;
if (e.which === KEY_LEFT) { if (e.which === KEY_LEFT) {
position.x -= delta; position.x -= delta;
} else if (e.which === KEY_RIGHT) { } else if (e.which === KEY_RIGHT) {
position.x += delta; position.x += delta;
} else if (e.which === KEY_UP) { } else if (e.which === KEY_UP) {
position.y -= delta; position.y -= delta;
} else if (e.which === KEY_DOWN) { } else if (e.which === KEY_DOWN) {
position.y += delta; position.y += delta;
} }
if (position.x !== oldPosition.x || position.y !== oldPosition.y) { if (position.x !== oldPosition.x || position.y !== oldPosition.y) {
e.stopPropagation(); e.stopPropagation();
e.stopImmediatePropagation(); e.stopImmediatePropagation();
e.preventDefault(); e.preventDefault();
strategy.setPosition(position.x, position.y); strategy.setPosition(position.x, position.y);
} }
}); });
}
} }
return { return {

View file

@ -48,7 +48,7 @@ App.Util.Resizable = function(jQuery) {
}; };
} }
function makeResizable($element) { function makeResizable($element, enableHotkeys) {
var $resizer = jQuery('<div class="resizer"></div>'); var $resizer = jQuery('<div class="resizer"></div>');
var strategy = relativeResizeStrategy($element); var strategy = relativeResizeStrategy($element);
$element.append($resizer); $element.append($resizer);
@ -72,31 +72,33 @@ App.Util.Resizable = function(jQuery) {
}); });
}); });
$element.keydown(function(e) { if (enableHotkeys) {
var size = strategy.getSize(); $element.keydown(function(e) {
var oldSize = {width: size.width, height: size.height}; var size = strategy.getSize();
if (!e.shiftKey) { var oldSize = {width: size.width, height: size.height};
return; if (!e.shiftKey) {
} return;
}
var delta = e.ctrlKey ? 10 : 1; var delta = e.ctrlKey ? 10 : 1;
if (e.which === KEY_LEFT) { if (e.which === KEY_LEFT) {
size.width -= delta; size.width -= delta;
} else if (e.which === KEY_RIGHT) { } else if (e.which === KEY_RIGHT) {
size.width += delta; size.width += delta;
} else if (e.which === KEY_UP) { } else if (e.which === KEY_UP) {
size.height -= delta; size.height -= delta;
} else if (e.which === KEY_DOWN) { } else if (e.which === KEY_DOWN) {
size.height += delta; size.height += delta;
} }
if (size.width !== oldSize.width || size.height !== oldSize.height) { if (size.width !== oldSize.width || size.height !== oldSize.height) {
e.stopPropagation(); e.stopPropagation();
e.stopImmediatePropagation(); e.stopImmediatePropagation();
e.preventDefault(); e.preventDefault();
strategy.setSize(size.width, size.height); strategy.setSize(size.width, size.height);
} }
}); });
}
} }
return { return {