It will actually be 2 instances of the plugin on 2 elements: $ ('#test').data('bbcode'), and $('#test2').data('bbcode')
Thanks for those links, those will help me figure it out, although it doesn't look easy :) On Dec 6, 1:08 pm, "Richard D. Worth" <[EMAIL PROTECTED]> wrote: > On Sat, Dec 6, 2008 at 11:53 AM, Brian Ronk <[EMAIL PROTECTED]> wrote: > > > That might work. I'll tinker with that. How does it work with > > multiple instances of the same plugin through? Where I'm using it, I > > am going to be pulling data from 2 instances of the plugin. Maybe I > > could have two different names... I think that would work. > > Data has support for namespaces. So if your plugin is called foo, and > someone else has a bar plugin, each bbcode property can be separated be like > so: > > $("#test").data("bbcode.foo", fooBbcode); > $("#test").data("bbcode.bar", barBbcode); > > same for getting. So that's with two plugins with different names, but you > maybe figure out something based on that. It's tricky to do two instances of > the same plugin on the same element, because how does the user select one or > the other? Get's even more complex if you have a set of elements (more than > one element in the jQuery object on which you call your plugin method). > > > > > Although, I would like to know how to make my plugin accept a method > > call. > > You can do it by inspecting the type of the first parameter passed to the > plugin method. Usually that would be a hash containing init options. If it's > called again and is a string then you can treat that as a method name, and > do the appropriate thing (dispatch an internal function in your plugin, > probably). This is all abstracted quite nicely in the widget plugin created > by Scott González and Jörn Zaefferer. It's used as a base for all jQuery UI > widgets, and can be found here: > > http://jquery-ui.googlecode.com/svn/trunk/ui/ui.core.js > > You can look at most any jQuery UI widget for an example of use. Here's a > fairly simple one: > > http://jquery-ui.googlecode.com/svn/trunk/ui/ui.progressbar.js > > And here are some examples of use (including init, modifying options, > calling methods, destroying): > > http://jquery-ui.googlecode.com/svn/trunk/tests/visual/progressbar.html > > Notice you can declare an _init (near the beginning of the file) that gets > called at init (the first time the plugin method is called on an element), > with optional options that override any defaults (declared near the end of > the file). Any functions you declare without an underscore (_) at the > beginning are public. Also notice you can declare _getData and _setData. > These let you handle any get/set of your data keys in your plugin's > namespace. It's really quite a nice factory. If you end up making use of it > and have any further questions, you can get help on the jQuery UI list: > > http://groups.google.com/group/jquery-ui > > - Richard > > Richard D. Worthhttp://rdworth.org/