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.

});<br />

var action = "edit_event";<br />

// Loads the editing form <strong>and</strong> displays it<br />

$.ajax({<br />

type: "POST",<br />

url: processFile,<br />

data: "action="+action,<br />

success: function(data){<br />

// Hides the form<br />

var form = $(data).hide(),<br />

});<br />

// Make sure the modal window exists<br />

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

// Call the boxin function to create<br />

// the modal overlay <strong>and</strong> fade it in<br />

fx.boxin(null, modal);<br />

// Load the form into the window,<br />

// fades in the content, <strong>and</strong> adds<br />

// a class to the form<br />

form<br />

.appendTo(modal)<br />

.addClass("edit-form")<br />

.fadeIn("slow");<br />

},<br />

error: function(msg){<br />

alert(msg);<br />

}<br />

Determining the Form Action<br />

CHAPTER 8 ■ EDITING THE CALENDAR WITH AJAX AND JQUERY<br />

In the editing controls displayed for individual events, the button names describe the action taken <strong>by</strong> the<br />

button (e.g., edit_event for the Edit This Event button <strong>and</strong> delete_event for the Delete This Event<br />

button). These buttons will be used <strong>by</strong> ajax.inc.php as the action for the submission.<br />

Because the event creation button doesn’t have a button name, you need to keep a default value<br />

(edit_event).<br />

To access the name of the clicked button, you’ll use a property of the event object called target.<br />

This property contains a reference to the element that triggered the event. Use <strong>jQuery</strong> to select the event<br />

target <strong>and</strong> use .attr() to retrieve its name.<br />

Now modify the event h<strong>and</strong>ler using the following bold code:<br />

// Displays the edit form as a modal window<br />

$(".admin-options form,.admin").live("click", function(event){<br />

// Prevents the form from submitting<br />

event.preventDefault();<br />

291

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

Saved successfully!

Ooh no, something went wrong!