git-annex/templates/longpolling.julius
Joey Hess 62dac85880 update the sidebar by long polling
Needs to use a different NotificationBroadcaster, and not replace the
whole sidebar div, but instead add in new content. However, it's 3:30 am.
2012-07-29 03:23:17 -04:00

41 lines
897 B
Text

// Uses long-polling to update a div with id=#{ident}
// The gethtml route should return a new div, with the same id.
//
// Maximum update frequency is controlled by #{startdelay}
// and #{delay}, both in milliseconds.
(function( $ ) {
numerrs=0;
$.LongPoll#{ident} = (function() {
return {
send : function() {
$.ajax({
'url': '@{gethtml}',
'dataType': 'html',
'success': function(data, status, jqxhr) {
$('##{ident}').replaceWith(data);
setTimeout($.LongPoll#{ident}.send, #{show delay});
numerrs=0;
},
'error': function(jqxhr, msg, e) {
numerrs=numerrs+1;
if (numerrs > 3) {
window.close();
}
else {
setTimeout($.LongPoll#{ident}.send, #{show delay});
}
},
});
}
}
}());
$(document).bind('ready.app', function() {
setTimeout($.LongPoll#{ident}.send, #{show startdelay});
});
})( jQuery );