by aherrick
29. September 2008 15:06
I was looking for an easy solution to add Twitter to my blog, and decide to write a class extension to fit my needs. With input from Fence Row Productions I came up with a class to easily grab your most recent tweet and display it on your blog. The code will parse Twitter API to display your most recent Tweet.
Check out how I am currently using it.
Added two ASP.NET label controls "lblTweet" and "lblTweetInfo." Also added an image control "imgTweet."
Here is my current code behind file for my MasterPage. The class constructor is your Twitter login name (twitter.com/you)
imgTweet.ImageUrl = "~/pics/twitter_bird_32.png";
Twitter t = new Twitter("andrew_herrick");
this.lblTweet.Text = t.TweetStatus;
this.lblTweetInfo.Text =
string.Format("<a href='{0}' target='NEW'>{1}</a> from {2}.",
t.TweetURL, t.TweetDateDiff, t.TweetSource);
Attached is the complete class. Let me know how it goes and enjoy!
Twitter.cs (4.65 kb)
1035ce83-c466-4359-889d-f7db1278f146|3|4.3
Tags: c#
by aherrick
5. September 2008 04:21
I was working on my Twitter extension to display my most recent tweet and I wanted to display how long ago I tweeted. I was able to acquire some code which I tweaked a bit to fit my needs. Check it out!
This method accepts two dates that you want to compare. For example: In my case, date1 is "DateTime.Now" and date2 is the Tweet date (whenever my most recent tweet was). I will have a full post on the twitter extension you see above soon!
Take a look at the code below!
private string GetDifferenceDate(DateTime date1, DateTime date2)
{
if (DateTime.Compare(date1, date2) >= 0)
{
TimeSpan ts = date1.Subtract(date2);
// if more than 1 day ago
if (ts.Days > 0)
return string.Format("{0} days, {1} hours, {2} minutes",
ts.Days, ts.Hours, ts.Minutes);
else
return string.Format("{0} hours, {1} minutes", ts.Hours, ts.Minutes);
}
else
return "Not valid";
}
3cf90c33-742a-49a9-9367-4ae46a9d97bc|1|4.0
Tags: c#
by aherrick
2. September 2008 11:25
The other day we had a request from a client to provide a rollover effect to display data. They only wanted it to display when a text area was hovered. One of my coworkers and I came up with a solution that fit our needs. I tweaked it a bit from using a DIV to using links and span tags. This makes it more flexible. Here is what I came up with. This solution that is cross-browser compatible.
HTML
CSS
First I start by setting up the link. The point of setting the z-index is to make sure the "popup" effect floats above all other elements on the page.
I am made two classes, rollover for the link and tooltip for the text to show. This will distinguish between other a link and span tag attributes on the page.
Initially the span tooltip is set to not display. The final part of the CSS is what the span tag looks like when the link is hovered. This is where there is a lot of flexibilty on how you want your tooltip to look. I positioned the tooltip absolute based on the relative position of the link.
I played with the colors and padding to come up with something I liked. This can be changed to fit your sites needs of course.
Here is the full code for your enjoyment!
PureCSSRolloverPopupEffect.zip (2.28 kb)