> Having a little trouble finding good examples of uses for the core
> function data(). Anyone know of a tutorial or some such on this?

A lot of plugins use this capability.  For example, I use it in
BlockUI and Cycle.  It's a great way to store data that you will need
later.  In Cycle I use "data" to store the options object.  I can then
access it from other functions later on or from the main plugin
function if it is called again (or from outside the plugin even).
This lets me do interesting things like allow the user to invoke cycle
once to set it up and then invoke it again with different arguments
that drive different behavior.  To illustrate:

// initialize and start a slideshow
$('#slideshow').cycle( { /* normal options object here * } );
...
// terminate the slideshow
$('#slideshow').cycle( 'stop' );
...
// resume the terminated slideshow (where it left off)
$('#slideshow').cycle( 'resume' );
...
// advance to a particular slide index
$('#slideshow').cycle( 5 );

Note that it this example it was not necessary for the user to pass in
the options over and over.  Internally, the plugin fetches the options
from the DOM element using the "data" functionality.  This is just one
concrete example; depending on your code "data" can be used in many
different ways.

Mike

Reply via email to