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

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

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

Creating Date Objects<br />

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

Because only events created for the month being displayed should be added to the calendar, you need to<br />

determine what month <strong>and</strong> year is being displayed, as well as the month <strong>and</strong> year that the event occurs.<br />

■ Note For this step you’ll take advantage of JavaScript’s built-in Date object, which provides methods to simplify<br />

many date-related operations. For a full explanation of all available methods associated with the Date object, visit<br />

http://w3schools.com/jsref/jsref_obj_date.asp.<br />

Modifying the Calendar Class with an ID<br />

To generate a Date object for the currently displayed month, you need to add an ID to the h2 element<br />

that displays the month above the calendar. To ensure cross-browser compatibility, modify the<br />

buildCalendar() method in the Calendar class with the following bold code:<br />

public function buildCalendar()<br />

{<br />

/*<br />

* Determine the calendar month <strong>and</strong> create an array of<br />

* weekday abbreviations to label the calendar columns<br />

*/<br />

$cal_month = date('F Y', strtotime($this->_useDate));<br />

$cal_id = date('Y-m', strtotime($this->_useDate));<br />

$weekdays = array('Sun', 'Mon', 'Tue',<br />

'Wed', 'Thu', 'Fri', 'Sat');<br />

}<br />

/*<br />

* Add a header to the calendar markup<br />

*/<br />

$html = "\n\t$cal_month";<br />

for ( $d=0, $labels=NULL; $d

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

Saved successfully!

Ooh no, something went wrong!