diff options
author | 2012-07-26 21:03:46 -0400 | |
---|---|---|
committer | 2012-07-26 21:03:46 -0400 | |
commit | f5ef46d01eb7bbaac45eec162267bcbf2500d511 (patch) | |
tree | 0e2fd9d872919d08f70d09d169d65d13c1305a6c /templates | |
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')
-rw-r--r-- | templates/longpolling.julius | 16 | ||||
-rw-r--r-- | templates/metarefresh.hamlet | 2 | ||||
-rw-r--r-- | templates/status.hamlet (renamed from templates/poll.hamlet) | 2 |
3 files changed, 13 insertions, 7 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 ); diff --git a/templates/metarefresh.hamlet b/templates/metarefresh.hamlet new file mode 100644 index 000000000..be22aa899 --- /dev/null +++ b/templates/metarefresh.hamlet @@ -0,0 +1,2 @@ +<noscript> + <meta http-equiv="refresh" content="#{delayseconds}; URL=@{home}"> diff --git a/templates/poll.hamlet b/templates/status.hamlet index fcdd705b6..1f975b35f 100644 --- a/templates/poll.hamlet +++ b/templates/status.hamlet @@ -1,2 +1,2 @@ -<div id="poll"> +<div id="#{poll}"> polled at #{time} |