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

Project: menus and blocks


We will do a few short projects in this chapter. In this first project, we will create a couple of new themes. These themes will mimic two standard Drupal layout components: blocks and menus.

The focus of this project will be to see how PHP Templates and PHP functions can be converted into JavaScript-based theme functions.

Our theming project is going to add a new menu inside of new block to a page using JavaScript. Although we will be adding these elements from JavaScript, we want them to look and perform indistinguishably from the server-generated blocks and menus.

We will put the code inside of a new file called themes.js. It should be included with our frobnitz.info file, so make sure to add a scripts[] entry and refresh the cache.

Adding a block with a menu in it

The new menu and block will be added as soon as the document is loaded. This means we can start with the now familiar jQuery ready event handler:

$(document).ready(function () {
var links = [
{name: 'Drupal...