Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cogumm committed Nov 5, 2010
0 parents commit 7a92bd7
Show file tree
Hide file tree
Showing 10 changed files with 466 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config.ru
@@ -0,0 +1,2 @@
require 'tracks'
run Sinatra::Application
Binary file added public/images/blank.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/urele.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
235 changes: 235 additions & 0 deletions public/jquery.livetwitter.js
@@ -0,0 +1,235 @@
/*
* jQuery LiveTwitter 1.5.2
* - Live updating Twitter plugin for jQuery
*
* Copyright (c) 2009-2010 Inge Jørgensen (elektronaut.no)
* Licensed under the MIT license (MIT-LICENSE.txt)
*
* $Date: 2010/07/16$
*/

/*
* Usage example:
* $("#twitterSearch").liveTwitter('bacon', {limit: 10, rate: 15000});
*/

(function($){
if(!$.fn.reverse){
$.fn.reverse = function() {
return this.pushStack(this.get().reverse(), arguments);
};
}
$.fn.liveTwitter = function(query, options, callback){
var domNode = this;
$(this).each(function(){
var settings = {};

// Handle changing of options
if(this.twitter) {
settings = jQuery.extend(this.twitter.settings, options);
this.twitter.settings = settings;
if(query) {
this.twitter.query = query;
}
this.twitter.limit = settings.limit;
this.twitter.mode = settings.mode;
if(this.twitter.interval){
this.twitter.refresh();
}
if(callback){
this.twitter.callback = callback;
}

// ..or create a new twitter object
} else {
// Extend settings with the defaults
settings = jQuery.extend({
mode: 'search', // Mode, valid options are: 'search', 'user_timeline'
rate: 15000, // Refresh rate in ms
limit: 10, // Limit number of results
refresh: true
}, options);

// Default setting for showAuthor if not provided
if(typeof settings.showAuthor == "undefined"){
settings.showAuthor = (settings.mode == 'user_timeline') ? false : true;
}

// Set up a dummy function for the Twitter API callback
if(!window.twitter_callback){
window.twitter_callback = function(){return true;};
}

this.twitter = {
settings: settings,
query: query,
limit: settings.limit,
mode: settings.mode,
interval: false,
container: this,
lastTimeStamp: 0,
callback: callback,

// Convert the time stamp to a more human readable format
relativeTime: function(timeString){
var parsedDate = Date.parse(timeString);
var delta = (Date.parse(Date()) - parsedDate) / 1000;
var r = '';
if (delta < 60) {
r = delta + ' seconds ago';
} else if(delta < 120) {
r = 'a minute ago';
} else if(delta < (45*60)) {
r = (parseInt(delta / 60, 10)).toString() + ' minutos atr&aacute;s';
} else if(delta < (90*60)) {
r = 'an hour ago';
} else if(delta < (24*60*60)) {
r = '' + (parseInt(delta / 3600, 10)).toString() + ' horas atr&aacute;s';
} else if(delta < (48*60*60)) {
r = 'a day ago';
} else {
r = (parseInt(delta / 86400, 10)).toString() + ' dias atr&aacute;s';
}
return r;
},

// Update the timestamps in realtime
refreshTime: function() {
var twitter = this;
$(twitter.container).find('span.time').each(function(){
$(this).find('a').html(twitter.relativeTime(this.timeStamp));
});
},

// Handle reloading
refresh: function(initialize){
var twitter = this;
if(this.settings.refresh || initialize) {
var url = '';
var params = {};
if(twitter.mode == 'search'){
params.q = this.query;

if(this.settings.geocode){
params.geocode = this.settings.geocode;
}
if(this.settings.lang){
params.lang = this.settings.lang;
}
if(this.settings.rpp){
params.rpp = this.settings.rpp;
} else {
params.rpp = this.settings.limit;
}

// Convert params to string
var paramsString = [];
for(var param in params){
if(params.hasOwnProperty(param)){
paramsString[paramsString.length] = param + '=' + encodeURIComponent(params[param]);
}
}
paramsString = paramsString.join("&");
url = "http://search.twitter.com/search.json?"+paramsString+"&callback=?";
} else if(twitter.mode == 'user_timeline') {
url = "http://api.twitter.com/1/statuses/user_timeline/"+encodeURIComponent(this.query)+".json?count="+twitter.limit+"&callback=?";
} else if(twitter.mode == 'list') {
var username = encodeURIComponent(this.query.user);
var listname = encodeURIComponent(this.query.list);
url = "http://api.twitter.com/1/"+username+"/lists/"+listname+"/statuses.json?per_page="+twitter.limit+"&callback=?";
}
$.getJSON(url, function(json) {
var results = null;
if(twitter.mode == 'search'){
results = json.results;
} else {
results = json;
}
var newTweets = 0;
$(results).reverse().each(function(){
var screen_name = '';
var profile_image_url = '';
if(twitter.mode == 'search') {
screen_name = this.from_user;
profile_image_url = this.profile_image_url;
created_at_date = this.created_at;
} else {
screen_name = this.user.screen_name;
profile_image_url = this.user.profile_image_url;
// Fix for IE
created_at_date = this.created_at.replace(/^(\w+)\s(\w+)\s(\d+)(.*)(\s\d+)$/, "$1, $3 $2$5$4");
}
var tweet_url = 'http://twitter.com/'+screen_name+'/statuses/'+this.id;
var userInfo = this.user;
var linkified_text = this.text.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/, function(m) { return m.link(m); });
linkified_text = linkified_text.replace(/@[A-Za-z0-9_]+/g, function(u){return u.link('http://twitter.com/'+u.replace(/^@/,''));});
linkified_text = linkified_text.replace(/#[A-Za-z0-9_\-]+/g, function(u){return u.link('http://search.twitter.com/search?q='+u.replace(/^#/,'%23'));});

if(!twitter.settings.filter || twitter.settings.filter(this)) {
if(Date.parse(created_at_date) > twitter.lastTimeStamp) {
newTweets += 1;
var tweetHTML = '<div class="tweet tweet-'+this.id+'">';
if(twitter.settings.showAuthor) {
tweetHTML +=
'<img width="24" height="24" src="'+profile_image_url+'" />' +
'<p class="text"><span class="username"><a href="http://twitter.com/'+screen_name+'">'+screen_name+'</a>:</span> ';
} else {
tweetHTML +=
'<p class="text"> ';
}
tweetHTML +=
linkified_text +
' <span class="time"><a href="'+tweet_url+'">'+twitter.relativeTime(created_at_date)+'</a></span>' +
'</p>' +
'</div>';
$(twitter.container).prepend(tweetHTML);
var timeStamp = created_at_date;
$(twitter.container).find('span.time:first').each(function(){
this.timeStamp = timeStamp;
});
if(!initialize) {
$(twitter.container).find('.tweet-'+this.id).hide().fadeIn();
}
twitter.lastTimeStamp = Date.parse(created_at_date);
}
}
});
if(newTweets > 0) {
// Limit number of entries
$(twitter.container).find('div.tweet:gt('+(twitter.limit-1)+')').remove();
// Run callback
if(twitter.callback){
twitter.callback(domNode, newTweets);
}
// Trigger event
$(domNode).trigger('tweets');
}
});
}
},
start: function(){
var twitter = this;
if(!this.interval){
this.interval = setInterval(function(){twitter.refresh();}, twitter.settings.rate);
this.refresh(true);
}
},
stop: function(){
if(this.interval){
clearInterval(this.interval);
this.interval = false;
}
},
clear: function(){
$(this.container).find('div.tweet').remove();
this.lastTimeStamp = null;
}
};
var twitter = this.twitter;
this.timeInterval = setInterval(function(){twitter.refreshTime();}, 5000);
this.twitter.start();
}
});
return this;
};
})(jQuery);
1 change: 1 addition & 0 deletions public/jquery.livetwitter.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions public/style.css
@@ -0,0 +1,86 @@
* {margin:0; padding:0;}
body {
background:#000 url("/images/bg-wooddy.jpg") repeat-x left top;
font:16px/1.4em Arial, sans-serif;
color:#000;
text-align:center;
}
h2 {
color:#fff;
margin-top:40px;
font-family:Helvetica, Arial, sans-serif;
font-size:24px;
font-weight:bold;
}
#page {
width:900px;
margin:0 auto;
text-align:left;
}
#top {
background:url("/images/top.jpg") center top no-repeat;
height:175px;
padding:50px 70px 0;
}
#top h1 {
margin:0 auto;
width:171px;
}
.tracka, .trackb {
color:#7d0000;
float:left;
font-size:2.3em;
font-weight:bold;
line-height:1em;
position:relative;
top:-60px;
text-shadow:0 2px 2px #999999;
width:38%;
}
.trackb {
margin-left:172px;
text-align:right;
}
a, a:visited {
color:#ffae30;
}
a:hover {
color:#ff7e00;
}
.tweet {
margin:4px 0;
width:400px;
padding:12px;
color:#fff;
border-bottom:1px solid #555;
overflow:hidden;
}
.tweet img {
float:left;
margin:0 8px 4px 0;
width:48px;
height:48px;
border:1px solid #888;
}
.tweet .text {
margin:0;
padding-bottom:10px;
float:right;
width:330px;
}
.tweet .time a {
font-size:80%;
color:#888;
white-space:nowrap;
text-decoration:none;
}
.tweet .time a:hover {
text-decoration:underline;
}
.twitterTracker {
float:left;
margin-top:-45px;
}
.twitterTracker.A {
margin-right:48px;
}
10 changes: 10 additions & 0 deletions tracks.rb
@@ -0,0 +1,10 @@
require 'rubygems'
require 'sinatra'

get "/" do
erb :show_info
end

get "/:tracka/:trackb" do
erb :show
end

0 comments on commit 7a92bd7

Please sign in to comment.