Creating a Slideshow (^) ❘ 451
var slideCollection = slideshows.length + 1;
slideshows[slideCollection] =
new slideshow(node, slideCollection);
node.data('slideshow', slideCollection);
}
}
);
}
});
Presently, the $.slideshow() method is called on each HTML element with a class name of slide-
show, and that happens automatically when the DOM is ready. When $.slideshow() is called, a
variable called slideCollection is created based on the number of slideshows already created. This
variable keeps track of each collection and makes it possible to go back and reference an existing
collection. Each slideshow in the document is numbered offset from one, and this data is stored with
each instance of the slideshow using the jQuery data API. If an instance does not have the associated
slideshow data attached to it, then it hasn’t been processed by the plugin. This makes it possible to
call the $.slideshow() plugin method as many times as you need to call it to create a slideshow over
the life of a document or application. New slideshows are created and added to the existing
collection of slideshows as needed.
The next bit of code is lifted from the website of John Resig (the creator of jQuery). It provides an
easy-to-reference factory method for creating prototype objects, which is to say a single object that
you can instantiate again and again, creating multiple copies, each with their own properties, tim-
ers, and settings, individually intact.
// From John Resig's awesome class instantiation code.
// http://ejohn.org/blog/simple-class-instantiation/
var hot = {
factory : function()
{
return function(args)
{
if (this instanceof arguments.callee)
{
if (typeof this.init == 'function')
{
this.init.apply(this, args && args.callee? args : arguments);
}
}
else
{
return new arguments.callee(arguments);
}
}
}
};
var slideshow = hot.factory();
http://www.it-ebooks.info
elliott
(Elliott)
#1