Skip to content
Permalink
Browse files

UI Tabs: reviewed code to handle hover/focus states: needs to take di…

…sabling into account, namespaced events, to be destroyed
  • Loading branch information
Klaus Hartl
Klaus Hartl committed Jan 10, 2009
1 parent 8427536 commit 422e0666e996830382e171a123df6006f3600617
Showing with 14 additions and 21 deletions.
  1. +14 −21 ui/ui.tabs.js
@@ -32,7 +32,7 @@ $.widget("ui.tabs", {
$this.removeData(prefix + '.tabs');
});
});
this.$lis.add(this.$panels).each(function() {
this.$lis.unbind('.tabs').add(this.$panels).each(function() {
if ($.data(this, 'destroy.tabs'))
$(this).remove();
else
@@ -78,24 +78,6 @@ $.widget("ui.tabs", {

var self = this, o = this.options;

this.$lis
.hover(
function() {
$(this).addClass('ui-state-hover');
},
function() {
$(this).removeClass('ui-state-hover');
}
);

this.$tabs
.focus(function() {
$(this).parent().addClass('ui-state-focus');
})
.blur(function() {
$(this).parent().removeClass('ui-state-focus');
});

this.$tabs.each(function(i, a) {
// inline tab
if (a.hash && a.hash.replace('#', '')) // Safari 2 reports '#' for an empty hash
@@ -188,10 +170,21 @@ $.widget("ui.tabs", {
// just trigger show event
else onShow();
}

// states
var handleState = function(state, el) {
if (el.is(':not(.' + o.disabledClass + ')')) el.toggleClass('ui-state-' + state);
};
this.$lis.bind('mouseover.tabs mouseout.tabs', function() {
handleState('hover', $(this));
});
this.$tabs.bind('focus.tabs blur.tabs', function() {
handleState('focus', $(this).parents('li:first'));
});

// clean up to avoid memory leaks in certain versions of IE 6
$(window).bind('unload', function() {
self.$tabs.unbind('.tabs');
self.$lis.add(self.$tabs).unbind('.tabs');
self.$lis = self.$tabs = self.$panels = null;
});

@@ -342,7 +335,7 @@ $.widget("ui.tabs", {
return false;

});

// disable click if event is configured to something else
if (o.event != 'click') this.$tabs.bind('click.tabs', function(){return false;});

0 comments on commit 422e066

Please sign in to comment.
You can’t perform that action at this time.