The only way i can see is to do something like:
var tabs = $('.tabs');
var selected = null;
tabs.find('li').each(function(i){
if($(this).hasClass('ui-tabs-selected'){
selected = i;
return false;
}
});
Could we add a method for this?
e.g. .tabs('selected') ?
Although it starts bleeding into general jQuery territory, it would be
cool to be able to query tab positions based on other details as well:
.tabs('position', 'href', '#myTab'); //returns the index of the tab
containing href="#myTab"
.tabs('position', 'text', 'My Tab'); //returns the index of the tab with
the title "My Tab"
It's kind of related to http://dev.jqueryui.com/ticket/3171, which
highlights the issues of not being able to easily get the index of a tab.
Let me know if it's worth putting on trac.
Cheers,
David
If the index is a string, then treat it like a jquery selector,
otherwise, it's a normal index number.
This would give the position method a lot of flexibility, and wouldn't
clutter the interface with a bunch of extra options.
eg:
.tabs('position'); //returns the position of the currently selected tab
.tabs('position', '.ui-tabs-selected'); //same as above
.tabs('position', '[href="#myTab"]'); //using attribute selector
.tabs('position', '#tabWithId'); //using id selector
.tabs('position', ':contains("My Tab")'); //position of tab with text
"My Tab"
This functionality could be expanded to work with all index based methods:
.tabs('disable', '#tabWtihId');
.tabs('select', ':contains("My Tab")');
etc.
I went ahead and made a ticket for this :
http://dev.jqueryui.com/ticket/4354
On 17 Mrz., 07:53, David Muir <davidkm...@gmail.com> wrote:I've thought about it some more, and I've come up with this: If the index is a string, then treat it like a jquery selector, otherwise, it's a normal index number. This would give the position method a lot of flexibility, and wouldn't clutter the interface with a bunch of extra options. eg: .tabs('position'); //returns the position of the currently selected tab .tabs('position', '.ui-tabs-selected'); //same as above$(...).data('selected.tabs');
.tabs('position', '[href="#myTab"]'); //using attribute selector .tabs('position', '#tabWithId'); //using id selector .tabs('position', ':contains("My Tab")'); //position of tab with text "My Tab"$('ul.ui-tabs-nav a').index( $('a[href="#myTab"]') ); etc.
This functionality could be expanded to work with all index based methods: .tabs('disable', '#tabWtihId'); .tabs('select', ':contains("My Tab")'); etc. I went ahead and made a ticket for this :http://dev.jqueryui.com/ticket/4354I don't believe this should be part of the core. As shown, it can be done easily with what jQuery provides already. As for selecting a tab by its id, there is already a ticket for this. --Klaus
On 17 Mrz., 08:48, David Muir <davidkm...@gmail.com> wrote:
> Are the data keys documented anywhere?
Not sure, I think it was once in some "Core" section in the
> selected.tabs is mentioned in the overview, but I wrongly assumed it
> returned the tab element itself, not the index.
documentation, but I cannot find it any longer - documentation has
been restructured the other day. Basically for every plugin you can
retrieve every available (namespaced) option like that:
$(...).data("disabled.tabs");
$(...).data("collapsible.tabs");
On Tue, Mar 17, 2009 at 5:22 AM, Klaus Hartl <klaus...@googlemail.com> wrote:
On 17 Mrz., 08:48, David Muir <davidkm...@gmail.com> wrote:
> Are the data keys documented anywhere?
Each option includes sample code in the documentation showing how to get and set its value after init. Example:
http://docs.jquery.com/UI/Tabs#option-selected
"
Code examples
Initialize a tabs with the selected option specified.
$('.selector').tabs({ selected: 3 });
Get or set the selected option, after init.
//getter
var selected = $('.selector').tabs('option', 'selected');
//setter
$('.selector').tabs('option', 'selected', 3);
"
Not sure, I think it was once in some "Core" section in the
> selected.tabs is mentioned in the overview, but I wrongly assumed it
> returned the tab element itself, not the index.
documentation, but I cannot find it any longer - documentation has
been restructured the other day. Basically for every plugin you can
retrieve every available (namespaced) option like that:
$(...).data("disabled.tabs");
$(...).data("collapsible.tabs");
this syntax is deprecated in 1.7, in favor of
$(...).tabs("option", "disabled");
$(...).tabs("option", "collapsible");
See http://jqueryui.com/docs/Developer_Guide#Setters_and_Getters
- Richard