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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

284<br />

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

}<br />

},<br />

edata = date.split('-'),<br />

// Extracts the calendar month from the H2 ID<br />

cdata = $("h2").attr("id").split('-');<br />

// Sets the date for the calendar date object<br />

cal.setFullYear(cdata[1], cdata[2], 1);<br />

// Sets the date for the event date object<br />

event.setFullYear(edata[0], edata[1], edata[2]);<br />

// Since the date object is created using<br />

// GMT, then adjusted for the local timezone,<br />

// adjust the offset to ensure a proper date<br />

event.setMinutes(event.getTimezoneOffset());<br />

// If the year <strong>and</strong> month match, start the process<br />

// of adding the new event to the calendar<br />

if ( cal.getFullYear()==event.getFullYear()<br />

&& cal.getMonth()==event.getMonth() )<br />

{<br />

// Gets the day of the month for event<br />

var day = String(event.getDate());<br />

}<br />

// Adds a leading zero to 1-digit days<br />

day = day.length==1 ? "0"+day : day;<br />

// Adds the new date link<br />

$("")<br />

.hide()<br />

.attr("href", "view.php?event_id="+data)<br />

.text(entry.event_title)<br />

.insertAfter($("strong:contains("+day+")"))<br />

.delay(1000)<br />

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

"deserialize" : function(str){...},<br />

"urldecode" : function(str) {...}<br />

■ Note The data variable is undefined as of right now. You’ll remedy this in the next section.<br />

Now, back in the click event h<strong>and</strong>ler for the Submit button, modify the success callback of the<br />

$.ajax() function to execute fx.addevent() <strong>by</strong> using the following bold code:

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

Saved successfully!

Ooh no, something went wrong!