• Categories



  • Archives

  • MooTools 1.2 Asset.css onload problem, and fix

    Published July 3rd, 2008

    As part of the experiments I mentioned yesterday, I’ve been looking at the feasibility of loading CSS on-the-fly. MooTools has a method to achieve this (Asset.css) but I found to my disappointment that its onload event only works in Internet Explorer, so in other browsers you have no way of knowing when the CSS has finished loading (or if it’s failed).

    I posted a bug report yesterday and as far as I can tell it’s slated to be looked at for the next release (1.3), but while pondering the problem overnight I came up with an idea and with some help from this blog post I was able to create an interim fix. Because it uses XMLHTTPRequest it can’t load CSS from a third-party domain, but it works for what I need and it’s better than nothing until the official fix is forthcoming.

    I’ve put the code into this file (right-click, save as…) which you simply load after MooTools itself (it replaces the existing Asset.css definition with a new one).

    Popups/dialog boxes in MooTools

    Published July 2nd, 2008

    I’m just starting preliminary work on a complete (and long overdue) rewrite of our project’s CMS. Right now I’m really just tinkering around, exploring some ideas. As part of this process I wanted to experiment with some dialog boxes, and not wanting to reinvent the wheel I decided to look for a ready-to-use project based on MooTools, our JavaScript library of choice.

    My first stop would have been the official MooTools forum, but in their wisdom the project’s leaders have decided to remove them completely. The oft-mooted ‘MooForge’ has never materialised but after exploring a variety of blind alleys I came across MooScripts, an unofficial but quite comprehensive collection of MooTools add-on scripts.

    From there I was led to the Mocha UI project, which is a fairly lightweight implementation of dialog boxes for MooTools 1.2. It’s feature list is impressive and it’s quick too (compared to others I tried). Like Mootools it also uses the very permissive MIT licence, which basically says ‘use it how you like, at your own risk’.

    Firefox 3: portable version slowdown

    Published June 27th, 2008

    I’ve been using Firefox 3 for several months now (through various betas and release candidates) and I have to say I’m pretty happy with it. I’ve resisted blogging about it because I think more than enough words have already been written on the subject, but I’ll just say that I’ve been very happy with its improved speed and stability over FF2.

    However I do have one caveat to add. I use the portable version (running from a USB key) and found, after some weeks of use, that it was becoming increasingly sluggish. I put up with it for a while but was getting quite frustrated when, one day, I got an error when shutting down the browser. I don’t remember the specifics, but it mentioned a file in my profile directory called urlclassifier3.sqlite.

    Out of curiosity I looked at the file and found that it was over well over 70MB in size. This made me even more curious, so I did some searching and found various references to it and its potentially detrimental effect on Firefox’s performance. So I renamed it, restarted Firefox and — presto! — the browser was back to its former, sprightly self.

    Some further digging revealed that this is a cache file for data about phishing and malware sites, and can be disabled by unchecking the “Tell me if the site I’m visiting is a suspected attack site” and “Tell me if the site I’m visiting is a suspected forgery” options in Tools > Options > Security. Of course, you do so at your own risk — you could alternatively leave theese options enabled and just delete the file once in a while, when it gets really big and FF starts to slow down.

    OK, two caveats: I’m definitely in the ‘I hate the AwesomeBar‘ camp — I’m a
    creature of habit and the old-style auto-complete worked just fine for
    me. Bah.

    Monitor site uptime for free

    Published June 23rd, 2008

    A while back I thought up, but never implemented, a plan to develop a free web site uptime monitoring service. Basically, I spent a few hours thinking about features, wrote a few dozen lines of code and bought a smart domain name. It would’ve been great, seriously — there were other services out there but none that offered the sort of thing I was planning.

    I’m still kind of disappointed that I didn’t follow through with it but recently I found something that ticks most of the boxes that I was interested in, and plenty more besides. Going by the slightly ungainly name of mon.itor.us, you get plenty of neat options for keeping track of your site’s responsiveness, several types of notification (including SMS if you need it) - and they even send you a weekly summary report. The basic service, which will probably be fine for most people, is ad-supported and free.

    Note to self: PHP object constructors never return false

    Published June 13th, 2008

    As part of my ongoing refactoring work (see previous post) and having decided to take a more active stand against broken windows syndrome I’ve been cleaning up various coding oddities as I’ve found them.

    Today I came across (something like) this little snippet:

    if( ! $obj = new myObject( $id ) )
    {
      throw new Exception( 'Not a valid object' );
    }
    

    At first glance we might assume that the constructor attempts to populate the new object with some data loaded from (say) a database, but if no data matching the supplied ID is available, then the constructor returns false to indicate this. All very reasonable, right?

    Except that it’s not possible to return false, or indeed any value, from a constructor because the ‘return value’ of the constructor is the object itself. Which means that the above snippet is redundant, because the expression will always evaluate to true.

    It would’ve made more sense to throw an exception within the method that loads the data — and in fact this is exactly what happens, which makes the quoted code doubly redundant and even more inexplicable.

    I don’t think I’m the one who’s responsible for this particular brain fart but it’s OK because the only other likely candidate left the company last year so I happily can blame it on him…