As newcomer here I would like to chime in :)
The naming sounds confusing to me, and it does not follow the pattern set by other jQuery functions. None of the jQuery core (or UI methods I've encountered so far) methods use "set" in their name but base their name solely on their task or the widget they are managing. In addition the naming is very non-intuitive. If I am reading code and I see calls to focus() and setFocus() mixed it would just confuse me.
I suspect the best approach to keep the API clean and intuitive is to fold this into the core focus() method and expose it via an option. Something like $(this).focus({delay: 500, async : true}); If that I would go for Eduardo's suggestion to rename it to asyncFocus (or delayedFocus?): that immediately reveals the purpose of the method in its name.
Regards,
Wichert.
On 1/21/09 11:30 PM, Scott González wrote:Currently the idea is to use setFocus for the name (unanimous so far - it's what we've been using in the experimental branch). The current implementation does accept a delay like you've suggested, but does not allow for not passing a value and doing it synchronously. If you want a synchronous focus, use .focus() - .setFocus() will default to a 1ms delay.
You can see the current implementation at http://jquery-ui.googlecode.com/svn/branches/experimental/tabbable/ui.core.js
Really the only question to answer is whether this should force the element to be focusable or whether it should be up to the developer to ensure the element is focusable before trying to set focus.
On Wed, Jan 21, 2009 at 12:58 PM, Eduardo Lundgren <eduardo...@gmail.com> wrote:
If we keep the name .delayedFocus() we have to give the possibility to specify the delay in ms to be compatible with the name.
If we use setFocus() and receive a parameter like:
- .setFocus(1) - use the asynchronous focus with 1ms of delaying.
- .setFocus() - use the synchronous focus, without setTimeout.
What about .asyncFocus() with no parameters ? this name means that I want to set the focus asap (0 or 1 ms) and asynchronously.--
On Wed, Jan 21, 2009 at 6:38 AM, Scott González <scott.g...@gmail.com> wrote:
Should this method force the element to be focusable? This would
happen by checking if the element has a tabindex and if it doesn't, it
would set it to -1 before setting focus. Or, should it just try to
set focus and fail silently?
Eduardo Lundgren
Software Engineer
Liferay, Inc.
Enterprise. Open Source. For Life.
How about overriding $.fn.focus so it behaves as follows:
- no parameters = trigger focus immediately (current behavior)
- function as parameter = bind handler to focus event (current behavior)
- number as parameter = trigger focus asynchronously with a <number> ms delay (new behavior)
As newcomer here I would like to chime in :)
The naming sounds confusing to me, and it does not follow the pattern set by other jQuery functions. None of the jQuery core (or UI methods I've encountered so far) methods use "set" in their name but base their name solely on their task or the widget they are managing. In addition the naming is very non-intuitive. If I am reading code and I see calls to focus() and setFocus() mixed it would just confuse me.
I suspect the best approach to keep the API clean and intuitive is to fold this into the core focus() method and expose it via an option. Something like $(this).focus({delay: 500, async : true}); If that I would go for Eduardo's suggestion to rename it to asyncFocus (or delayedFocus?): that immediately reveals the purpose of the method in its name.
On Thu, Jan 22, 2009 at 5:12 PM, Scott González <scott.g...@gmail.com> wrote:
How about overriding $.fn.focus so it behaves as follows:
- no parameters = trigger focus immediately (current behavior)
- function as parameter = bind handler to focus event (current behavior)
- number as parameter = trigger focus asynchronously with a <number> ms delay (new behavior)
+1
How about overriding $.fn.focus so it behaves as follows:
- no parameters = trigger focus immediately (current behavior)
- function as parameter = bind handler to focus event (current behavior)
- number as parameter = trigger focus asynchronously with a <number> ms delay (new behavior)
To keep things consistent both function and number should be supported as well.
The former indeed. Similar to other jQuery methods the possible calling
options should imho be:
.focus()
.focus(delay)
.focus(delay, callback)
all of which should return the jQuery instance so they chain properly.
.focus(callback) does not add anything useful that I can think of, and I
can find no other jQuery with that calling convention.
The second
--
Wichert Akkerman <wic...@wiggy.net> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.
.focus(callback) does not add anything useful that I can think of, and I
can find no other jQuery with that calling convention.