We've got a lot of plugins that take an element as a option's value (position's of, draggable's helper, etc.). Each of these work slightly differently because there are so many cases to handle that some of them get overlooked. I wrote a function a long time ago to handle this, but never ended up using it anywhere. Here are the cases I came up with back then as possible options:
Note: In many cases there is a context for determining the element. For example, draggable's helper has a context of the actual draggable element.
jQuery object - just return the object again DOMElement - wrap it in a jQuery object array of DOMElements - wrap them in a jQuery object selector - return the jQuery object that matches the selection the string "parent" - return the parent of the context element the string "clone" - return a clone of the context element function - return the result of executing the function and passing the context element as a parameter anything else - return an empty jQuery object
I'd like to go through and test this on all of our plugins, but I wanted to see if anything had any other cases that we should be handling.
> We've got a lot of plugins that take an element as a option's value
> (position's of, draggable's helper, etc.). Each of these work slightly
> differently because there are so many cases to handle that some of them get
> overlooked. I wrote a function a long time ago to handle this, but never
> ended up using it anywhere. Here are the cases I came up with back then as
> possible options:
> Note: In many cases there is a context for determining the element. For
> example, draggable's helper has a context of the actual draggable element.
> jQuery object - just return the object again
> DOMElement - wrap it in a jQuery object
> array of DOMElements - wrap them in a jQuery object
> selector - return the jQuery object that matches the selection
> the string "parent" - return the parent of the context element
> the string "clone" - return a clone of the context element
> function - return the result of executing the function and passing the
> context element as a parameter
> anything else - return an empty jQuery object
> I'd like to go through and test this on all of our plugins, but I wanted to
> see if anything had any other cases that we should be handling.
> We've got a lot of plugins that take an element as a option's value
> (position's of, draggable's helper, etc.). Each of these work slightly
> differently because there are so many cases to handle that some of them get
> overlooked. I wrote a function a long time ago to handle this, but never
> ended up using it anywhere. Here are the cases I came up with back then as
> possible options:
> Note: In many cases there is a context for determining the element. For
> example, draggable's helper has a context of the actual draggable element.
> jQuery object - just return the object again
> DOMElement - wrap it in a jQuery object
> array of DOMElements - wrap them in a jQuery object
> selector - return the jQuery object that matches the selection
> the string "parent" - return the parent of the context element
> the string "clone" - return a clone of the context element
> function - return the result of executing the function and passing the
> context element as a parameter
> anything else - return an empty jQuery object
> I'd like to go through and test this on all of our plugins, but I wanted to
> see if anything had any other cases that we should be handling.
> We've got a lot of plugins that take an element as a option's value
> (position's of, draggable's helper, etc.). Each of these work slightly
> differently because there are so many cases to handle that some of them get
> overlooked. I wrote a function a long time ago to handle this, but never
> ended up using it anywhere. Here are the cases I came up with back then as
> possible options:
> Note: In many cases there is a context for determining the element. For
> example, draggable's helper has a context of the actual draggable element.
> jQuery object - just return the object again
> DOMElement - wrap it in a jQuery object
> array of DOMElements - wrap them in a jQuery object
> selector - return the jQuery object that matches the selection
> the string "parent" - return the parent of the context element
> the string "clone" - return a clone of the context element
> function - return the result of executing the function and passing the
> context element as a parameter
> anything else - return an empty jQuery object
> I'd like to go through and test this on all of our plugins, but I wanted to
> see if anything had any other cases that we should be handling.
On Fri, Nov 13, 2009 at 7:44 AM, Richard D. Worth <rdwo...@gmail.com> wrote:
> the string "self" - return the context element ? Or maybe "this" ?
I think everywhere that we would currently do this we just use null for the option, e.g., draggable's helper. I'm not sure if that means we should return the context element as a fallback instead of an empty jQuery object or if we should add "self" as an option and make that the default for draggable's helper option. A third option would be to have the plugin check if a value even exists:
var helper = options.helper ? element(options.helper) : this.element;
I'd prefer not having to do that check, so I think one of the first two options is better.
joern.zaeffe...@googlemail.com> wrote: > Ok, one more: Where would you put that method and how to you call it? On > the widget prototype? A static method in the $.ui namespace?
I'd want to put it in the $.ui namespace because it is useful outside of widgets. I'm not sure what to name it though.
Usage: var helper = $.ui.element(this.options.helper, this.element);