[jQuery] Re: Creating a Plugin
You could store the bbcode in the element's jQuery data store: $(#test).data(bbcode, ...); and you can get it back out by var bbcode = $(#test).data(bbcode); See http://docs.jquery.com/Core/data for more info. Please let me know if your question goes further into how to make your plugin accept a method call that would then return this data. - Richard On Fri, Dec 5, 2008 at 2:27 AM, Brian Ronk [EMAIL PROTECTED] wrote: I'm making an edit in place plugin, and am running into an issue, mainly because I'm not sure how to do it. The data I am working with is bbcode, so what is seen on screen (non editing) is not bbcode, but it decoded. I would like to be able to return the bbcode to work with it in another area. I'm just not sure how to do that. What I'd like to be able to do is to initialize it: $('#test').bbcode (); and then be able to call it again (or something) to get the actual bbcode out. So, something like $('#test').bbcode('code'); or $ ('#test').showcode(); It basically works right now, except for the returning data. I'm just not sure on how to procede to do that.
[jQuery] Re: Creating a Plugin
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. Although, I would like to know how to make my plugin accept a method call. On Dec 6, 9:05 am, Richard D. Worth [EMAIL PROTECTED] wrote: You could store the bbcode in the element's jQuery data store: $(#test).data(bbcode, ...); and you can get it back out by var bbcode = $(#test).data(bbcode); Seehttp://docs.jquery.com/Core/datafor more info. Please let me know if your question goes further into how to make your plugin accept a method call that would then return this data. - Richard On Fri, Dec 5, 2008 at 2:27 AM, Brian Ronk [EMAIL PROTECTED] wrote: I'm making an edit in place plugin, and am running into an issue, mainly because I'm not sure how to do it. The data I am working with is bbcode, so what is seen on screen (non editing) is not bbcode, but it decoded. I would like to be able to return the bbcode to work with it in another area. I'm just not sure how to do that. What I'd like to be able to do is to initialize it: $('#test').bbcode (); and then be able to call it again (or something) to get the actual bbcode out. So, something like $('#test').bbcode('code'); or $ ('#test').showcode(); It basically works right now, except for the returning data. I'm just not sure on how to procede to do that.
[jQuery] Re: Creating a Plugin
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. Worth http://rdworth.org/
[jQuery] Re: Creating a Plugin
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/
[jQuery] Re: Creating a Plugin
On Sat, Dec 6, 2008 at 2:38 PM, Brian Ronk [EMAIL PROTECTED] wrote: It will actually be 2 instances of the plugin on 2 elements: $ ('#test').data('bbcode'), and $('#test2').data('bbcode') That's no problem. Each of those elements has their own data store. If you end up going the widget factory route, they'll each have their own instance of that widget-based plugin. - Richard Thanks for those links, those will help me figure it out, although it doesn't look easy :) No problem. Do let us know how it goes. We still need to document better how it all works, and how to make use of it, so your perspective is very valuable. - Richard
[jQuery] Re: Creating a Plugin
I don't think that will work for a few reasons. I have to be able to see the decoded text in a certain size, thus what I have is something where you click on the editable area, and it switches to editing. Plus, I have a few custom bbcodes that are being used, and I didn't see a way to add them. Granted, I could have missed. Thanks for that link though, it might come in handy somewhere else. On Dec 5, 2:41 am, Kevin Kietel [EMAIL PROTECTED] wrote: How about this jQuery editor: http://markitup.jaysalvat.com/ it's called markItUp! and uses Html, Textile, Wiki Syntax, Markdown, BBcode On 5 dec, 08:27, Brian Ronk [EMAIL PROTECTED] wrote: I'm making an edit in place plugin, and am running into an issue, mainly because I'm not sure how to do it. The data I am working with is bbcode, so what is seen on screen (non editing) is not bbcode, but it decoded. I would like to be able to return the bbcode to work with it in another area. I'm just not sure how to do that. What I'd like to be able to do is to initialize it: $('#test').bbcode (); and then be able to call it again (or something) to get the actual bbcode out. So, something like $('#test').bbcode('code'); or $ ('#test').showcode(); It basically works right now, except for the returning data. I'm just not sure on how to procede to do that.
[jQuery] Re: Creating a Plugin
How about this jQuery editor: http://markitup.jaysalvat.com/ it's called markItUp! and uses Html, Textile, Wiki Syntax, Markdown, BBcode On 5 dec, 08:27, Brian Ronk [EMAIL PROTECTED] wrote: I'm making an edit in place plugin, and am running into an issue, mainly because I'm not sure how to do it. The data I am working with is bbcode, so what is seen on screen (non editing) is not bbcode, but it decoded. I would like to be able to return the bbcode to work with it in another area. I'm just not sure how to do that. What I'd like to be able to do is to initialize it: $('#test').bbcode (); and then be able to call it again (or something) to get the actual bbcode out. So, something like $('#test').bbcode('code'); or $ ('#test').showcode(); It basically works right now, except for the returning data. I'm just not sure on how to procede to do that.