Victus Spiritus


Javascript Twitter Realtime Search Widget

18 Jan 2010

Part of Social Gravity, a new interface we're building for social data, relies on a clean search portal to track entities/hashtags. After browsing through several remote scripts options I decided on the offical Twitter search widget which is functional, branded, but limited in how much we can adapt it. The alternative was modifying a simple but easy to understand script example, the jquery Twitter ticker. Our baseline is the official Twitter widget code, while I explore what can be done with the raw JavaScript interface to the pipeline of data. Even if the script I write gets discarded (which is likely), the skill of slightly more competent JavaScript coding will come in handy.

After a number of hours yesterday afternoon/evening (mostly reading up on JavaScript & jquery), I ended up with a self updating modified Twitter search widget (it's not super clean as I'm learning the basics). It would be easy to plug this into rails or any other web framework. I couldn't get a clean looking version of the source while on my phone (default blogging platform), but I'll insert it below as a placeholder.

The changes I made were to demo.html and script.js. In demo.html I deleted the loading image div so that tweets aren't covered up. In script.js I changed and added a few functions:

TweetTick is the pulse function which asks if there are any new matching search results from all or a subset of users. The format function updates the existing search results with the first of the results and redisplays the list with update times.

The github repo is available here and you can see the widget live in the iframe below and at this twitter real time search demo site.

[iframe 500 800]