Skip to content
Snippets Groups Projects
Commit 7cb92694 authored by Shane Tomlinson's avatar Shane Tomlinson
Browse files

Add a small delay after an xhr request is complete before submit_disabled...

Add a small delay after an xhr request is complete before submit_disabled class is removed from the body.  This helps to reduce the flicker users see when email addresses are being checked and there are consecutive XHR requests.

issue #1898
parent 75451402
No related branches found
No related tags found
No related merge requests found
......@@ -15,8 +15,17 @@ BrowserID.Modules.XHRDisableForm = (function() {
self.subscribe("xhr_start",
dom.addClass.curry("body", "submit_disabled"));
self.subscribe("xhr_complete",
dom.removeClass.curry("body", "submit_disabled"));
self.subscribe("xhr_complete", function() {
// Add a small delay between the time the XHR is complete and when the
// submit_disabled class is actually removed. This helps reduce the
// amount of flicker the user sees if one XHR request completes and
// another one starts immediately afterwards.
// See https://github.com/mozilla/browserid/issues/1898
setTimeout(function() {
dom.removeClass("body", "submit_disabled");
self.publish("submit_enabled");
}, 100);
});
sc.start.call(self, options);
}
......
......@@ -29,13 +29,19 @@
}
});
test("xhr_start adds 'submit_disabled' to class, xhr_complete removes it", function() {
asyncTest("xhr_start adds 'submit_disabled' to class, xhr_complete removes it", function() {
var body = $("body");
mediator.publish("xhr_start");
equal(body.hasClass("submit_disabled"), true, "xhr_start adds submit_disabled");
// submit_disabled is removed after a small delay so that if consecutive
// XHR requests happen, there is no button flicker. See issue #1898
// - https://github.com/mozilla/browserid/issues/1898
mediator.subscribe("submit_enabled", function() {
equal(body.hasClass("submit_disabled"), false, "xhr_complete removes submit_disabled");
start();
});
mediator.publish("xhr_complete");
equal(body.hasClass("submit_disabled"), false, "xhr_complete removes submit_disabled");
});
}());
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment