Optimize return trapping code
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 21 Dec 2009 20:34:49 +0000 (13:34 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 22 Dec 2009 05:30:13 +0000 (22:30 -0700)
imp/js/compose.js

index 312c25e..dc23acc 100644 (file)
@@ -360,19 +360,23 @@ var ImpCompose = {
         }
     },
 
+    keyDownHandler: function(e)
+    {
+        if (e.keyCode == 10 || e.keyCode == Event.KEY_RETURN) {
+            e.stop();
+        }
+    },
+
     onDomLoad: function()
     {
+        var handler = this.keyDownHandler.bindAsEventListener(this);
+
         /* Prevent Return from sending messages - it should bring us out of
          * autocomplete, not submit the whole form. */
-        $$('INPUT').each(function(i) {
+        $('compose').select('INPUT').each(function(i) {
             /* Attach to everything but button and submit elements. */
             if (i.type != 'submit' && i.type != 'button') {
-                i.observe('keydown', function(e) {
-                    if (e.keyCode == 10 || e.keyCode == Event.KEY_RETURN) {
-                        e.stop();
-                        return false;
-                    }
-                });
+                i.observe('keydown', handler);
             }
         });