From e7ea60f293c0d232f3fcd939bcc4c6d45771f903 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 22 Feb 2015 19:30:07 +0100 Subject: [PATCH] Fixed bad arrows behavior while editing post notes --- .../js/Presenters/PostNotesPresenter.js | 6 +-- public_html/js/Util/Draggable.js | 50 ++++++++++--------- public_html/js/Util/Resizable.js | 50 ++++++++++--------- 3 files changed, 55 insertions(+), 51 deletions(-) diff --git a/public_html/js/Presenters/PostNotesPresenter.js b/public_html/js/Presenters/PostNotesPresenter.js index 7f80d9ab..83df850b 100644 --- a/public_html/js/Presenters/PostNotesPresenter.js +++ b/public_html/js/Presenters/PostNotesPresenter.js @@ -61,8 +61,8 @@ App.Presenters.PostNotesPresenter = function( $postNote.data('postNote', postNote); $postNote.find('.text-wrapper').click(postNoteClicked); postNote.$element = $postNote; - draggable.makeDraggable($postNote, draggable.relativeDragStrategy); - resizable.makeResizable($postNote); + draggable.makeDraggable($postNote, draggable.relativeDragStrategy, true); + resizable.makeResizable($postNote, true); }); $form.find('button').click(formSubmitted); @@ -163,7 +163,7 @@ App.Presenters.PostNotesPresenter = function( $form.data('postNote', postNote); $form.find('textarea').val(postNote.text); $form.show(); - draggable.makeDraggable($form, draggable.absoluteDragStrategy); + draggable.makeDraggable($form, draggable.absoluteDragStrategy, false); } function hideForm() { diff --git a/public_html/js/Util/Draggable.js b/public_html/js/Util/Draggable.js index 72fa7363..be2e6456 100644 --- a/public_html/js/Util/Draggable.js +++ b/public_html/js/Util/Draggable.js @@ -82,7 +82,7 @@ App.Util.Draggable = function(jQuery) { }; } - function makeDraggable($element, dragStrategy) { + function makeDraggable($element, dragStrategy, enableHotkeys) { var strategy = dragStrategy($element); $element.data('drag-strategy', strategy); @@ -108,31 +108,33 @@ App.Util.Draggable = function(jQuery) { }); }); - $element.keydown(function(e) { - var position = strategy.getPosition(); - var oldPosition = {x: position.x, y: position.y}; - if (e.shiftKey) { - return; - } + if (enableHotkeys) { + $element.keydown(function(e) { + var position = strategy.getPosition(); + var oldPosition = {x: position.x, y: position.y}; + if (e.shiftKey) { + return; + } - var delta = e.ctrlKey ? 10 : 1; - if (e.which === KEY_LEFT) { - position.x -= delta; - } else if (e.which === KEY_RIGHT) { - position.x += delta; - } else if (e.which === KEY_UP) { - position.y -= delta; - } else if (e.which === KEY_DOWN) { - position.y += delta; - } + var delta = e.ctrlKey ? 10 : 1; + if (e.which === KEY_LEFT) { + position.x -= delta; + } else if (e.which === KEY_RIGHT) { + position.x += delta; + } else if (e.which === KEY_UP) { + position.y -= delta; + } else if (e.which === KEY_DOWN) { + position.y += delta; + } - if (position.x !== oldPosition.x || position.y !== oldPosition.y) { - e.stopPropagation(); - e.stopImmediatePropagation(); - e.preventDefault(); - strategy.setPosition(position.x, position.y); - } - }); + if (position.x !== oldPosition.x || position.y !== oldPosition.y) { + e.stopPropagation(); + e.stopImmediatePropagation(); + e.preventDefault(); + strategy.setPosition(position.x, position.y); + } + }); + } } return { diff --git a/public_html/js/Util/Resizable.js b/public_html/js/Util/Resizable.js index 303ff27f..58c41c17 100644 --- a/public_html/js/Util/Resizable.js +++ b/public_html/js/Util/Resizable.js @@ -48,7 +48,7 @@ App.Util.Resizable = function(jQuery) { }; } - function makeResizable($element) { + function makeResizable($element, enableHotkeys) { var $resizer = jQuery('
'); var strategy = relativeResizeStrategy($element); $element.append($resizer); @@ -72,31 +72,33 @@ App.Util.Resizable = function(jQuery) { }); }); - $element.keydown(function(e) { - var size = strategy.getSize(); - var oldSize = {width: size.width, height: size.height}; - if (!e.shiftKey) { - return; - } + if (enableHotkeys) { + $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; - } + 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); - } - }); + if (size.width !== oldSize.width || size.height !== oldSize.height) { + e.stopPropagation(); + e.stopImmediatePropagation(); + e.preventDefault(); + strategy.setSize(size.width, size.height); + } + }); + } } return {