Book review: Drupal 6 JavaScript and jQuery

by Matt Butcher | Published by Packt Publishing

The very first Drupal module I was ever tasked with building was a little widget for displaying portfolio items. You could scroll through thumbnails, three at a time, each successive three being loaded via AJAX, and clicking on any thumbnail loaded a larger image and description, via AJAX of course, for that portfolio item. I was brand new to Drupal and, despite being pretty scared of JavaScript, was thought of as "the AJAX person" on the team (because I had once mentioned that one time I had built something that used AJAX). It was a pretty tall order, from my perspective. If I could pick one book to magically pass to the me of then, this gem by Matt Butcher would undoubtedly be it, the fact that I was working with Drupal 5 notwithstanding (ok, things like "Drupal.behaviors" would have thrown me for a loop but you get my point).

The book aims to get people with little to no knowledge of Drupal or JavaScript up to speed with creating really awesome functionality, really fast. In fact, its title almost belies the breadth of its scope: although the use of jQuery in Drupal 6 is the one topic that it covers exhaustively, it doesn't skip over any of the basic tools or concepts required to get going with Drupal, and so it would work pretty well as a first Drupal book for any aspiring front-end Drupaler. It covers everything from the ultra-utra-basic ("what is CSS?", "what is a Drupal block?") to Drupal JavaScript Behaviors (and everything else in drupal.js), to JavaScript Theming, to AJAX, to building modules with AJAX functionality, to jQuery syntax, effects, and even writing jQuery plugins!

The approach taken is extremely pragmatic, using small projects to illustrate all of the essential concepts and techniques. The projects are interesting and fun, and ones that could easily be used as a basis for trying one's hand at more complex functionality. The code explanations are comprehensive and clear and the text is littered with handy tips and pointers, e.g. explanations of why one way of doing something is better than another. The author's considerable experience with the web adds a lot of value through these pointers and yet doesn't impede him from delivering very good novice-level explanations of tricky concepts, as can sometimes happen.

The topic of JavaScript in Drupal is an important one to get one's head around. There are nuances to it and it's very easy to do things the WRONG way, when you don't know what you're doing. But it's only going to become harder and harder to avoid having to learn how to do it right if building Drupal sites is what you do for a living. Look at any requirements document for a client website these days - especially if there are social networking features or any type of user interaction involved, e.g. browing through large amounts of content, playing games, forwarding content to a friend - and the chances are that there are at least some nifty visual effects required if not full-blown AJAX functionality. This book makes it very easy to learn the right way to do those things.

Drupal 7 is bringing in some massive changes regarding the use of JavaScript and jQuery - drupal_add_js() is quite a different beast from what it was in D6, jQuery UI is in core, and pending patches include JavaScript library management. Matt, I hope we can look forward to a second edition for Drupal 7 ;-)

To get a copy of the book, visit the Packt Publishing website.