Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Created April 27, 2020 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kou1okada/0fedcdc1120330096a0ddc708d271c96 to your computer and use it in GitHub Desktop.
Save kou1okada/0fedcdc1120330096a0ddc708d271c96 to your computer and use it in GitHub Desktop.
Moodle 2: Login: Auto focus username

Usage

Load below code at /login/index.php.

<script src="Moodle2LoginAutoFocusUsername.js"></script>

or

<script>
// Copy and paste the content of `Moodle2LoginAutoFocusUsername.js` here.
</script>
/**
* Moodle 2: Login: Auto focus username
*/
(function(){
function focus_to_username() {
if (!location.href.match('/login/(index\.php)?$')) return;
let e = document.getElementById("username");
if (e) e.focus();
}
function onDOMContentLoaded(f) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', f);
} else {
f();
}
}
onDOMContentLoaded(focus_to_username);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment