-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refresh shows a spinner and uses ajax poll with If-Modified-Since
- Loading branch information
Adam Wiggins
committed
Apr 14, 2009
1 parent
e7db3f4
commit 60f2c12
Showing
11 changed files
with
93 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div class="feed" id="feed_<%= feed.id %>"> | ||
<div class="header"> | ||
<div class="title"><%= feed.title %></div> | ||
<div class="subtitle"> | ||
<span class="last_updated"><%= time_ago_in_words(feed.updated_at) %> ago | </span> | ||
<span class="refresh"> | ||
<%= link_to_function "refresh", "refresh_feed(this)", | ||
:feed_id => feed.id, :last_modified => feed.updated_at %> | ||
</span> | ||
</div> | ||
</div> | ||
|
||
<div class="posts"> | ||
<% feed.posts.each do |post| %> | ||
<div><%= link_to post.title, post.url %></div> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render :partial => 'feed', :locals => { :feed => @feed } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,35 @@ | ||
// Place your application-specific JavaScript functions and classes here | ||
// This file is automatically included by javascript_include_tag :defaults | ||
function refresh_feed(link) { | ||
new Ajax.Request('/feeds/refresh/' + link.getAttribute('feed_id'), { method: 'get' }) | ||
spin_and_wait(link) | ||
} | ||
|
||
function refresh_all() { | ||
new Ajax.Request('/feeds/refresh_all', { method: 'get' }) | ||
$$('.feed .refresh a').each(function(link) { | ||
spin_and_wait(link) | ||
}) | ||
} | ||
|
||
function spin_and_wait(link) { | ||
link.addClassName('refreshing') | ||
poll_for_update(link.getAttribute('feed_id'), link.getAttribute('last_modified'), link) | ||
} | ||
|
||
function poll_for_update(feed_id, last_modified, link) { | ||
setTimeout(function() { | ||
new Ajax.Request('/feeds/' + feed_id, { | ||
method: 'get', | ||
requestHeaders: { 'If-Modified-Since': last_modified }, | ||
onComplete: function(transport) { | ||
if (transport.status == 204) { | ||
poll_for_update(feed_id, last_modified, link) | ||
} else if (transport.status == 200) { | ||
$('feed_' + feed_id).innerHTML = transport.responseText | ||
} else { | ||
link.innerHTML = 'error' | ||
} | ||
} | ||
}) }, | ||
1000 | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module Delayed | ||
class Worker | ||
SLEEP = 5 | ||
SLEEP = 1 | ||
|
||
cattr_accessor :logger | ||
self.logger = if defined?(Merb::Logger) | ||
|