Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created January 11, 2011 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/773978 to your computer and use it in GitHub Desktop.
Save walterdavis/773978 to your computer and use it in GitHub Desktop.
var current_selection = false;
//somewhere in your selection code, set this to
//true when you have marked a selection
// ...
current_selection = true;
var getKeyCode = function(evt){
var code;
if (evt.keyCode) code = evt.keyCode;
else if (evt.which) code = evt.which;
return parseInt(code,10);
}
document.observe('keypress',function(evt){
if(current_selection && getKeyCode(evt) == 32){
//keep the event from doing anything to your form
evt.stop();
$('yourMenu').show();
//maybe cancel the global variable here, so you can
//once again type spaces
current_selection = false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment