Skip to main content

Search and Top Navigation

#7749 closed enhancement (duplicate)

Opened September 29, 2011 04:37PM UTC

Closed September 29, 2011 05:33PM UTC

Last modified September 29, 2011 05:33PM UTC

In options, support functions wherever selectors can be used

Reported by: cowboy Owned by:
Priority: minor Milestone: 1.9.0
Component: ui.widget Version: 1.8.16
Keywords: Cc:
Blocked by: Blocking:
Description

It would be great if Widget had a helper function like this (but better named):

_selectorOrFunction: function(arg) {
  return $.isFunction(arg) ? arg.call(this.element) : $(arg);
}

This function, when used to process an option, would allow a user to pass in a value that's a:

  • CSS selector string
  • DOM element
  • Array of DOM elements
  • jQuery object
  • Function that returns a jQuery object.

I used this code in a recent project, and it really helped. I'd even go so far as to say that anywhere a selector string (or any of the other preceding bullet point items) can currently be used, this processing could automatically be applied.

Of course, if a selector string is used, it doesn't do a relative find by default, but the tradeoff is that it offers a lot more flexibility. If that were a problem:

_selectorOrFunction: function(arg) {
  return $.isFunction(arg) ? arg.call(this.element) : this.element.find(arg);
}

Maybe this would be the most consistent / backwards compatible with jQuery UI:

_selectorOrFunction: function(arg) {
  return $.isFunction(arg) ? arg.call(this) : this.element.find(arg);
}

Either way, those are my 2¢. Thanks.

Attachments (0)
Change History (3)

Changed September 29, 2011 04:46PM UTC by gnarf comment:1

im in support of something like this - maybe even

 _find 
for a name if it echoes .element.find()

Changed September 29, 2011 05:33PM UTC by scottgonzalez comment:2

resolution: → duplicate
status: newclosed

Changed September 29, 2011 05:33PM UTC by scottgonzalez comment:3

Duplicate of #4957.