Skip to content

Instantly share code, notes, and snippets.

@jonDowdle
Created April 17, 2009 14:40
Show Gist options
  • Select an option

  • Save jonDowdle/97064 to your computer and use it in GitHub Desktop.

Select an option

Save jonDowdle/97064 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "show-tweets",
homepage: "http://www.jdowdle.com/",
author: { name: "Jon Dowdle", email: "[email protected]" },
license: "MPL",
_userSelection: function(input){
var userSelection = input ? input:CmdUtils.getSelection();
return userSelection;
},
_getSearchUrl: function( action ){
var baseUrl = 'http://search.twitter.com/search.json?';
switch(action){
case 'geocode':
return baseUrl + 'geocode=';
break;
}
},
_fetchTweets: function( locationObj ){
var location = locationObj[0];
var distance = '5km';
var geocodeVal = encodeURIComponent( location.lat + "," + location.long + ',' + distance);
var searchUrl = 'http://search.twitter.com/search.json?geocode=' + geocodeVal;
jQuery.getJSON(searchUrl, function(d,s){ _showTweets(d, s) });
},
takes: {
"location": noun_arb_text
},
modifiers: { "about":noun_arb_text },
preview: function( previewBlock, usrInput, hashtag ){
var msg = 'Shows posts to Twitter near: ';
previewBlock.innerHTML = msg + this._userSelection(usrInput.text);
},
execute: function( usrInput, hashtag ){
CmdUtils.geocodeAddress( this._userSelection(usrInput.text) , this._fetchTweets );
//displayMessage("No on has tweeted near " + this._userSelection() + ". Watch out for zombies!");
}
});
CmdUtils.CreateCommand({
name: "search-tweets",
homepage: "http://www.jdowdle.com/",
author: { name: "Jon Dowdle", email: "[email protected]" },
license: "MPL",
_userSelection: function(input){
var userSelection = input ? input:CmdUtils.getSelection();
return userSelection;
},
_fetchTweets: function( qry ){
var searchUrl = 'http://search.twitter.com/search.json?q=' + encodeURIComponent(qry);
jQuery.getJSON(searchUrl, function(d,s){ _showTweets(d, s) });
},
takes: {
"search string": noun_arb_text
},
preview: function( previewBlock, usrInput){
var msg = 'Shows posts to Twitter about: ';
previewBlock.innerHTML = msg + this._userSelection(usrInput.text);
},
execute: function( usrInput){
this._fetchTweets( this._userSelection(usrInput.text) );
}
});
function _showTweets(jsonData, status){
CmdUtils.log('In showTweets');
var doc = CmdUtils.getDocument();
jQuery(doc.body).find('#ubiq-twitter').empty();
var $holder = jQuery('<ul/>').attr('id', 'ubiq-twitter');
$holder.css({
position:'fixed',
bottom:'0px', right:'0px',
width:'275px', height: '75px',
backgroundColor:'lightBlue',
listStyle:'none', cursor:'pointer',
margin:'0',
padding:'15px'
});
$holder.css('-moz-border-radius', '5px');
CmdUtils.log(jsonData.results);
if( jQuery(doc.body).find('#ubiq-twitter').length > 0 ){
$holder.remove();
jQuery(doc.body).append($holder);
}else{
jQuery(doc.body).append($holder);
}
jQuery.each(jsonData.results.slice(0,5), function(i, tweet){
var $img = jQuery('<img />');
var $li = jQuery('<li />');
var $div = jQuery('<div />');
CmdUtils.log(tweet);
$img.css(
{
'-moz-border-radius':'3px',
padding: '5px', margin: '0 8px 5px 0',
border: '1px solid #333',
width: '45px', height:'45px',
backgroundColor: 'white',
float: 'left'
});
$img.attr('src', tweet.profile_image_url);
$li.prepend(tweet.text);
$li.prepend($img);
$li.hide();
$li.queue( function(){
jQuery(this).fadeIn(500, function(){
jQuery(this).fadeOut(2000, function(){
if(jQuery(this).next().dequeue().length == 0){
$holder.fadeOut();
}
});
} );
});
$li.click(function(){
var user = tweet.from_user;
var updateId= tweet.id;
var url = "http://twitter.com/" + user + "/status/" + updateId;
Utils.openUrlInBrowser(url);
});
$holder.append($li);
});
if(jsonData.results.length > 0){
$holder.show();
$holder.find('li:first').dequeue();
}else{
$holder.text('No tweets found');
$holder.fadeOut(3000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment