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.

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

You may have noticed that the modal window appears to flicker right as it’s opened. This happens<br />

because fx.initModal() appends the modal window to the body element without hiding it. To correct<br />

this, add a call to .hide() in fx.initModal() using the following bold code:<br />

// Functions to manipulate the modal window<br />

fx = {<br />

};<br />

// Checks for a modal window <strong>and</strong> returns it, or<br />

// else creates a new one <strong>and</strong> returns that<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 />

.hide()<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 />

// Code omitted for brevity<br />

},<br />

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

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

// Code omitted for brevity<br />

}<br />

Finally, clicking the Close button does not remove the overlay. To fade out <strong>and</strong> remove the overlay,<br />

simply modify the selector in fx.boxout() to include the class modal-overlay:<br />

// Functions to manipulate the modal window<br />

fx = {<br />

// Checks for a modal window <strong>and</strong> returns it, or<br />

// else creates a new one <strong>and</strong> returns that<br />

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

// Code omitted for brevity<br />

261

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

Saved successfully!

Ooh no, something went wrong!