got this JS working

This commit is contained in:
Joey Hess 2012-07-30 20:22:10 -04:00
parent 9b1ed7a720
commit 9648acc7a4
2 changed files with 26 additions and 31 deletions

View file

@ -13,29 +13,26 @@ connfailed=
' </div>' + ' </div>' +
'</div>' ; '</div>' ;
function longpoll(url, divid) { function longpoll(url, divid, cont) {
(function( $ ) { $.ajax({
$.ajax({ 'url': url,
'url': url, 'dataType': 'html',
'dataType': 'html', 'success': function(data, status, jqxhr) {
'success': function(data, status, jqxhr) { $('#' + divid).replaceWith(data);
$('#' + divid).replaceWith(data); connfails=0;
connfails=0; cont();
return 1; },
}, 'error': function(jqxhr, msg, e) {
'error': function(jqxhr, msg, e) { connfails=connfails+1;
connfails=connfails+1; if (connfails > 3) {
if (connfails > 3) { // blocked by many browsers
// blocked by many browsers window.close();
window.close(); $('#modal').replaceWith(connfailed);
$('#modal').replaceWith(connfailed); $('#modal').modal('show');
$('#modal').modal('show');
return 0;
}
else {
return 1;
}
} }
}); else {
})( jQuery ); cont();
}
}
});
} }

View file

@ -1,11 +1,9 @@
// longpolling for #{ident} // longpolling for #{ident}
function poller#{ident}() { function poller#{ident}() {
if (longpoll('@{gethtml}', '#{ident}')) { longpoll('@{gethtml}', '#{ident}', function() {
setTimeout(poller#{ident}, #{delay}); setTimeout(poller#{ident}, #{delay});
}
}
(function( $ ) {
$(document).bind('ready.app', function() {
setTimeout(poller#{ident}, #{startdelay});
}); });
})( jQuery ); }
$(function() {
setTimeout(poller#{ident}, #{startdelay});
});