Skip to content

Commit 711df1f

Browse files
committed
Widget: Added _hoverable() and _focusable().
1 parent 6072703 commit 711df1f

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

ui/jquery.ui.accordion.js

+4-25
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,11 @@ $.widget( "ui.accordion", {
4343
.addClass( "ui-accordion-li-fix" );
4444

4545
self.headers = self.element.find( options.header )
46-
.addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" )
47-
.bind( "mouseenter.accordion", function() {
48-
if ( options.disabled ) {
49-
return;
50-
}
51-
$( this ).addClass( "ui-state-hover" );
52-
})
53-
.bind( "mouseleave.accordion", function() {
54-
if ( options.disabled ) {
55-
return;
56-
}
57-
$( this ).removeClass( "ui-state-hover" );
58-
})
59-
.bind( "focus.accordion", function() {
60-
if ( options.disabled ) {
61-
return;
62-
}
63-
$( this ).addClass( "ui-state-focus" );
64-
})
65-
.bind( "blur.accordion", function() {
66-
if ( options.disabled ) {
67-
return;
68-
}
69-
$( this ).removeClass( "ui-state-focus" );
70-
});
46+
.addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" );
7147

48+
self._hoverable( self.headers );
49+
self._focusable( self.headers );
50+
7251
self.headers.next()
7352
.addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" );
7453
self.headers.find( ":first-child" ).addClass( "ui-accordion-heading" );

ui/jquery.ui.widget.js

+34
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)