Search code examples
javascriptjqueryimpress.js

Restore default value of arrows key


I'm using a script (impress.js) that bins some particular action to keyup and keydown events for left, right, up and down arrows.

In some particular moments (for example while typing in a textarea) I want back the default behaviour for the arrows.

I tried without success with

$("a#show-ta").click( function() {      
  document.addEventListener("keydown", function ( event ) {
    if (event.keyCode >= 37 && event.keyCode <= 40) {
      return;
    }
  });
  document.addEventListener("keyup", function ( event ) {
    if (event.keyCode >= 37 && event.keyCode <= 40) {
      return;
    }
  }); 
}); 

where a#show-ta is the button that shows my textarea.


Solution

  • You want to prevent the keypress from bubbling up to the document where (I assume) Impress binds its handlers:

    $("textarea").on('keyup keydown keypress', function(e) {
      e.stopPropagation();
    });