A little bit of undead fun

18 Apr 2018

The relationships between myself and my clients are important. Especially when self-employed in a potentially solitary profession such as a developer then the dynamic of the client relationship is particularly crucial, more so than any financial compensation, and it is also important for the client as in many cases I find people hire me for me, not just for the work I'm able to do. I'm lucky to have a wide variety of really terrific clients that are fun to work with and with whom the working relationship often ends up generating some entirely unexpected results.

Yesterday I was having an online conversation with a long-time e-commerce client with whom I've enjoyed a spot of satisfying nonsense from time to time. We were kicking around some ideas for a refresh of the site and in one message I managed to mis-type 'read' as 'dead'... subsequently of course the conversation took on an entirely new direction.. one with a zombie flavour and a tongue in cheek challenge of sorts that resulted in possibly my favourite single line of javascript ever...

 

var randomZombie = zombies[Math.floor(Math.random()*zombies.length)];

 

Perhaps it's just me but it has a lovely 'tempo' to it.. I think...

The bigger picture is that to much hilarity from her team as a bit of end of the day fun I built a 5-minute 'easter egg' into the site that would instantly swap out all of her product pictures for zombie heads. It was purely a happy coincidence that the site sells skincare products.. one possible spin being "this is what's going to happen if you don't look after your skin..".

 

You are just the BEST. I had to go take a little walk just then, am in absolute BITS.

Can you leave that live for Halloween please?

 

 

One the giggling stopped however I was asked to develop the feature into something that can be used as a promotion on holidays and for special events locally, the image set being swapped out for whatever set is pertinent to the occasion. She's very good with social media promotion and knows her customers well so we think this is an opportunity to have a bit of fun with the site and the customers and another way to drive traffic to the site. Time will tell but either way the effort required is minimal.

Here's the code. It isn't perfect.. I'm finding the event listener in Chrome doesn't always fire for reasons I have not bothered to investigate (it's odd, sometimes it fires, sometimes it doesn't. I did read somewhere that Chrome doesn't support zEvent.code, don't know ) but I can resolve that in the 'proper' version, as well as provide support for touch devices.  In this case the key combo is alt+shift+z (for zombie of course). All that's missing is a little banner saying "you're now browsing in undead mode."

 

document.addEventListener ("keydown", function (zEvent) {
        if (zEvent.shiftKey  &&  zEvent.altKey  &&  zEvent.code === "KeyZ") {
            doZombies();
}


function random_zombie()
{
    
    var zombies = ['http://zombie-image-url1', 'http://zombie-image-url2', 'http://zombie-image-url3', etc etc ....];

    var randomZombie = zombies[Math.floor(Math.random()*zombies.length)];

    return randomZombie;

}


function doZombies()
{
    [].forEach.call(document.querySelectorAll('img.thumbnail,#main_image > img'), function(img) {
    img.setAttribute('src', random_zombie());
    
    });
}

 

Complete nonsense I know but as a generator of excellent humour worth far more than a few lines of code would suggest, with the unexpected benefit of it being useful as a genuine promotional feature, definitely worth 5 minutes of mucking about.

p.s.  Yep, it's definitely me.

 

zombies