Detecting failure

I warn you in advance that this post does not end with a resolution of my problems.

For reasons relating to dynamic loading of javascript dependencies, I wanted to find a way to tell:

  1. When a script tag finishes loading a file
  2. Whether that file was successfully loaded

For various reasons, I didn’t want to add cruft into the files being loaded – no appending a function call to the end of every file, or anything.

Now, the finishes-loading case turns out to be pretty easy, albeit with some quirky cross-browser ramifications:

var eax, load;
eax = document.createElement('script');
eax.setAttribute('type', 'text/javascript');
eax.setAttribute('src', src);
load = function(e) {
    // FF/Safari get the `load` handler, IE gets the `readystatechange` handler.

    // IE doesn't fire 'load' for JS (but does for CSS...)

    if(!eax.readyState || eax.readyState == 'complete' || eax.readyState == 'loaded') {
        // IE6 stalls at 'loaded' sometimes

        alert('loaded!');
        // remove these listeners for everyone, because it's

        // easier than testing everything to find out whether it's needed.

        removeEventListener(eax, 'readystatechange', arguments.callee);
        removeEventListener(eax, 'load', arguments.callee);
    }
};
addEventListener(eax, 'load', load); // FF/Safari get this

addEventListener(eax, 'readystatechange', load); // IE gets this

It’s a horrible mish-mash of events, obviously, but it works. Insofar as it goes.

Working out whether the load was successful turns out to be the hard part.

In Firefox it’s very easy. The load event doesn’t fire if there are problems loading the JS file, and a error event fires instead. This is lovely.

In Safari the load event doesn’t fire if there are problems, but there’s no other sign given. So I could probably fake this with a setTimeout set to a reasonable length – not perfect, but good enough for most cases.

In IE the readystatechange event fires away regardless. It’s here that I’m stuck – I can’t see any way to tell, in the readystatechange handler whether the script tag was really loaded without problems.

Since IE represents an unfortunately large component of deviantART’s users, half-working failure detection isn’t going to cut it. Especially since all the developers mainly use Firefox/Safari, and wouldn’t expect IE to behave differently.

So for now I’m going with verifying that the script tag loaded something, and says it’s complete. I’ll keep my eyes out for a way to work around IE…

Intrepidly lacking

I updated my desktop to the new Ubuntu release (Intrepid Ibix)

This is mostly good, but I discovered a problem as a side-effect of them improving their mouse support. Now that my mouse is auto-detected with all its buttons, the side-button no longer defaults to being a middle-click. I like having the side-button do middle clicks.

So, no problem, I thought. I’ll just go rebind it. There is doubtless something in the mouse settings that lets me adjust this – I mean, Windows generally handles this fine, so surely Ubuntu will be at least equivalent.

This turned out to not be true.

After a lot of searching, I found the community documentation for the Logitech Marblemouse USB, which (sort of) discusses how to remap buttons.

So I ran: $ xinput set-button-map "Logitech USB Gaming Mouse" 1 8 3 4 5 6 7 2 9

This didn’t remap it, per se. It swapped clicking the mouse wheel and clicking the side-button.

(I’m not certain that this will persist through a reboot. I might need to meddle with .Xmodmap.)

It’s a weird place to be lacking what I consider basic functionality.

Ubuntu: sharing music with iTunes

  1. sudo aptitude install mt-daapd
  2. Edit /etc/mt-daapd.conf so that mp3_dir = [your music directory]. (Also any other configuration changes you might want to make; the file is well-commented.)
  3. sudo /etc/init.d/mt-daapd restart

Really this would work on any Debian-derived distro… but I’ve only tried it on Ubuntu.

Update: It looks like mt-daapd puts an admin interface on http://localhost:3689/ (with the default password being ‘mt-daapd’), which you can use to configure things like the location of your music. So you might not even need to do any config file editing…

Disadvantages to a Hollywood office

Yesterday when leaving work I stepped out the back door of our building and almost blundered through someone filming a scene for something.

The back doors of our building had been made over into a hospital entrance, and someone who was the very embodiment of The Wise Old Bum was dispensing advice to people in scrubs, while some sort of faux-homeless band played on the bridge crossing the alley to the parking garage.

Weird.