Skip to content

Commit

Permalink
Merge branch 'w28_MDL-23344_m22_loginfocus2' of git://github.com/skod…
Browse files Browse the repository at this point in the history
…ak/moodle
  • Loading branch information
samhemelryk committed Jul 18, 2011
2 parents ce4a587 + 2d16dad commit c5fe313
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions admin/settings/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
$temp->add(new admin_setting_manageauths());
$temp->add(new admin_setting_heading('manageauthscommonheading', get_string('commonsettings', 'admin'), ''));
$temp->add(new admin_setting_special_registerauth());
$temp->add(new admin_setting_configcheckbox('loginpageautofocus', get_string('loginpageautofocus', 'admin'), get_string('loginpageautofocus_help', 'admin'), 0));
$temp->add(new admin_setting_configselect('guestloginbutton', get_string('guestloginbutton', 'auth'),
get_string('showguestlogin', 'auth'), '1', array('0'=>get_string('hide'), '1'=>get_string('show'))));
$temp->add(new admin_setting_configtext('alternateloginurl', get_string('alternateloginurl', 'auth'),
Expand Down
2 changes: 2 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@
$string['logguests'] = 'Log guest access';
$string['logguests_help'] = 'This setting enables logging of actions by guest account and not logged in users. High profile sites may want to disable this logging for performance reasons. It is recommended to keep this setting enabled on production sites.';
$string['loginhttps'] = 'Use HTTPS for logins';
$string['loginpageautofocus'] = 'Autofocus login page form';
$string['loginpageautofocus_help'] = 'Enabling this option improves usability of the login page, but automatically focusing fields may be considered an accessibility issue.';
$string['loglifetime'] = 'Keep logs for';
$string['longtimewarning'] = '<b>Please note that this process can take a long time.</b>';
$string['maintenancemode'] = 'In maintenance mode';
Expand Down
28 changes: 28 additions & 0 deletions lib/javascript-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,34 @@ M.util.get_string = function(identifier, component, a) {
return stringvalue;
};

/**
* Set focus on username or password field of the login form
*/
M.util.focus_login_form = function(Y) {
var username = Y.one('#username');
var password = Y.one('#password');

if (username == null || password == null) {
// something is wrong here
return;
}

var curElement = document.activeElement
if (curElement == 'undefined') {
// legacy browser - skip refocus protection
} else if (curElement.tagName == 'INPUT') {
// user was probably faster to focus something, do not mess with focus
return;
}

if (username.get('value') == '') {
username.focus();
} else {
password.focus();
}
}


//=== old legacy JS code, hopefully to be replaced soon by M.xx.yy and YUI3 code ===

function checkall() {
Expand Down
4 changes: 4 additions & 0 deletions login/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@
echo $OUTPUT->box_end();
} else {
include("index_form.html");
if (!empty($CFG->loginpageautofocus)) {
//focus username or password
$PAGE->requires->js_init_call('M.util.focus_login_form', null, true);
}
}

echo $OUTPUT->footer();

0 comments on commit c5fe313

Please sign in to comment.