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.

};<br />

},<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 />

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

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

Appending the Event to the Calendar<br />

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

You’re finally ready to append the new event to the calendar. To do so, create a new anchor element,<br />

hide it, set its href attribute, <strong>and</strong> use the title of the event as the link text.<br />

Next, set a one-second delay using .delay(1000) <strong>and</strong> fade in the new event.<br />

You can implement this <strong>by</strong> adding the following code shown in bold:<br />

fx = {<br />

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

"boxin" : function(data, modal) {...},<br />

"boxout" : function(event) {...},<br />

// Adds a new event to the markup after saving<br />

"addevent" : function(data, formData){<br />

// Converts the query string to an object<br />

var entry = fx.deserialize(formData),<br />

// Makes a date object for current month<br />

cal = new Date(NaN),<br />

// Makes a date object for the new event<br />

event = new Date(NaN),<br />

// Extracts the event day, month, <strong>and</strong> year<br />

date = entry.event_start.split(' ')[0],<br />

// Splits the event data into pieces<br />

283

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

Saved successfully!

Ooh no, something went wrong!