From 10627abff221427012b952347cc65b3a679b6145 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 21 Dec 2009 13:34:49 -0700 Subject: [PATCH] Optimize return trapping code --- imp/js/compose.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/imp/js/compose.js b/imp/js/compose.js index 312c25e67..dc23acc56 100644 --- a/imp/js/compose.js +++ b/imp/js/compose.js @@ -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); } }); -- 2.11.0