Book Image

Drupal 6 JavaScript and jQuery

By : Matt Butcher
Book Image

Drupal 6 JavaScript and jQuery

By: Matt Butcher

Overview of this book

<p>JavaScript: It's not just for calculators and image rollovers.<br /><br />Drupal 6 is loaded with new features, and not all of them are necessarily implemented in PHP. This unique book, for web designers and developers, will take you through what can be done with JavaScript (and especially with jQuery) in Drupal 6.<br /><br />With the combination of the powerhouse jQuery library with its own robust set of JavaScript tools, Drupal 6 comes with a pre-packaged killer JavaScript environment. Cross-platform by nature, it provides all of the tools necessary to create powerful AJAX-enabled scripts, gorgeous visual effects, and view-enhancing behaviors. In addition, Drupal developers have ported some of its most powerful PHP tools – like a theming engine and support for localization and language translation – to JavaScript, making it possible to write simple scripts where once only complex PHP code could be used.<br /><br />This book gives you the keys to the toolbox, showing you how to use Drupal's JavaScript libraries to make your modules and themes more dynamic, interactive and responsive, and add effects to make your Drupal site explode into life! <br /><br />If you've dipped your toe in the water of theme or module development with Drupal 6, this is the book you want to make the look and behavior of your work something special. With it's project-based approach, this book is carefully constructed to guide you from how JavaScript fits into the overall Drupal architecture through to making you a master of the jQuery library in the world of Drupal themes and modules.</p>
Table of Contents (14 chapters)
Drupal 6 JavaScript and jQuery
Credits
About the author
About the reviewers
Preface

Using jQuery in Drupal


So far, we have seen just a few lines of jQuery code. But, our examples have been independent of Drupal. How can we use jQuery inside of Drupal?

The answer is simple. If we write our JavaScript "the Drupal way", then Drupal will make it very easy to use jQuery. Here's what I mean.

How do we include JavaScript files in Drupal themes? By using the scripts[] directive in the theme's .info file. And if you're a PHP programmer, you can use the drupal_add_js() function in either a theme or a module.

If you use either of these means, then Drupal will automatically include the basic JavaScript libraries, including drupal.js and jquery.js. That's right. Drupal not only includes jQuery in its core distribution, but automatically includes it for you.

To see an example of this, we need not look further than the code we wrote in the previous chapter. Looking in the<head></head> section of the HTML for our theme, we can see the following<script></script> tags...