diff options
author | 2012-07-26 21:03:46 -0400 | |
---|---|---|
committer | 2012-07-26 21:03:46 -0400 | |
commit | f5ef46d01eb7bbaac45eec162267bcbf2500d511 (patch) | |
tree | 0e2fd9d872919d08f70d09d169d65d13c1305a6c /templates/longpolling.julius | |
parent | 9b2eec2e7af34e107bcb438a501286996fe0eb41 (diff) |
cleaned up refreshing code into a widget
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.
Diffstat (limited to 'templates/longpolling.julius')
-rw-r--r-- | templates/longpolling.julius | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/templates/longpolling.julius b/templates/longpolling.julius index 38ecbc77d..26356f5e9 100644 --- a/templates/longpolling.julius +++ b/templates/longpolling.julius @@ -1,5 +1,9 @@ -// Uses long-polling to update a div with id=poll. -// The PollR route should return a new div, also with id=poll. + +// 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( $ ) { @@ -7,11 +11,11 @@ $.LongPoll = (function() { return { send : function() { $.ajax({ - 'url': '@{PollR}', + 'url': '@{gethtml}', 'dataType': 'html', 'success': function(data, status, jqxhr) { - $('#poll').replaceWith(data); - setTimeout($.LongPoll.send, 3000); + $('##{poll}').replaceWith(data); + setTimeout($.LongPoll.send, #{delay}); }, }); } @@ -19,7 +23,7 @@ $.LongPoll = (function() { }()); $(document).bind('ready.app', function() { - setTimeout($.LongPoll.send, 40); + setTimeout($.LongPoll.send, #{startdelay}); }); })( jQuery ); |