1

Is it possible to cancel current jQueryUI resizable and draggable interaction with a key press?

Marcin Wisnicki
  • 4,511
  • 4
  • 35
  • 57

1 Answers1

1

Yes it's possible. You can check to escape key on the document, and if so disable the draggable feature.

Code:

$(document).ready(function() {
    $('.popup_click').draggable();
 }); 

$(document).keyup(function(e) {
  if (e.keyCode == 27) {  
      $('.popup_click').draggable( 'disable' ).addClass('disabled');
  }   
});

Demo: http://jsfiddle.net/IrvinDominin/7L2FY/

EDIT

To stop drag you can fire a mouseup:

$(document).keyup(function(e) {
  if (e.keyCode == 27) {  
      $( '.popup_click' ).trigger( 'mouseup' );
  }   
});

Demo: http://jsfiddle.net/IrvinDominin/7L2FY/1/

Irvin Dominin
  • 30,819
  • 9
  • 77
  • 111
  • By canceling interaction I meant aborting in-progress resize/drag. – Marcin Wisnicki Nov 29 '13 at 12:02
  • I thought about doing it this way but it may cause [problems due to missing event properties](http://bugs.jqueryui.com/ticket/5664#comment:1) and is not supported by jquery devs. Also it does not restore original state. – Marcin Wisnicki Nov 29 '13 at 13:57