X-Git-Url: https://git.distorted.org.uk/~mdw/chopwood/blobdiff_plain/a2916c0635fec5b45ad742904db9f5769b48f53d..HEAD:/chpwd.js diff --git a/chpwd.js b/chpwd.js index 9ad74ad..f771d65 100644 --- a/chpwd.js +++ b/chpwd.js @@ -64,10 +64,15 @@ var FORMS = {}; * submitting a form with invalid data. */ +function update(obj, slot, value) { + /* Update an object slot only if we're gping to change its value. */ + if (obj[slot] !== value) obj[slot] = value; +} + function check() { /* Check through the various forms to make sure they're filled in OK. If - * not, set the `F-whinge' elements, and disable `F-submit'. - */ + * not, set the `F-whinge' elements, and disable `F-submit'. + */ var f, form, whinge; for (f in FORMS) { @@ -75,10 +80,10 @@ function check() { we = elt(f + '-whinge'); sb = elt(f + '-submit'); whinge = form.check(); - if (sb !== null) sb.disabled = (whinge !== null); + if (sb !== null) update(sb, 'disabled', whinge !== null); if (we !== null) { - we.textContent = whinge || 'OK'; - we.className = whinge === null ? 'whinge' : 'whinge wrong'; + update(we, 'textContent', whinge || 'OK'); + update(we, 'className', whinge === null ? 'whinge' : 'whinge wrong'); } } @@ -130,19 +135,19 @@ function init() { // properly. for (w in form.elts) { if ((e = elt(f + '-' + form.elts[w])) === null) continue; - e.addEventListener('click', check_soon); - e.addEventListener('change', check_soon); - e.addEventListener('keypress', check_soon); - e.addEventListener('blur', check_soon); + e.addEventListener('click', check_soon, false); + e.addEventListener('change', check_soon, false); + e.addEventListener('keypress', check_soon, false); + e.addEventListener('blur', check_soon, false); } if ((e = elt(f + '-submit')) !== null) { e.addEventListener('click', function (ev) { return check_presubmit(ev, f) - }); + }, false); } })(f, FORMS[f]); } -window.addEventListener('load', init); +window.addEventListener('load', init, false); /*----- That's all, folks -------------------------------------------------*/