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.

354<br />

CHAPTER 10 ■ EXTENDING JQUERY<br />

};<br />

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

Creating a Publicly Accessible Helper Method<br />

To keep your plugin code clean <strong>and</strong> organized, you will place the actual animation of the elements in a<br />

helper method called zoom.<br />

This method, like the defaults object, will be publicly accessible under the dateZoom namespace.<br />

Making this method public means that a user can potentially redefine the method before calling the<br />

plugin or even call the method outside of the plugin, if he so desires.<br />

You create the zoom method <strong>by</strong> inserting the following bold code into the dateZoom plugin:<br />

(function($){<br />

// A plugin that enlarges the text of an element when moused<br />

// over, then returns it to its original size on mouse out<br />

$.fn.dateZoom = function(options)<br />

{<br />

// Only overwrites values that were explicitly passed <strong>by</strong><br />

// the user in options<br />

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

};<br />

// Loops through each matched element <strong>and</strong> returns the<br />

// modified <strong>jQuery</strong> object to maintain chainability<br />

return this.each(function(){<br />

// more code here<br />

});<br />

// Defines default values for the plugin<br />

$.fn.dateZoom.defaults = {<br />

"fontsize" : "110%",<br />

"easing" : "swing",<br />

"duration" : "600",<br />

"callback" : null<br />

};<br />

// Defines a utility function that is available outside of the<br />

// plugin if a user is so inclined to use it<br />

$.fn.dateZoom.zoom = function(element, size, opts)<br />

{<br />

// zoom the elements<br />

};<br />

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

This method accepts the element to animate, the size to which it should be animated, <strong>and</strong> an object<br />

containing options.

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

Saved successfully!

Ooh no, something went wrong!