Permalink
Browse files

key-kill-mode: a page-mode for blocking keyup and keydown events

Key-kill mode is a generic page-mode that can be used on any site for
blocking keyup and keydown events.  To use it, load the module and add
tests, like this:

    require("key-kill");
    key_kill_mode.test.push(build_url_regexp($domain = "github"));
    key_kill_mode.test.push(/\/\/.*slashdot\.org\//);
  • Loading branch information...
1 parent 9bedf9a commit 0341e791c78653a2f5bbbff9a1dac04bf898dd65 @retroj committed Mar 23, 2013
Showing with 32 additions and 0 deletions.
  1. +32 −0 modules/page-modes/key-kill.js
@@ -0,0 +1,32 @@
+/**
+ * (C) Copyright 2013 John J Foerch
+ *
+ * Use, modification, and distribution are subject to the terms specified in the
+ * COPYING file.
+**/
+
+function key_kill_event_kill (event) {
+ var elem = event.target;
+ if (elem instanceof Ci.nsIDOMHTMLInputElement ||
+ elem instanceof Ci.nsIDOMHTMLTextAreaElement)
+ {
+ return;
+ }
+ event_kill(event);
+}
+
+define_page_mode("key-kill-mode",
+ [],
+ function enable (buffer) {
+ buffer.browser.addEventListener("keyup", key_kill_event_kill, true);
+ buffer.browser.addEventListener("keydown", key_kill_event_kill, true);
+ },
+ function disable (buffer) {
+ buffer.browser.removeEventListener("keyup", key_kill_event_kill, true);
+ buffer.browser.removeEventListener("keydown", key_kill_event_kill, true);
+ },
+ $display_name = "Key-kill");
+
+page_mode_activate(key_kill_mode);
+
+provide("key-kill");

0 comments on commit 0341e79

Please sign in to comment.