Monthly Archive for August, 2008

Fun with Ubiquity

Today I came across the most interesting announcement from Mozilla’s Aza Raskin: Ubiquity 0.1 alpha is out. That means I have a new toy to play with!

Ubiquity is an add-on for the Firefox browser that enables the user to interact with content like never before; contextual fragments of a webpage can be translated, sent by email, looked up with Google Maps, searched with by wikipedia, youtube, flickr and so much more. I suggest you watch the video!

As with every other new toy, I started playing with it right away and I immediately fell in love with the ‘email’ command. I could simply select some text, do ALT+SPACE, type ‘email this to ruben’, hit ENTER and go! It automatically fires up GMail, sets subject, to-address, body text and the only thing left to do is press ‘Send’.
Problem: I do like GMail, but I use it only for emergencies. When ALL my other mailboxes are unavailable, which happens, like…never. So I rolled my own little Ubiquity command called ‘mail’ that does the exact same thing as ‘email’, but uses the standard ‘mailto:’ interface to access your desktop email client.
Problem: it doesn’t support HTML mail, thus no fancy content like images and hyperlinks. I guess I could add a couple of regular expressions that parse the body text for links and replaces images with BBCode-like placeholders - [img src=http://path.to/image.jpg]. I’ll do that upon request, ok?

This is only a very simple, first tryout of what I could do with this Ubiquity alpha. There’s probably more to come, so check up on me regularly when you’re interested.

Enjoy!

Gem of the day

It’s not like I’m going to post a random thing I found useful as a Gem-of-the-day every day, but let’s stick with often.

The first gem is this one:

/**
 * Execute a script in the global scope.
 *
 * @param {String} str
 * @type  {String}
 */
jpf.exec = function(str){
    if (!str) return str;
    var head, script;
    if (window.execScript) {
        window.execScript(str);
    } else if (head = document.getElementsByTagName("head")[0]) {
        script = document.createElement('script');
        script.setAttribute('type', 'text/javascript');
        script.text = str;
        head.appendChild(script);
        head.removeChild(script);
    } else {
        eval(str, window);
    }
    return str;
};

So what does this little gem do? Well, it provides a developer the power to execute a piece of script - at runtime of course - in the global scope. For example, if your XmlHttpRequest loads the content of a .js script file (e.g. the Content-type header is set to ‘text/javascript’), ‘exec()’ will execute that script as if it were loaded with a <script> tag in the <head> section.

Dynamic script loading this feature is called. Wow. Anyway, we use it at Javeline and I found it in the Mootools library - lots of cool stuff in there by the way.

Update: Added the eval fallback with its second argument telling eval to execute the code in the scope of the window object. (This is supported by Gecko browsers only)
Update2: Changed document.head reference to document.getElementsByTagName(”head”)[0]. (Thx Mors)