Question

Which tabstrip widget has a working onload event hook, so I can run some code (load tab contents) whenever a tab is opened?

JQuery UI tabs has an "activate" event, but it's not triggered when the page is loaded, so opening URL#tabs-2 will show an empty second tab. There is a "create" event, which is triggered when the page is loaded, but not when a tab is clicked, which leads to duplicate code (same callback in both events).
So far I've only found the obvious workaround to put that code in a separate function loadTabstrip1Tab(index)/loadTabstrip2Tab(index)/... which is called in both events.
According to a bug report (activate event not fired for first tab when created), the lack of such an event seems to be a design decision.
There's probably a simple solution, but I can't seem to figure it out.
(Re-)Activating the currently active tab does nothing.

Is there a fix for this widget?

Can someone recommend another tab widget which offers such a tab activation event hook?

Était-ce utile?

La solution

Well I found something for JQuery UI Tabs. The "show" option is not an event but it looks like it does what I'd expect the "activate" event to do:

$("#tabs").tabs({
    show: function( e,ui )
    {
        alert("tab " + ui.panel.id + " activated");
    }
});

Here's a jsfiddle demo (works with JQuery 1.9 + JQuery UI 1.9).

So I guess this turns the first question into "is this a good/bad solution"...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top