![Joey Hess](/assets/img/avatar_default.png)
Very happy to have a reusable autoUpdate widget that can make any Yesod widget automatically refresh! Also added support for non-javascript browsers, falling back to meta refresh. Also, the home page is now rendered with the webapp status on it, before any refreshing is done.
29 lines
633 B
Text
29 lines
633 B
Text
|
|
// Uses long-polling to update a div with id=#{poll}
|
|
// 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( $ ) {
|
|
|
|
$.LongPoll = (function() {
|
|
return {
|
|
send : function() {
|
|
$.ajax({
|
|
'url': '@{gethtml}',
|
|
'dataType': 'html',
|
|
'success': function(data, status, jqxhr) {
|
|
$('##{poll}').replaceWith(data);
|
|
setTimeout($.LongPoll.send, #{delay});
|
|
},
|
|
});
|
|
}
|
|
}
|
|
}());
|
|
|
|
$(document).bind('ready.app', function() {
|
|
setTimeout($.LongPoll.send, #{startdelay});
|
|
});
|
|
|
|
})( jQuery );
|