diff --git a/browserid/static/dialog/controllers/dialog_controller.js b/browserid/static/dialog/controllers/dialog_controller.js index 9f0507b275c2c141b29e9ad2b1e306ed7b6b313b..676de02490c7747c608340b8bcda2b953809d24a 100644 --- a/browserid/static/dialog/controllers/dialog_controller.js +++ b/browserid/static/dialog/controllers/dialog_controller.js @@ -44,7 +44,8 @@ var bid = BrowserID, user = bid.User, - errors = bid.Errors; + errors = bid.Errors, + offline = false; PageController.extend("Dialog", {}, { init: function(el) { @@ -59,17 +60,23 @@ }, getVerifiedEmail: function(origin_url, onsuccess, onerror) { - this.onsuccess = onsuccess; - this.onerror = onerror; + var self=this; + + self.onsuccess = onsuccess; + self.onerror = onerror; + + if('onLine' in navigator && !navigator.onLine) { + self.doOffline(); + return; + } user.setOrigin(origin_url); // get the cleaned origin. $("#sitename").text(user.getHostname()); - this.doCheckAuth(); + self.doCheckAuth(); - var self=this; $(window).bind("unload", function() { self.doCancel(); }); @@ -82,6 +89,14 @@ el = this.element; + hub.subscribe("offline", function(msg, info) { + self.doOffline(); + }); + + hub.subscribe("xhrError", function(msg, info) { + self.doXHRError(info); + }); + hub.subscribe("user_staged", function(msg, info) { self.doConfirmUser(info.email); }); @@ -140,6 +155,15 @@ }, + doOffline: function() { + this.renderError(errors.offline); + offline = true; + }, + + doXHRError: function(info) { + if (!offline) this.renderError(errors.offline); + }, + doConfirmUser: function(email) { this.confirmEmail = email; diff --git a/browserid/static/dialog/resources/error-messages.js b/browserid/static/dialog/resources/error-messages.js index 860825d589d909dd7ac1b2290e64dc2d1d0f08c4..7064d82d9f4a1fdaaccd01341763679ab4a412e0 100644 --- a/browserid/static/dialog/resources/error-messages.js +++ b/browserid/static/dialog/resources/error-messages.js @@ -78,6 +78,12 @@ BrowserID.Errors = (function(){ message: "An error was encountered while signing you out. Yucky!" }, + offline: { + type: "networkError", + title: "You are offline!", + message: "Unfortunately, BrowserID cannot communicate while offline!" + }, + registration: { type: "serverError", title: "Registration Failed",