]> source.dussan.org Git - jquery-ui.git/commitdiff
Widget: Added _hoverable() and _focusable().
authorScott González <scott.gonzalez@gmail.com>
Fri, 21 Jan 2011 20:37:18 +0000 (15:37 -0500)
committerScott González <scott.gonzalez@gmail.com>
Fri, 21 Jan 2011 20:37:18 +0000 (15:37 -0500)
ui/jquery.ui.accordion.js
ui/jquery.ui.widget.js

index b9147abe08e22647c1840491da81645ee33c2cc8..954ee91bda7d9ce6e2211e2254bd3519283a301a 100644 (file)
@@ -43,32 +43,11 @@ $.widget( "ui.accordion", {
                                .addClass( "ui-accordion-li-fix" );
 
                self.headers = self.element.find( options.header )
-                       .addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" )
-                       .bind( "mouseenter.accordion", function() {
-                               if ( options.disabled ) {
-                                       return;
-                               }
-                               $( this ).addClass( "ui-state-hover" );
-                       })
-                       .bind( "mouseleave.accordion", function() {
-                               if ( options.disabled ) {
-                                       return;
-                               }
-                               $( this ).removeClass( "ui-state-hover" );
-                       })
-                       .bind( "focus.accordion", function() {
-                               if ( options.disabled ) {
-                                       return;
-                               }
-                               $( this ).addClass( "ui-state-focus" );
-                       })
-                       .bind( "blur.accordion", function() {
-                               if ( options.disabled ) {
-                                       return;
-                               }
-                               $( this ).removeClass( "ui-state-focus" );
-                       });
+                       .addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" );
 
+               self._hoverable( self.headers );
+               self._focusable( self.headers );
+               
                self.headers.next()
                        .addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" );
                self.headers.find( ":first-child" ).addClass( "ui-accordion-heading" );
index dd7992da2da74d74ba6b24733fe9c0678b94fcf2..1357d40f9853b09776e9c3fbf6fb18eebb835a04 100644 (file)
@@ -130,6 +130,8 @@ $.Widget.prototype = {
                        options );
 
                this.bindings = $();
+               this.hoverable = $();
+               this.focusable = $();
                this._bind({ remove: "destroy" });
 
                this._create();
@@ -151,6 +153,8 @@ $.Widget.prototype = {
 
        destroy: function() {
                this._destroy();
+               // we can probably remove the unbind calls in 2.0
+               // all event bindings should go through this._bind()
                this.element
                        .unbind( "." + this.widgetName )
                        .removeData( this.widgetName );
@@ -160,7 +164,11 @@ $.Widget.prototype = {
                        .removeClass(
                                this.widgetBaseClass + "-disabled " +
                                "ui-state-disabled" );
+
+               // clean up events and states
                this.bindings.unbind( "." + this.widgetName );
+               this.hoverable.removeClass( "ui-state-hover" );
+               this.focusable.removeClass( "ui-state-focus" );
        },
        _destroy: $.noop,
 
@@ -203,6 +211,8 @@ $.Widget.prototype = {
                        this.widget()
                                .toggleClass( this.widgetBaseClass + "-disabled ui-state-disabled", !!value )
                                .attr( "aria-disabled", value );
+                       this.hoverable.removeClass( "ui-state-hover" );
+                       this.focusable.removeClass( "ui-state-focus" );
                }
 
                return this;
@@ -235,6 +245,30 @@ $.Widget.prototype = {
                });
        },
 
+       _hoverable: function( element ) {
+               this.hoverable = this.hoverable.add( element );
+               this._bind( element, {
+                       mouseenter: function( event ) {
+                               $( event.currentTarget ).addClass( "ui-state-hover" );
+                       },
+                       mouseleave: function( event ) {
+                               $( event.currentTarget ).removeClass( "ui-state-hover" );
+                       }
+               });
+       },
+
+       _focusable: function( element ) {
+               this.focusable = this.focusable.add( element );
+               this._bind( element, {
+                       focus: function( event ) {
+                               $( event.currentTarget ).addClass( "ui-state-focus" );
+                       },
+                       blur: function( event ) {
+                               $( event.currentTarget ).removeClass( "ui-state-focus" );
+                       }
+               });
+       },
+
        _trigger: function( type, event, data ) {
                var callback = this.options[ type ];