Abstract event keycode detection

release-0.6
thomascube 18 years ago
parent b566ffd227
commit 9bbb17c1c6

@ -1638,14 +1638,13 @@ function rcube_webmail()
// handler for keyboard events on the _user field // handler for keyboard events on the _user field
this.login_user_keypress = function(e) this.login_user_keypress = function(e)
{ {
if (!e) var key = rcube_event.get_keycode(e);
e = window.event; var elm;
var key = e.keyCode ? e.keyCode : e.which;
// enter // enter
if ((key==13) && (document.form._pass)) if ((key==13) && (elm = rcube_find_object('_pass')))
{ {
rcube_find_object('_pass').focus(); elm.focus();
return false; return false;
} }
}; };
@ -1986,11 +1985,9 @@ function rcube_webmail()
if (this.ksearch_timer) if (this.ksearch_timer)
clearTimeout(this.ksearch_timer); clearTimeout(this.ksearch_timer);
if (!e)
e = window.event;
var highlight; var highlight;
var key = e.keyCode ? e.keyCode : e.which; var key = rcube_event.get_keycode(e);
var mod = rcube_event.get_modifier(e);
switch (key) switch (key)
{ {
@ -2022,7 +2019,7 @@ function rcube_webmail()
return rcube_event.cancel(e); return rcube_event.cancel(e);
case 9: // tab case 9: // tab
if(e.shiftKey) if(mod == SHIFT_KEY)
break; break;
case 13: // enter case 13: // enter
@ -2531,7 +2528,7 @@ function rcube_webmail()
// handler for keyboard events on the input field // handler for keyboard events on the input field
this.name_input_keypress = function(e) this.name_input_keypress = function(e)
{ {
var key = document.all ? event.keyCode : document.getElementById ? e.keyCode : 0; var key = rcube_event.get_keycode(e);
// enter // enter
if (key==13) if (key==13)

@ -103,6 +103,15 @@ function roundcube_browser()
// static functions for event handling // static functions for event handling
var rcube_event = { var rcube_event = {
/**
* returns the event key code
*/
get_keycode: function(e)
{
e = e || window.event;
return e && e.keyCode ? e.keyCode : (e && e.which ? e.which : 0);
},
/** /**
* returns modifier key (constants defined at top of file) * returns modifier key (constants defined at top of file)
*/ */

Loading…
Cancel
Save