You are previewing Drupal 6 JavaScript and jQuery.
O'Reilly logo
Drupal 6 JavaScript and jQuery

Book Description

Putting jQuery, AJAX, and JavaScript effects into your Drupal 6 modules and themes

  • Learn about JavaScript support in Drupal 6

  • Packed with example code ready for you to use

  • Harness the popular jQuery library to enhance your Drupal sites

  • Make the most of Drupal's built-in JavaScript libraries

In Detail

JavaScript: It's not just for calculators and image rollovers.

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.

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.

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!

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.

Table of Contents

  1. Drupal 6 JavaScript and jQuery
  2. Credits
  3. About the author
  4. About the reviewers
  5. Preface
    1. What this book covers
    2. Who this book is for
    3. Conventions
    4. Reader feedback
    5. Customer support
      1. Downloading the example code for the book
      2. Errata
      3. Piracy
      4. Questions
  6. 1. Drupal and JavaScript
    1. Do you speak...?
      1. PHP
      2. SQL
      3. HTML
      4. CSS
      5. XML
      6. JavaScript
    2. Drupal's architecture
      1. The Drupal Core
      2. The Theme Engine
      3. Modules
    3. Users, nodes, and blocks
      1. Users
      2. Blocks
      3. Nodes
    4. Drupal JavaScript development tools
      1. A good editor
      2. Firebug
      3. The Drupal Devel package
    5. Summary
  7. 2. Working with JavaScript in Drupal
    1. How Drupal handles JavaScript
      1. Where Drupal JavaScript comes from?
    2. Project overview: printer-friendly page content
    3. The printer script
      1. Drupal coding standards
        1. Stylistic differences between PHP and JavaScript
      2. The first lines
      3. The print() function
    4. Creating a theme
      1. Full themes and subthemes
      2. Creating a theme: first steps
        1. Creating a theme directory
        2. Creating the .info file
        3. Adding files to the theme
      3. The CSS file
      4. Adding JavaScript to a theme
        1. Overriding a template
        2. Adding the script file
    5. Summary
  8. 3. jQuery: Do More with Drupal
    1. jQuery: the write less, do more library
      1. A first jQuery script
        1. Getting jQuery
        2. Starting with a basic HTML document
        3. Querying with jQuery (and the Firebug console)
        4. Bye bye, jQuery(); hello $()
        5. Doing more with jQuery
          1. Not every function returns a jQuery object
    2. Using jQuery in Drupal
      1. Don't do it yourself!
    3. Project: rotating sticky node teasers
      1. The StickyRotate functions
        1. The init() function
        2. The periodicRefresh() function
        3. Adding an event handler with jQuery
    4. A brief look backward
    5. Summary
  9. 4. Drupal Behaviors
    1. The drupal.js library
    2. Drupal JavaScript behaviors
      1. Defining a behavior to handle repeatable events
      2. Telling Drupal to attach behaviors
        1. Context and behaviors: bug potential
    3. Project: collapsing blocks
    4. Utilities
      1. Checking capabilities with Drupal.jsEnabled
      2. The Drupal.checkPlain() function (and the jQuery alternative)
      3. The Drupal.parseJson() function
      4. The Drupal.encodeURIComponent() function
      5. The Drupal.getSelection() function
    5. Project: a simple text editor
      1. The main behavior
        1. Step 1: find text areas that need processing
        2. Step 2: add event handlers
        3. Step 3: attach the button bar
    6. Summary
  10. 5. Lost in Translations
    1. Translations and drupal.js
    2. Translation and languages
      1. Turning on translation support
      2. Getting and installing translations
      3. Configuring languages
        1. Adding the language
        2. Configuring languages
    3. Using the translation functions
      1. The Drupal.t() function
      2. The Drupal.formatPlural() function
    4. Adding a translated string
    5. Project: weekend countdown
      1. Translating the project's strings
      2. Changing a translation file
    6. Summary
  11. 6. JavaScript Theming
    1. Theming in PHP, theming in JavaScript
    2. The Drupal.theme() function
    3. Project: menus and blocks
      1. Adding a block with a menu in it
      2. Theming a block
      3. Theming a menu
    4. The JavaScript theming module
      1. Theming tables
      2. Sending notifications to the user
      3. Adding links
    5. Project: templates for JavaScript
      1. The node template
      2. From a template to a system: what next?
      3. A template system
      4. Theming with templates
      5. Using the template system
      6. A word of warning
    6. Summary
  12. 7. AJAX and Drupal Web Services
    1. AJAX, JSON, XHR, AHAH, and Web 2.0
      1. Web application and Web 2.0
        1. The position of AJAX in Web 2.0
      2. Getting technical
      3. Move over, XML
    2. Project: web clips with RSS and AJAX
      1. Really Simple Syndication (RSS)
      2. The project goals
      3. Creating the web clips tool
        1. The WebClips behavior
        2. The WebClips.showItem() function
    3. Project: real-time comment notifications
      1. Displaying comments as notifications
      2. Installing Views and Views Datasource
      3. Creating a JSON view
      4. The comment watcher
        1. The comment watcher behavior
        2. The CommentWatcher.check() function
        3. Theming the comment notification
        4. Managing cookies
    4. Summary
  13. 8. Building a Module
    1. How modules work
      1. The module structure
        1. The directory
        2. The .info file
        3. The .module file
        4. Where do modules go?
    2. Project: creating a JavaScript loader module
      1. Creating the module directory
      2. A JavaScript sample
      3. The module's .info file
        1. A custom addition
      4. The .module file
        1. The jsloader_help() function
        2. The jsloader_init() function
    3. Project: the editor revisited
      1. First step: creating the module
      2. The CSS file
      3. The bettereditor.module file
      4. The bettereditor.js script
        1. The editor() behavior
        2. The insertTag() function
        3. The addTag() theme
        4. The button() theme function
        5. The buttonBar() theme function
      5. A last question
    4. Summary
  14. 9. Integrating and Extending
    1. Project: autocompletion and search
      1. The theory
      2. Our plan
      3. First step: creating the taxonomy
      4. The new module
      5. The search autocomplete JavaScript
    2. Project: jQuery UI
      1. What is jQuery UI?
      2. Getting jQuery UI
      3. The accordion module
      4. The .info and .module files
      5. The accordion JavaScript
    3. Project: writing a jQuery plug-in
      1. The plug-in code
        1. A brief introduction to closures
        2. The divWrap() function
    4. Summary