From 1160f39cb0fcd8e05508a9dedc65142c8fc1cf74 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 28 Sep 2013 22:05:10 -0400 Subject: [PATCH] revamped reconnection notification, closes #354 --- public/language/en/footer.json | 3 -- public/src/app.js | 47 +++++++------------------------ public/templates/footer.tpl | 16 ----------- public/templates/header.tpl | 4 +++ public/themes/vanilla/header.less | 16 +++++++++++ 5 files changed, 30 insertions(+), 56 deletions(-) diff --git a/public/language/en/footer.json b/public/language/en/footer.json index 2655ac2795..91cb43fb42 100644 --- a/public/language/en/footer.json +++ b/public/language/en/footer.json @@ -1,7 +1,4 @@ { - "disconnect.title": "Socket Disconnect", - "disconnect.message": "Looks like you disconnected, try reloading the page.", - "disconnect.reload_button": "Reload", "chat.chatting_with": "Chat with ", "chat.placeholder": "type chat message, here press enter to send", "chat.send": "Send", diff --git a/public/src/app.js b/public/src/app.js index c3376caf65..e0acf14152 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -23,8 +23,8 @@ var socket, } else { socket = io.connect(config.socket.address); - var reconnecting = false; - var reconnectTries = 0; + var reconnecting = false, + reconnectEl, reconnectTimer; socket.on('event:connect', function (data) { app.username = data.username; @@ -40,17 +40,12 @@ var socket, socket.on('connect', function (data) { if (reconnecting) { - setTimeout(function () { - app.alert({ - alert_id: 'connection_alert', - title: 'Connected', - message: 'Connection successful.', - type: 'success', - timeout: 5000 - }); - }, 1000); + reconnectEl.html(' Connected!'); reconnecting = false; - reconnectTries = 0; + + setTimeout(function() { + reconnectEl.removeClass('active'); + }, 3000); } socket.emit('api:updateHeader', { @@ -63,33 +58,11 @@ var socket, }); socket.on('reconnecting', function (data) { - function showDisconnectModal() { - $('#disconnect-modal').modal({ - backdrop: 'static', - show: true - }); - - $('#reload-button').on('click', function () { - $('#disconnect-modal').modal('hide'); - window.location.reload(); - }); - } - + if (!reconnectEl) reconnectEl = $('#reconnect'); reconnecting = true; - reconnectTries++; - if (reconnectTries > 4) { - showDisconnectModal(); - return; - } - - app.alert({ - alert_id: 'connection_alert', - title: 'Reconnecting', - message: 'You have disconnected from NodeBB, we will try to reconnect you.
', - type: 'warning', - timeout: 5000 - }); + reconnectEl.addClass('active'); + reconnectEl.html(' Reconnecting...'); }); socket.on('api:user.get_online_users', function (users) { diff --git a/public/templates/footer.tpl b/public/templates/footer.tpl index ea47c97d86..38b4614a79 100644 --- a/public/templates/footer.tpl +++ b/public/templates/footer.tpl @@ -2,22 +2,6 @@ - -