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.

[ 215 ]<br />

Chapter 7<br />

Since we just want the items from the feed, we can use the <strong>jQuery</strong> find() function,<br />

which takes a CSS selector to query the DOM. The query that we just saw, will return<br />

all of the elements. WebClips.items, a variable that belongs<br />

to our main WebClips object, is a <strong>jQuery</strong> object wrapping a list of the <br />

elements.<br />

Why do we store the items in WebClips.items? We do that since we want this list<br />

to be accessible to other WebClips functions. Here, we will make the list globally<br />

available. Other functions will retrieve data from this list of items.<br />

Next, we begin building the display for our web clips area:<br />

var clip = <strong>Drupal</strong>.theme('webclipArea', 'webclips');<br />

$('#main').addClass('webclips-processed').prepend(clip);<br />

First, we use <strong>Drupal</strong>.theme() to create the web clips area. This function, which<br />

we will look at in just a moment, takes one argument. The argument is the ID<br />

(webclips) for the web clips area. We will use that later to find the area <strong>and</strong><br />

exchange the clip (the RSS feed item) displayed in that area.<br />

Before moving on to the rest of this function, let's take a quick look at the <strong>Drupal</strong>.<br />

theme.prototype.webclipArea() theming function. This function is responsible<br />

for defining the region where the web clips will be displayed. However, individual<br />

web clips will be themed separately as seen here:<br />

<strong>Drupal</strong>.theme.prototype.webclipArea = function (id) {<br />

var tpl = '';<br />

return tpl;<br />

};<br />

This function simply builds some HTML that looks like this:<br />

';<br />

There is a with the class webclip-area. Inside of this is an empty<br />

tag. Above, I've used ID as a placeholder for the ID that is passed<br />

into the theming function. Ours will have the ID webclips.<br />

The theme is executed in the behavior <strong>and</strong> the results are stored in clip.<br />

Once we have a themed the clip area, we insert that into the DOM at the top of the<br />

main content area (the element with the ID main). To make sure the behavior doesn't<br />

run again, we need to add the webclips-processed class to the element with the<br />

main ID. Then, using the prepend() <strong>jQuery</strong> function, we add the web clip section<br />

directly inside the main section before any other content.<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!