Skip to content
This repository has been archived by the owner on Feb 12, 2019. It is now read-only.

added ability to pass cached tweets (raw json from twitter api) #376

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions tweet/jquery.tweet.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
},
filter: function(tweet) { // [function] whether or not to include a particular tweet (be sure to also set 'fetch')
return true;
}
},
cached_tweets: null
// You can attach callbacks to the following events using jQuery's standard .bind() mechanism:
// "loaded" -- triggered when tweets have been fetched and rendered
}, o);
Expand Down Expand Up @@ -233,13 +234,24 @@
}

function load(widget) {
var loading = $('<p class="loading">'+s.loading_text+'</p>');
if (s.loading_text) $(widget).not(":has(.tweet_list)").empty().append(loading);
$.getJSON(build_api_url(), function(data){
var tweets = $.map(data.statuses || data, extract_template_data);
var use_tweets_json = function (data) {
var tweets = $.map(data, extract_template_data);
tweets = $.grep(tweets, s.filter).sort(s.comparator).slice(0, s.count);
$(widget).trigger("tweet:retrieved", [tweets]);
});
};

var loading = $('<p class="loading">'+s.loading_text+'</p>');
if (s.loading_text) $(widget).not(":has(.tweet_list)").empty().append(loading);

if (s.cached_tweets !== null) {
// Use preloaded tweets for speed.
use_tweets_json(s.cached_tweets);
// But use them only once.
// Each next time 'load' is called the tweets will be fetched.
s.cached_tweets = null;
} else {
$.getJSON(build_api_url(), use_tweets_json);
}
}

return this.each(function(i, widget){
Expand Down