• Help cleaning up some awful JS

    From Deepthaw@VERT/DS94 to All on Mon Jun 19 13:49:29 2017
    Subject: Help cleaning up some awful JS
    @VIA: DS94
    @MSGID: <59481CB9.707.syncjs@bbs.deepthaw.com>
    @TZ: c168
    Full disclosure: JavaScript is *not* my first language. That'd be C++.

    I've been modifying electronic chicken's v4 web interface to automatically add logos for external programs if they exist on the web server.

    I have some kludgy code that *works* but I guarantee it's not the best way to do it. I'm just not familiar enough with JS and jquery to know what the "correct" ways to do it are.

    Here's the relevant code. It checks if a .png (I'm going to tweak it to search for jpg and gif as well) with a name matching the code for that external program exists, then resizes it to a maximum 150px wide icon to display above the title of the external program.

    var image = "./images/" + xx.c + ".png";
    $.ajax({
    url: image,
    type:'HEAD',
    error: function()
    {
    $(a).text(xx.n);
    },
    success: function()
    {
    $(a).html("<img style=\"max-width:150px;\" src = \"" + image + "\"><br/>");
    $(a).append(xx.n);
    }
    });

    ---
    ■ Synchronet ■ Deep Space '94 - bbs.deepthaw.com - The Best 1994 Had to Offer