thoughts of the driverSteinn Eldjarn Sigurdarson on tech, tel, digital freedom and possibly his life..

June 3, 2009

Slightly different take on javascript library detection..

Filed under: General, Technology — Steinn E. Sigurðarson @ 9:07 am

A small update in reference to this, a post I wrote earlier about upgrading my WordPress, and also a javascript method to safely check if a js library has already been loaded in a parent system of a widget or module.

I don’t know about you guys, but in my case, my earlier code would start acting up on my firebug sometimes, and it would force me to step through the exception which it was catching — very annoying, so I made another version which doesn’t use exceptions.

if (typeof(MooTools) !== 'undefined')
{
                // We have MooTools, is it recent?
                var numv = parseInt(MooTools.version.replace(/\./g, ''));
                if (numv < 122)
                {
                        // old version, what do we do?
                }
                else
                {
                        // new version woohoo! do nothing!
                }
}
else
{
        // Failure, we assume MooTools is not setup, and we include it
        // XXX: check here for prototype/jquery and abort in that case

        var head = document.getElementsByTagName("head")[0];
        var newscript = document.createElement('script');
        newscript.type = 'text/javascript';
        newscript.src = '/blocks/indicators/code/mootools-1.2.js';
        head.appendChild(newscript);
}

I do however think that my firebug and firefox combo on the windows machine are simply f*!@#$% …. but who cares… more code, another post, we happy! =)

digg this

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

gin 0.321 & tonic. | Powered by WordPress