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.

258<br />

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

"initModal" : function() {<br />

// If no elements are matched, the length<br />

// property will be 0<br />

if ( $(".modal-window").length==0 )<br />

{<br />

// Creates a div, adds a class, <strong>and</strong><br />

// appends it to the body tag<br />

return $("")<br />

.addClass("modal-window")<br />

.appendTo("body");<br />

}<br />

else<br />

{<br />

// Returns the modal window if one<br />

// already exists in the DOM<br />

return $(".modal-window");<br />

}<br />

},<br />

// Adds the window to the markup <strong>and</strong> fades it in<br />

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

// Creates an overlay for the site, adds<br />

// a class <strong>and</strong> a click event h<strong>and</strong>ler, then<br />

// appends it to the body element<br />

$("")<br />

.hide()<br />

.addClass("modal-overlay")<br />

.click(function(event){<br />

// Removes event<br />

fx.boxout(event);<br />

})<br />

.appendTo("body");<br />

},<br />

// Loads data into the modal window <strong>and</strong><br />

// appends it to the body element<br />

modal<br />

.hide()<br />

.append(data)<br />

.appendTo("body");<br />

// Fades in the modal window <strong>and</strong> overlay<br />

$(".modal-window,.modal-overlay")<br />

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

// Fades out the window <strong>and</strong> removes it from the DOM<br />

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

// If an event was triggered <strong>by</strong> the element<br />

// that called this function, prevents the<br />

// default action from firing<br />

if ( event!=undefined )

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

Saved successfully!

Ooh no, something went wrong!