Topsy turvy

A bug report for maphilight lead to me becoming aware of a fascinating quirk in IE. A quirk in which IE holds to published standards with fanatical zeal, contrary to everything one might have come to expect, and far in excess of Firefox/Opera/Safari.

When you use the .innerHTML property to add an element to the DOM, IE will fire an “unknown runtime error” if that element is incorrectly nested. So trying to place a <div> inside a <p> (as was the case in the bug report) will error very unhelpfully.

Surprising behavior.

Anyway, this led to the release of maphilight 1.1.1. (Which also includes an official minified version of the file, for convenience’s sake.)

del.icio.us widget

I couldn’t find a WordPress widget that produced output similar to del.icio.us’s linkrolls script. (You can just put their script into a Text widget, but its output doesn’t always mesh well with WordPress themes – it hardcodes h2s, and so forth.)

The Automattic example widget came close, but was a bit lacking on the customization front.

del.icio.us for WordPress also came close, but I disagree with having your server fetch the RSS feed, instead of using the perfectly good JSON API.

So I took the Automattic widget, hacked some extra features into it, made it configurable, and you can now see it in my sidebar. Well, footer currently. It’s a theme thing.

If you want it yourself, here’s the link: del.icio.us plus

Edit on 2008-03-27: This is now in the wordpress.org plugins repository. Edit on 2008-04-16: Version 1.1 released, granting multiple widget instances.

Creating an image map from SVG

I was asked how I made the map in my examples earlier.

I wrote a small script to do it. (The script is quite limited – I only made it complete enough to handle the SVG files I was using. Others might break it. Also, it requires pyparsing… and hoo-boy is that slow.)

Example!

Wikipedia is good for this, and has provided me with the example file I’ll use, a map of the USA. If you have some GIS data already, I believe that ArcGIS 9.2 has native SVG support, or it looks like you can convert ESRI shapefiles with shp2svg.

My example file is filled with all sort of crud that isn’t a definition of state boundaries, though, so I need to get just that. Perusing it (in a text editor or a SVG editor like Inkscape) reveals that all the state borders are in a group named “States”. Helpful!

So I run my script: svg2imagemap.py Map_of_USA_with_state_names.svg 960 593 States

(The “960 593” is the size of the image I’m creating from the SVG file.)

This creates an html file named [svg name].html, so Map_of_USA_with_state_names.html. It only contains the area tags, so I dump them into an image map in a page set up like the one in the other examples…

And we get: A map of the USA.

Just to disclaim again: That script is unlikely to be immediately useful for any particular SVG image. You would almost certainly need to tweak it significantly to make it work for your purposes. But it’s a good start, at least.

One last time: I make no guarantee of this script working on an arbitrary SVG file. At best it’s an example of an approach to take. If you use it, expect to have to debug how it interacts with your particular file.

maphilight: image map mouseover highlighting

UPDATE 2011-05-04: Version 1.3 released. Works in IE9. (There’s a pattern here.)

UPDATE 2010-05-22: Version 1.2 released. Works in IE8.

I just released maphilight, a jQuery plugin that turns image maps into wonderful graphical masterpieces.

Image maps aren’t so popular any more, for some strange reason. So a quick definition: an imagemap is an <img> with the usemap attribute, pointing to a <map> that describes polygons that link places within that image.

This sprung from me wanting to display pretty highlighting of countries on a map, but not wanting to mess with flash for it. It involves enough annoying fiddling with <canvas> (and VML, because IE is in the stone age) that I feel I’m saving other people a decent amount of work by releasing it.

(Tools like “HTML-Image map Creator WYSIWYG” might be handy if you want to make image maps yourself.)

Fixing sortForce in jQuery's tablesorter

jQuery has a table-sorting plugin, part of their official UI project. It’s quite a nice table-sorting library, handling the common cases, with options making it configurable to suit many people’s needs.

However, I ran into a problem when using it in a project. The documentation and the functionality don’t quite line up.

It has an option, sortForce, which its documentation says you can use to “add an additional forced sort that will be appended to the dynamic selections by the user”. This is a handy concept – it lets you, say, keep records ordered by name, regardless of which other criteria the user chooses to sort by.

The problem is that it actually prepends the sort to the user’s selection, which means that the user is restricted to sorting within the forced sort. (This is also a potentially useful tool; it’s just not what the documentation indicates.)

So I wrote up a patch that fixes this, along with a few other niggling issues with sortForce. (Its interaction with the user sorting by multiple columns, and it locking the forced-sort column in one sort direction.) To preserve backwards-compatibility I added a new option, sortAppend, to provide the documented behavior.

I also submitted the patch to the maintainer, so hopefully it can get incorporated.

2008-08-27: My patch was incorporated as of version 2.0.2, so it’s all good. 2009-03-17: But bits of it weren’t applied, so it can’t be said to have been fixed. Oh well. I’ll resubmit.

Practicing JavaScript with Dilbert

I discovered that there was a flash widget displaying Dilbert archives in color, back to the start of 2007.

Naturally I thought to myself “aha, there must be an XML data feed somewhere in that!” Some light flash-decompilation later, I discovered that I was right.

I then seized on this as a learning opportunity, and wrote a much better viewer, in boring old JavaScript. Why is it better? Because it doesn’t require Flash, and is not limited to one panel at a time, that’s why.

My Dilbert viewer, can you view it?

Caveats:

  1. It’s perfect in Firefox3 and Safari. Sundays aren’t quite right in IE7; the first and last buttons are missing in Opera. All else is untested.
  2. For some reason, the widget seems to get different feeds for the last week or two, which means this viewer is a week behind. I suspect user-agent sniffing, but have not yet been motivated to work out what a flash-player’s user-agent is.

Things learned:

  1. Cross-domain xmlhttprequest requiring a proxy is a pain, and has no obvious benefit.
  2. jQuery is still awesome.
  3. Forgetting to take out debug statements that rely on FireBug when uploading is dumb of me.
  4. Decompiling these things is complex – the embed code provided loads a .swf, which loads a .swf, which finally loads the actual widget that displays the comics.

Update: I worked out the cause of the weird out-of-sync-ness I observed between the data files I received and the content seen in the official widget. The lesson is not to trust the data feed when it tries to tell you which domain to look at; it includes a <Domain> tag, which seems like a perfect complement to the domain-less URLs given in the strip descriptions. However, that domain contains files that are several weeks out of date. So I just hardcoded the “real” URL.

They finally released this stuff to the main Dilbert site, so I just went through and fixed up the viewer to use the appropriate new feed format. Darn changes.

Three gigabytes free...ish

Wordpress.com announced yesterday that all users get three gigabytes of upload space for free. This is a teensy upgrade from 50MB.

This seems to be primarily for psychological reasons, because there’s a big fat * after the upgrade.

The footnote is that Mr. Mullenweg mentions in this post that “[y]ou still need a space upgrade to upload certain file types, like movies”, and later in the comments that “[y]ou still need a space upgrade to be able to upload MP3s”. So you still have to pay them if you plan to do anything significant with their bandwidth. (Not sure where they stand on humongous zip files, or similar.)

Not that this is wrong of them. It rings a bit of being an arbitrarily large number chosen for PR reasons, but that’s understandable.

The 3 gig limit is very reassuring to an important segment of the blogoratispheroidalmass. Specifically, the people without their own hosting, who want to be able to post their photos on their blog and not worry about having to trim out old ones after a few months.

50MB = 300-500 decent quality JPEGs of photos. It’s easy to imagine that being a problem after a short while. 3 gigs… not so much.

Why I can't play Dungeon Runners

Last night I thought to myself “hey, I know, I’ll try out Dungeon Runners!” It’s a pseudo-free pseudo-MMO, which could be described as a Diablo parody – that’s the sort of game that sounds appealing to me.

Sadly, I discovered that Dungeon Runners is not a game I can play.

You see, it requires that inbound port 80 be open for your initial connection to a world server. This is a mind-bogglingly weird decision.

Port 80 is an entrenched-by-standards ports – it’s what webservers listen on.

Thus Dungeon Runners is off-limits to two classes of people:

  1. People whose ISP block port 80 inbound, because they really don’t want people running servers. (Verizon did this for a while on my connection.)

  2. People who run a server. (That’s me.)

Okay, I could shuffle ports around, temporarily assigning 80 to my games computer whenever I wanted to log in. But that’s more effort than I want to put into this. Thus I effectively cannot play Dungeon Runners.