06.05.2013 Views

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

Drupal 6 JavaScript and jQuery - Ebook-Cours.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Integrating <strong>and</strong> Extending<br />

Let's take a look at the beginning of this function:<br />

$('input[name="search_block_form"]:not(.form-auto<strong>com</strong>plete)')<br />

.each(function () {<br />

// More code here...<br />

}).addClass('form-auto<strong>com</strong>plete');<br />

This first <strong>jQuery</strong> object grabs elements that match the query input[name="<br />

search_block_form"]:not(.form-auto<strong>com</strong>plete). This is a little longer<br />

than our usual query, but it is not difficult to underst<strong>and</strong>.<br />

The query is <strong>com</strong>posed of three parts: an element query (input), an attribute<br />

query ([name="search_block_form"]), <strong>and</strong> a negation pseudo-class (:not(.<br />

form-auto<strong>com</strong>plete)). In short, the query looks for all elements with<br />

an attribute name that has the value search_block_form. But due to the negation<br />

pseudo-class, only elements that don't have the class form-auto<strong>com</strong>plete match.<br />

The search_block_form name is used by the search module when it<br />

creates a block containing a search text field. This part of the script could<br />

be extended to find other text fields <strong>and</strong> turn them into auto<strong>com</strong>pletion<br />

fields. For example, to enable auto<strong>com</strong>pletion in your theme's search box,<br />

you would use the name search_theme_form.<br />

In short, it matches all search text boxes that don't already have an auto<strong>com</strong>plete<br />

feature. This query should match any <strong>Drupal</strong> search block, which typically looks<br />

something like this:<br />

<br />

As we can see from the previous code, it iterates through each of the matching<br />

elements. In a moment, we will look at what happens to each element as it is iterated<br />

over. Then, once that is done, the class form-auto<strong>com</strong>plete is added to each of the<br />

matching elements.<br />

[ 296 ]<br />

This material is copyright <strong>and</strong> is licensed for the sole use by Richard Ostheimer on 18th June 2009<br />

2205 hilda ave., , missoula, , 59801

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!