Code Scavenger’s Chronicles

venting steam….

Archive for December 2008

Us

without comments

In Thud, the dwarf Bashfullsson says “I need no axe to be a dwarf, Nor do I need to hate trolls. What kind of creature defines itself by hatred?”.

Don’t we?

Written by shakhan

December 31, 2008 at 11:36 am

Posted in rest

Tagged with

Peeling the covers off HTML5

without comments

Went back to the HTML5 draft spec after a long while and found some interesting tidbits as usual.

element.click() has been made non-reentrant :- no worries anymore about dumb users clicking buttons again and again.

src attribute in img will be ignored if its the same as the page url :- most browsers used to fire an HTTP request even if the src attribute pointed to the same url as the page url (formally known as the ignored self-reference), duh.

And here’s the beast of a change which introduces script groups. Takes a while to stomach the implications.

MY NEW YEAR RESOLUTION :: MUST.KEEP.REVISITING.HTML5.SPEC.

Written by shakhan

December 30, 2008 at 5:21 pm

Posted in code

Tagged with ,

event.returnValue

without comments

You won’t know how important this sucker is unless you’ve coded confirmation dialogs in IE7. Yes, those worthless pop-ups which are supposed to help out the clueless.

<husky_mocking_overbearing_voice>
You might want to save you changes before you go to the other link! Are you sure you want to navigate away? Were all those clicks really just fluff not to be recorded for posterity?
</husky_mocking_overbearing_voice>

I was merrily invoking a js function from an anchor which throws up a innocuous confirmation dialog when I realized that clicking Cancel was still posting the page to the href URL!

Here are the relevant bits:-

<a onClick="javascript:return processClick(event);" href="/takemeaway">Click me</a>

function processClick(event) {
    if (unsavedChangesOnPage) {
        return showDialog(event);
    }
}

function showDialog(event) {
    return confirm("Do you really want to lose your changes?");
}


Apparently, with confirmation dialogs sometimes (on some machines; come on I should have a better answer); IE forgets to set the event returnValue to false! Bloody piece of crap!

Anyway, the solution was merely setting event.returnValue explicitly to false if Cancel was clicked.

Here’s the fix:-

function processClick(event) {
    if (unsavedChangesOnPage) {
        var result = showDialog(event);
        if (!result && itsStupidIE()) {
            event.returnValue = false;
        }
        return result;
    }
}


No love lost between me and IE!

Not now; not ever.

Written by shakhan

December 20, 2008 at 7:29 am

Posted in code

Tagged with ,

Antikythera

without comments

Finally..see the working version here.

Corroded remains of the device were found a century ago by spongedivers, who happened upon the shipwreck of a roman merchant vessel while sheltering from a storm near the island of Antikythera.

Written by shakhan

December 16, 2008 at 5:23 pm

Posted in rest

Tagged with