summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2012-07-30 18:01:41 -0400
committerJoey Hess <joey@kitenet.net>2012-07-30 18:01:41 -0400
commit502bc5d5f84a26bfd2ca700d8f90d78a81c7b1ac (patch)
tree113863fb55a035b57ef912f01ad974b01a829423 /static
parentd1358cc96f2e719a90e2192a24e61c57ce9ed50c (diff)
rewrote longpolling, trying to avoid duplication
does not work though. stupid JS
Diffstat (limited to 'static')
-rw-r--r--static/longpolling.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/static/longpolling.js b/static/longpolling.js
new file mode 100644
index 0000000000..4e5f102f00
--- /dev/null
+++ b/static/longpolling.js
@@ -0,0 +1,41 @@
+// Uses long-polling to update a div with a specified id,
+// by polling an url, which should return a new div, with the same id.
+
+connfails=0;
+
+connfailed=
+ '<div id="modal" class="modal fade">' +
+ ' <div class="modal-header">' +
+ ' <h3>git-annex has shut down</h3>' +
+ ' </div>' +
+ ' <div class="modal-body">' +
+ ' You can now close this browser window.' +
+ ' </div>' +
+ '</div>' ;
+
+function longpoll(url, divid) {
+ (function( $ ) {
+ $.ajax({
+ 'url': url,
+ 'dataType': 'html',
+ 'success': function(data, status, jqxhr) {
+ $('#' + divid).replaceWith(data);
+ connfails=0;
+ return 1;
+ },
+ 'error': function(jqxhr, msg, e) {
+ connfails=connfails+1;
+ if (connfails > 3) {
+ // blocked by many browsers
+ window.close();
+ $('#modal').replaceWith(connfailed);
+ $('#modal').modal('show');
+ return 0;
+ }
+ else {
+ return 1;
+ }
+ }
+ });
+ })( jQuery );
+}