better connection close handling

Depending on how the webapp was started up and whether the user clicked on
any links in it, window.close() may be disallowed by browser security
policy. Also if that fails, display a modal dialog that nicely blackens out
the webapp.

TODO: avoid Escape closing it. Bootstrap's docs are unclear about how to do
that.
This commit is contained in:
Joey Hess 2012-07-30 14:50:32 -04:00
parent a994130843
commit 78b3dada5b
4 changed files with 224 additions and 7 deletions

View file

@ -5,9 +5,9 @@
// Maximum update frequency is controlled by #{startdelay}
// and #{delay}, both in milliseconds.
(function( $ ) {
$dead=0;
numerrs=0;
(function( $ ) {
$.LongPoll#{ident} = (function() {
return {
@ -21,12 +21,11 @@ $.LongPoll#{ident} = (function() {
numerrs=0;
},
'error': function(jqxhr, msg, e) {
numerrs=numerrs+1;
if (numerrs > 3) {
if (! $dead) {
$dead=1;
// blocked by many browsers
window.close();
}
else {
setTimeout($.LongPoll#{ident}.send, #{show delay});
$('#lostconnection').modal('show');
}
},
});

View file

@ -21,3 +21,10 @@
<div .container-fluid>
<div .row-fluid>
^{content}
<div #lostconnection .modal .fade>
<div .modal-header>
<h3>
git-annex has shut down
<div .modal-body>
<p>
You can now close this browser window.