From d3413ee5a98367bc2f3c56011db8c9393306d80b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 30 Jul 2012 20:33:23 -0400 Subject: [PATCH] further refactoring my js --- static/longpolling.js | 17 ++--------------- templates/longpolling.julius | 7 ++++--- templates/page.julius | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 templates/page.julius diff --git a/static/longpolling.js b/static/longpolling.js index 75c6faeaf3..5b704acec3 100644 --- a/static/longpolling.js +++ b/static/longpolling.js @@ -3,17 +3,7 @@ connfails=0; -connfailed= - '' ; - -function longpoll(url, divid, cont) { +function longpoll(url, divid, cont, fail) { $.ajax({ 'url': url, 'dataType': 'html', @@ -25,10 +15,7 @@ function longpoll(url, divid, cont) { 'error': function(jqxhr, msg, e) { connfails=connfails+1; if (connfails > 3) { - // blocked by many browsers - window.close(); - $('#modal').replaceWith(connfailed); - $('#modal').modal('show'); + fail(); } else { cont(); diff --git a/templates/longpolling.julius b/templates/longpolling.julius index d34d5b47d8..520699cd73 100644 --- a/templates/longpolling.julius +++ b/templates/longpolling.julius @@ -1,8 +1,9 @@ // longpolling for #{ident} function poller#{ident}() { - longpoll('@{gethtml}', '#{ident}', function() { - setTimeout(poller#{ident}, #{delay}); - }); + longpoll('@{gethtml}', '#{ident}' + , function() { setTimeout(poller#{ident}, #{delay}); } + , function() { webapp_disconnected(); } + ); } $(function() { setTimeout(poller#{ident}, #{startdelay}); diff --git a/templates/page.julius b/templates/page.julius new file mode 100644 index 0000000000..a9d0b42239 --- /dev/null +++ b/templates/page.julius @@ -0,0 +1,17 @@ +connfailed = + '' ; + +function webapp_disconnected () { + $('#modal').replaceWith(connfailed); + $('#modal').modal('show'); + + // ideal, but blocked by many browsers + window.close(); +}