Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

document key observer

  • Loading branch information...
commit 9a6e68f6964f7c90372b430f527bb365dbbd61b6 1 parent d21f77e
kangax authored
Showing with 11 additions and 11 deletions.
  1. +11 −11 key_observer.js
View
22 key_observer.js
@@ -1,17 +1,17 @@
-/*
-
-Example:
-
-document.observe('key:esc', helpWindow.close);
-document.observe('key:space', focusNextField);
-
-*/
-
-
+/**
+ * Fires document-wide key:* events
+ * Observed keys are the ones from Event.KEY_*,
+ * as well as "space" and "pause" ones
+ *
+ * document.observe('key:esc', helpWindow.close);
+ * document.observe('key:space', focusNextField);
+ *
+ **/
(function() {
var hash = { 32: 'space', 19: 'pause' };
- var handler = function(e) {
+ function handler(e) {
if (!hash[e.keyCode]) return;
+ // tab needs keydown
if (e.type == 'keydown' && e.keyCode != Event.KEY_TAB) return;
document.fire('key:' + hash[e.keyCode], e);
}
Please sign in to comment.
Something went wrong with that request. Please try again.