key-kill-mode: a page-mode for blocking keyup and keydown events
authorJohn Foerch <jjfoerch@earthlink.net>
Sat, 23 Mar 2013 23:19:14 +0000 (23 19:19 -0400)
committerJohn Foerch <jjfoerch@earthlink.net>
Sat, 23 Mar 2013 23:19:14 +0000 (23 19:19 -0400)
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\//);

modules/page-modes/key-kill.js [new file with mode: 0644]

diff --git a/modules/page-modes/key-kill.js b/modules/page-modes/key-kill.js
new file mode 100644 (file)
index 0000000..61f79c6
--- /dev/null
@@ -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");