upgrading, extending.

So, it had been some time since I last gave any love to the software that runs this weblog. But recently, some evil minded person that I won’t name pointed out that the ugly and flashy google reader badge that I used as a widget in the right sidebar would, sometimes when my posts are not long enough, cover the bottom sidebar and hide some of the pictures of the flickr badge.

But truth is, that’s an ugly, straight from the factory google badge. And indeed, it is a bit flashy, but one can’t change much about it, except the foreground color and the number of items. And it sux.

So, I gave some love to the whole software. First, I did a long standing upgrade, which went smoothly (only had to upgrade one or two plugins). And then, I took my lovely emacs and went to work.

I first looked at how the original badge works. So we have two javascript files. The first one, obfuscated (or minimized), is the controller that creates the view (and the resulting html file). The second one is the data. It takes two arguments, the number of shared items, and a callback. The callback is a javascript function (or whatever that looks like one) which is called with the resulting data structure.

The various questions I asked myself while working on this:

  • How do I create a widget? You provide a callback with register_sidebar_widget(), but you may have to first use another callback (using add_action() this time) to wait for the widgets_init event.
  • which javascript framework should I use? The Software is shipped with jQuery, let’s use that for once.
  • How do I get a jQuery object as html to be written with document.write() ? Well, really, you don’t, because it seems you can’t only access the inner html code. But instead of using this ugly code with write(), I can simply declare a div and append() to it.
  • How do I know which div (or whatever) to use? The callback is given an array with things like widget_id.
  • How do I create options for a widget? You use register_widget_control() with a callback.

And now, I have a simple WordPress widget which displays my recently shared items on google reader with a simple list and no flashy colors.

You know what? I’m happy.

(even though this badge can still overwrite the bottom sidebar)

2 Responses to “upgrading, extending.”

  1. some evil minded person Says:

    Good stuff Seb!
    Glad I gave you good inspiration there! And that made you happy!

    Would you give the global code? (not to copy, I would nopt know how to do that anyway, but too look at the global look of what made you happy…)

    (Now I am just waiting for little flowers… But you know me, I need flowers everywhere! A birs is already quite good!)

  2. Sebastien Tanguy Says:

    If someone really cares about having a wordpress widget to display his/her latest shared feeds from google reader, I could probably publish the whole thing; It is not foolproof, but it is configurable enough to be used by most.

    In the meantime, you can still take a look at the heart of the solution, the whole 20 lines of javascript of it, simply by going to my main page, looking at the source (Ctrl-u with firefox) and then searching for “greader”.