summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKlaus Hartl <klaus.hartl@googlemail.com>2009-01-10 10:47:28 +0000
committerKlaus Hartl <klaus.hartl@googlemail.com>2009-01-10 10:47:28 +0000
commit422e0666e996830382e171a123df6006f3600617 (patch)
tree651395fa482fbe4e5537c338191900b7da21df83
parent842753690a230820639f702176c52de11404f376 (diff)
downloadjquery-ui-422e0666e996830382e171a123df6006f3600617.tar.gz
jquery-ui-422e0666e996830382e171a123df6006f3600617.zip
UI Tabs: reviewed code to handle hover/focus states: needs to take disabling into account, namespaced events, to be destroyed
-rw-r--r--ui/ui.tabs.js35
1 files changed, 14 insertions, 21 deletions
diff --git a/ui/ui.tabs.js b/ui/ui.tabs.js
index a90223e3b..873fdd9c2 100644
--- a/ui/ui.tabs.js
+++ b/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;});