Hi,
Attached patch shifts focus to the password field if 'enter' was pressed inside the username field.
I would commit this without asking if I weren't concerned about wether I placed the new 'login form methods' block in the right place, and using the proper reference vars etc.
Thomas, is this OK?
Robin
--- program/js/app.js (revision 521) +++ program/js/app.js (working copy) @@ -274,6 +274,8 @@ case 'login': var input_user = rcube_find_object('_user'); var input_pass = rcube_find_object('_pass');
if (input_user)
input_user.onkeypress = function(e){ return rcmail.login_user_keypress(e); };
if (input_user && input_user.value=='')
input_user.focus();
else if (input_pass)
@@ -1627,6 +1629,34 @@
return null;
};
/*********************************************************/
/********* login form methods *********/
/*********************************************************/
this.init_login_form_events = function(obj)
{
var handler = function(e){ return ref.login_user_keypress(e,this); };
if (obj.addEventListener)
obj.addEventListener(bw.safari ? 'keydown' : 'keypress', handler, false);
else
obj.onkeydown = handler;
};
// handler for keyboard events on the _user field
this.login_user_keypress = function(e)
{
var key = document.all ? event.keyCode : document.getElementById ? e.keyCode : 0;
// enter
if ((key==13) && (document.form._pass))
{
document.form._pass.focus();
return false;
}
};
/*********************************************************/
Robin Elfrink wrote:
Hi,
Hi Robin
Attached patch shifts focus to the password field if 'enter' was pressed inside the username field.
I would commit this without asking if I weren't concerned about wether I placed the new 'login form methods' block in the right place, and using the proper reference vars etc.
I don't see any usage of the method 'init_login_form_events'. What's it good for?
To set the focus you should to use rcube_find_object('_pass') instead of directly accessing document.form._pass.
And one last suggestion: var key = e && e.keyCode ? e.keyCode : event.keyCode;
Event properties actually have nothing to do with document.*
Thomas, is this OK?
Go ahead and commit the changes.
Thanks! ~Thomas
Thomas Bruederli wrote:
I don't see any usage of the method 'init_login_form_events'. What's it good for?
It adds an event listener to the username input box. I created (actually mostly copied) this function in case we need more login-screen-initialization in the future.
To set the focus you should to use rcube_find_object('_pass') instead of directly accessing document.form._pass.
Yes, that was stupid. Thanks.
And one last suggestion: var key = e && e.keyCode ? e.keyCode : event.keyCode;
Event properties actually have nothing to do with document.*
Duh. I copied the line from function this.name_input_keypress(). I see now that that function handles document-wide key events.
Robin
Robin Elfrink wrote:
I don't see any usage of the method 'init_login_form_events'. What's it good for?
It adds an event listener to the username input box. I created (actually mostly copied) this function in case we need more login-screen-initialization in the future.
Ah, but I failed to call that function. I'll remove it.
Robin
Robin Elfrink wrote:
Thomas Bruederli wrote:
And one last suggestion: var key = e && e.keyCode ? e.keyCode : event.keyCode;
Event properties actually have nothing to do with document.*
Duh. I copied the line from function this.name_input_keypress(). I see now that that function handles document-wide key events.
Well, then it's time to manage this uniquely. I just created another static method in rcube_event to get the event's key code (revision 527).
~Thomas