On Fri, May 9, 2008 at 3:33 PM, Adam V <[EMAIL PROTECTED]> wrote:

>
> Hey all,
>
> I've gone through some of the more obvious resources on creating
> jQuery Plugins (Mike Alsop's Plugin pattern, the documentation on
> docs.jquery.com, etc.) and I think I have a handle on things. There
> are a few things for which I can't seem to find a good explanation.
>
> First, I notice that much of the jQuery UI widgets make use of the
> dataCache (http://docs.jquery.com/Core/data#name) to keep references
> to things but I can't find anything that describes how or why you'd
> want to do such a thing.


.data() is used anywhere you want to store data on a DOMElement, instead of
expando properties. This is perfect for widget-style plugins that have all
sorts of settings/options (plus the instance itself) that need to be stored
on each element that "is" that widget. Also, there's namespacing, for a
single element being multiple widgets. For example:

$("#myEl").data("width")

can be handled by a different getter/plugin than

$("#myEl").data("width.dialog")

which can both be entirely different than

$("#myEl").width()

pretty key when (as in the case of dialog) the width of the original element
(the content of the dialog) is very different than the dialog itself (a
wrapper with chrome+padding)


> Second, the latest versions of jQuery UI (1.5?) uses the same sort of
> overloading that jQuery itself uses to simplfy the interaface. See,
> for example, the interface for Tabs (http://docs.jquery.com/UI/Tabs).
> I like this pattern and I could implement it myself, but I'm hoping
> that there is a standard, simple way to implement it.


There is a widget factory in ui.core.js that Scott and Jörn developed. For
an example of doing the same without that, see a couple files in UI 1.5b2
(before the factory was added):

http://dev.jquery.com/view/tags/ui/1.5b2/ui.selectable.js (lines 17-30, init
with options, plugin methods)
http://dev.jquery.com/view/tags/ui/1.5b2/ui.dialog.js (lines 50-97, plugin
property getters and setters)

This all needs better documenting. It's all quite new.

- Richard

Richard D. Worth
http://rdworth.org/

Reply via email to