@@ -130,6 +130,8 @@ $.Widget.prototype = {
130130 options ) ;
131131
132132 this . bindings = $ ( ) ;
133+ this . hoverable = $ ( ) ;
134+ this . focusable = $ ( ) ;
133135 this . _bind ( { remove : "destroy" } ) ;
134136
135137 this . _create ( ) ;
@@ -151,6 +153,8 @@ $.Widget.prototype = {
151153
152154 destroy : function ( ) {
153155 this . _destroy ( ) ;
156+ // we can probably remove the unbind calls in 2.0
157+ // all event bindings should go through this._bind()
154158 this . element
155159 . unbind ( "." + this . widgetName )
156160 . removeData ( this . widgetName ) ;
@@ -160,7 +164,11 @@ $.Widget.prototype = {
160164 . removeClass (
161165 this . widgetBaseClass + "-disabled " +
162166 "ui-state-disabled" ) ;
167+
168+ // clean up events and states
163169 this . bindings . unbind ( "." + this . widgetName ) ;
170+ this . hoverable . removeClass ( "ui-state-hover" ) ;
171+ this . focusable . removeClass ( "ui-state-focus" ) ;
164172 } ,
165173 _destroy : $ . noop ,
166174
@@ -203,6 +211,8 @@ $.Widget.prototype = {
203211 this . widget ( )
204212 . toggleClass ( this . widgetBaseClass + "-disabled ui-state-disabled" , ! ! value )
205213 . attr ( "aria-disabled" , value ) ;
214+ this . hoverable . removeClass ( "ui-state-hover" ) ;
215+ this . focusable . removeClass ( "ui-state-focus" ) ;
206216 }
207217
208218 return this ;
@@ -235,6 +245,30 @@ $.Widget.prototype = {
235245 } ) ;
236246 } ,
237247
248+ _hoverable : function ( element ) {
249+ this . hoverable = this . hoverable . add ( element ) ;
250+ this . _bind ( element , {
251+ mouseenter : function ( event ) {
252+ $ ( event . currentTarget ) . addClass ( "ui-state-hover" ) ;
253+ } ,
254+ mouseleave : function ( event ) {
255+ $ ( event . currentTarget ) . removeClass ( "ui-state-hover" ) ;
256+ }
257+ } ) ;
258+ } ,
259+
260+ _focusable : function ( element ) {
261+ this . focusable = this . focusable . add ( element ) ;
262+ this . _bind ( element , {
263+ focus : function ( event ) {
264+ $ ( event . currentTarget ) . addClass ( "ui-state-focus" ) ;
265+ } ,
266+ blur : function ( event ) {
267+ $ ( event . currentTarget ) . removeClass ( "ui-state-focus" ) ;
268+ }
269+ } ) ;
270+ } ,
271+
238272 _trigger : function ( type , event , data ) {
239273 var callback = this . options [ type ] ;
240274
0 commit comments