jQuery imgpreview plug-in

I’m forever grateful to all the much more talented people than me who choose to spend some of their free time by uploading useful stuff onto the web. A good example is the jQuery Plugin collection in general and the imgpreview plugin by James (Jimmy ?) Padolsey in particular.

Thank-you guys. A special thanks to Jimmy.

There’s only one problem with all of this: all these plugins allow relatively inexperienced coders like me to try and do stuff. I’ve been coding since I was a boy, but haven’t been paid to write code since I became a manager 11 years ago. I like to dabble with coding projects in my free time and I hate to read manuals, and together this isn’t a good combination. My only comfort is I know there are a lot of us out there who hate to RTFM.

Which leads me to a frustrating afternoon spent trying to implement the imgpreview plugin. I applied to my little project and kept getting some utterly unintelligible error messages (so a is undefined, now what?). I tried the usual (Google – 1 hit with no answer), dug up a non-minified version of the plugin (error messages said it couldn’t find the block I was pointing it at) and downgrading my copy of jQuery to 1.3.1 (still no results), I decided to go back to basics and implement a simplified version of Jimmy’s demo. Aaaand still, no dice.

By this point I knew I was doing something really, really dumb. As anyone who has programmed for more than a few years knows, there are only two paths to true enlightenment and I switched from random to methodical trial-and-error to find my problem: I had to declare the jscript after my block, not before.

BAD

$(‘ul#first a’).imgPreview();
«/script>

GOOD

$(‘ul#first a’).imgPreview();
«/script>

By now I expect anyone with more than a few weeks of javascript experience will have stopped reading so I don’t expect any of the usual snorting and/or condescension. I felt pretty dumb and decided to pay my penance by writing up this ID-10T error for any poor souls following in my footsteps.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s