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.

348<br />

CHAPTER 10 ■ EXTENDING JQUERY<br />

Performing Validation <strong>and</strong> Returning a Value<br />

This step is nearly identical to one in the original function, except you access the pattern here through<br />

the opts object:<br />

(function($){<br />

// Extends the <strong>jQuery</strong> object to validate date strings<br />

$.validDate = function(date, options)<br />

{<br />

// Sets up default values for the method<br />

var defaults = {<br />

"pattern" : /^\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}$/<br />

},<br />

};<br />

})(<strong>jQuery</strong>);<br />

// Extends the defaults with user-supplied options<br />

opts = $.extend(defaults, options);<br />

// Returns true if a match is found, false otherwise<br />

return date.match(opts.pattern)!=null;<br />

Conforming to <strong>jQuery</strong> Plugin File Naming Conventions<br />

To officially call a plugin a plugin, you must use the <strong>jQuery</strong> naming conventions for your plugin files. The<br />

accepted format is jquery.[name of plugin].js—to meet this guideline, change the name of validdate.js<br />

to jquery.validDate.js.<br />

Modifying the Include Script<br />

Now that the file name has changed, you need to update footer.inc.php to include it. Make the changes<br />

shown in bold to load the correct file:<br />

<br />

<br />

google.load("jquery", "1");<br />

<br />

<br />

<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!