/Ugly/ + 'JavaScript'

A place for ugly, silly, or just-plain-crap JavaScript.

A function for each cloud

Some poor Google employee had the job of making a maintenance page for the once-hyped Google Wave. Apparently, we need a function for each cloud, and each wave:

var cloudMoved = false;
var cloud2Moved = false;
var cloud3Moved = false;
var WAVE_TIME = 6000;

$(init);

function init()
{
    cloudMove();
    cloud2Move();
    cloud3Move();
    waves2Out();
    waves3Out();
}

function cloudMove()
{
    if (!cloudMoved) {
        $("#cloud").css("left", $("#cloud").offset().left)
    }
    
    $("#cloud").animate(
        //...
    )
}

function cloud2Move()
{
    if (!cloud2Moved) {
        $("#cloud2")
            .css("left", $("#cloud2").offset().left)
    }
    
    $("#cloud2").animate(
        //...
    )
}

function cloud3Move() //... etc.
Posted by James on 09 Sep 2011 | linky

Nostalgic Tribute to document.write

I feel almost nostalgic at the sight of this. A tear may be shed, not just from the pain that the code induces, but from the memory of how humble things once were…

function wrtOut2(){
 parent.main.document.write(ls
 +"<P><FORM><INPUT TYPE='button' NAME"
 +"='but' VALUE=' I want to play again! '"
 +" onClick='parent.location.href=\"s30.ht"
 +"m\";'><P><INPUT TYPE='button' NAME"
 +"='but1' VALUE=' Let Me See the Scripts '"
 +" onClick='parent.location.href=\"s52.ht"
 +"m\";'></FORM></FONT></BODY></HT"
 +"ML><P>");
}

All credit to a truly great publication: The Ugly JavaScript Book

Posted by James on 08 Sep 2011 | linky

Pointless If statement

We’ve all seen this:

if (kRegex.test(value)) {
    return true;
} else {
    return false;
}

Eew.

Beautified:

return kRegex.test(value);
Posted by James on 07 Sep 2011 | linky

Subscribe or follow @UglyJS!
.........
Fork then send a pull request to contribute.