From 8b6181199d048553ac26862fb78222b5e608bffa Mon Sep 17 00:00:00 2001 From: Darren Date: Mon, 8 Oct 2012 11:01:24 +0100 Subject: [PATCH] Window clsoe confirmation if connected --- client_backbone/dev/model_gateway.js | 9 ++++++++- client_backbone/dev/view.js | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/client_backbone/dev/model_gateway.js b/client_backbone/dev/model_gateway.js index 8cd3e87..f0657ad 100755 --- a/client_backbone/dev/model_gateway.js +++ b/client_backbone/dev/model_gateway.js @@ -63,7 +63,8 @@ kiwi.model.Gateway = function () { 'try multiple transports': true, 'connect timeout': 3000, 'max reconnection attempts': 7, - 'reconnection delay': 2000 + 'reconnection delay': 2000, + 'sync disconnect on unload': false }); this.socket.on('connect_failed', function (reason) { // TODO: When does this even actually get fired? I can't find a case! ~Darren @@ -129,6 +130,12 @@ kiwi.model.Gateway = function () { }; + + this.isConnected = function () { + return this.socket.socket.connected; + }; + + /* Events: msg diff --git a/client_backbone/dev/view.js b/client_backbone/dev/view.js index 717d9bf..8e10785 100755 --- a/client_backbone/dev/view.js +++ b/client_backbone/dev/view.js @@ -867,6 +867,13 @@ kiwi.view.Application = Backbone.View.extend({ this.doLayout(); $(document).keydown(this.setKeyFocus); + + // Confirmation require to leave the page + window.onbeforeunload = function () { + if (kiwi.gateway.isConnected()) { + return 'This will close all KiwiIRC conversations. Are you sure you want to close this window?'; + } + }; }, -- 2.25.1