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.

Calling the Utility Function from the Event H<strong>and</strong>ler<br />

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

Next, modify the click event h<strong>and</strong>ler to load the result of fx.initModal into a variable for use in the<br />

script <strong>by</strong> adding the following bold code in init.js:<br />

// Pulls up events in a modal window<br />

$("li>a").live("click", function(event){<br />

});<br />

// Stops the link from loading view.php<br />

event.preventDefault();<br />

// Adds an "active" class to the link<br />

$(this).addClass("active");<br />

// Gets the query string from the link href<br />

var data = $(this)<br />

.attr("href")<br />

.replace(/.+?\?(.*)$/, "$1"),<br />

// Checks if the modal window exists <strong>and</strong><br />

// selects it, or creates a new one<br />

modal = fx.initModal();<br />

■ Note The semicolon after the data variable has been replaced with a comma in this example.<br />

Save, then reload http://localhost/ <strong>and</strong> click one of the event titles to cause a modal window to<br />

appear on the screen (see Figure 7-1).<br />

245

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

Saved successfully!

Ooh no, something went wrong!