02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

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.

236<br />

CHAPTER 7 ■ ENHANCING THE USER INTERFACE WITH JQUERY<br />

Setting <strong>Pro</strong>gressive Enhancement Goals<br />

Using the principles of progressive enhancement, you’ll add the ability to view event information<br />

without a page refresh in a modal window, a content area that sits on top of existing markup to display<br />

additional information. Such windows are usually triggered <strong>by</strong> JavaScript, <strong>and</strong> they are used on many of<br />

today’s most popular web sites.<br />

In your calendar application, you’ll use a modal window to display event details after a user clicks<br />

the event title. This will be done without a page refresh using AJAX.<br />

Include <strong>jQuery</strong> in the Calendar App<br />

As you learned in the introduction to <strong>jQuery</strong> earlier in this book, using <strong>jQuery</strong> syntax requires that you<br />

first include the <strong>jQuery</strong> library. Because JavaScript files should be the last thing in your HTML markup<br />

before you the close body tag (), you’ll include the <strong>jQuery</strong> library <strong>and</strong> all subsequent files in<br />

footer.inc.php (/public/assets/common/footer.inc.php). Begin <strong>by</strong> including the latest version of <strong>jQuery</strong><br />

in your app; you accomplish this <strong>by</strong> adding the following bold lines to footer.inc.php:<br />

<br />

<br />

google.load("jquery", "1");<br />

<br />

<br />

<br />

Save this code, then load http://localhost/ in your browser. Open the Firebug console <strong>and</strong> execute<br />

the following comm<strong>and</strong> to ensure that <strong>jQuery</strong> is loaded in your app:<br />

$("h2").text();<br />

After running this comm<strong>and</strong>, the console will display the following output:<br />

>>> $("h2").text();<br />

"January 2010"<br />

■ Note Because you’re using the Google JSAPI, you need to have an Internet connection available, in addition to<br />

your Apache server. If you do not have access to an Internet connection or prefer not to use one, download the<br />

latest version of <strong>jQuery</strong> from http://jquery.com/ <strong>and</strong> include it instead.

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

Saved successfully!

Ooh no, something went wrong!