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: weekend countdown


The project that we will create in this chapter is a simple weekend countdown tool. This will display a little piece of text that indicates the current day of the week, and then says how many days are left until the weekend.

The main point of this application will be to make practical use of the translation system that we saw earlier. For that reason, we will first write some code, and then do a little translation.

Note

While we will consistently use the Drupal.t() function in this book, this is the only place where we will be writing a translation. You do not need to provide translations along with your theme or module (though if you have the ability to do the translations, it sure would be nice).

Our code is once again going to be attached to the frobnitz theme. The script file will be named day.js. Make sure you include it in the frobnitz.info file: scripts[] = day.js.

Here's the code:

var Day = Day || {};
Day.dayNames = [
Drupal.t("Sunday"),
Drupal.t("Monday"...