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.

[ 179 ]<br />

Chapter 6<br />

The other two message levels function similarly, but warning will create a yellow<br />

box <strong>and</strong> status will create a grey box (colors, of course, are determined by the CSS).<br />

If you are using this module, the <strong>Drupal</strong>.messages.set() function is a good tool for<br />

providing user notifications.<br />

Adding links<br />

There are many useful functions in the <strong>JavaScript</strong> theming library, but to save space<br />

(<strong>and</strong> cover more ground regarding theming), we will cover only one more. This<br />

function is <strong>Drupal</strong>.l(), <strong>and</strong> it is the main function used for creating links.<br />

Those familiar with PHP programming for <strong>Drupal</strong>, will find it unsurprising that<br />

<strong>Drupal</strong>.l() provides the same functionality as the <strong>Drupal</strong> PHP l() function. It is<br />

typically called in this way:<br />

<strong>Drupal</strong>.l(text, url);<br />

Here, text is the text that will be linked <strong>and</strong> url is the relative URL of a <strong>Drupal</strong><br />

resource. For example, we could create a link to the fifth node in our system like this:<br />

<strong>Drupal</strong>.l('Node 5', 'node/5');<br />

This would return a string of HTML that looked like this:<br />

Node 5<br />

Note that the link for the base path on my system has been adjusted. It has turned<br />

node/5 into /drupal/node/5.<br />

There is an optional third parameter which can contain additional options. These<br />

options are all documented at http://api.drupal.org/api/function/l/6. For<br />

example, if we wanted to use an absolute URL, instead of a relative one, we could set<br />

the absolute property to true:<br />

<strong>Drupal</strong>.l('<strong>Drupal</strong>', 'http://drupal.org', {'absolute':true});<br />

This would result in a link pointing to http://drupal.org, instead of a relative link<br />

to our own server.<br />

The <strong>JavaScript</strong> theming module provides some useful tools for extending the<br />

<strong>JavaScript</strong> capabilities of your <strong>Drupal</strong> 6 system.<br />

Next up, we are going to work on another project. In this project, we will implement<br />

a simple template system.<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!