UI Tabs - Add init callback to perform tasks once all tabs are loaded

UI Tabs - Add init callback to perform tasks once all tabs are loaded


I have an application where I'm using tabs to show three sets of form
fields. A user can only use one of the three sets at a time, so I want
to disable those that are hidden. This is easily done when a new tab
is clicked, using the show callback. However, doing so when the tabs
have finished initializing is not possible using the current code.
Below is a patch to add this ability via an init callback.
I used a setTimeout because calling the init callback immediately
didn't work quite correctly when using a simple (from cache) page
refresh. I'm not sure why and if there is a better place to call the
init method, there's no reason not to put it elsewhere.
--- jquery.ui-tabs.js    2008-11-26 10:59:11.669434000 -0600
+++ jquery.ui-tabs_init.js    2008-11-26 10:59:03.435059000 -0600
@@ -86,6 +86,7 @@
hide: function() {},
show: function() {},
load: function() {},
+ init: function() {},
// templates
tabTemplate: '<li><a href="#{href}"><span>#{text}</span></
a></li>',
@@ -221,6 +222,11 @@
this.load(o.initial + 1, href);
}
+ if (o.init && o.init.constructor == Function) {
+ // using timeout to properly init() on page refresh
+ setTimeout(o.init, 5);
+ }
+
}
// setup animations