Screen.Login = function(modules) { var root = document.getElementById('login'); var join = document.getElementById("join"); var submit = root.submitButton; init(); return {}; function init() { initDOMEvents(); initMessageHandlers(); var name = modules.save.get('player.name'); if(name != undefined && name.length > 0) { root.you.value = name; formDisable(false); } } function initDOMEvents() { root.addEventListener('submit', function(e) { e.preventDefault(); modules.session.start(root.you.value); }); } function initMessageHandlers() { modules.messaging.addEventListener(["LogIn"], function(o) { if(modules.session.is(o.from)) { modules.screen.select('hall'); } }); modules.messaging.addEventListener('open', function() {formDisable(false);}); modules.messaging.addEventListener('close', function() {formDisable(true);}); } function formDisable(disabled) { [submit, root.name].forEach(function(button) { button.disabled = disabled || !modules.messaging.isOn(); }); } }