mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Widget delegation: Update menu to use _bind with delegation. Clean up test.
This commit is contained in:
parent
5a45f483d7
commit
02aad7b0ae
@ -670,7 +670,6 @@ test( "_bind() with delegate", function() {
|
|||||||
expect( 8 );
|
expect( 8 );
|
||||||
$.widget( "ui.testWidget", {
|
$.widget( "ui.testWidget", {
|
||||||
_create: function() {
|
_create: function() {
|
||||||
var that = this;
|
|
||||||
this.element = {
|
this.element = {
|
||||||
bind: function( event, handler ) {
|
bind: function( event, handler ) {
|
||||||
equal( event, "click.testWidget" );
|
equal( event, "click.testWidget" );
|
||||||
@ -682,7 +681,7 @@ test( "_bind() with delegate", function() {
|
|||||||
ok( $.isFunction(handler) );
|
ok( $.isFunction(handler) );
|
||||||
},
|
},
|
||||||
trigger: $.noop
|
trigger: $.noop
|
||||||
}
|
};
|
||||||
this._bind({
|
this._bind({
|
||||||
"click": "handler",
|
"click": "handler",
|
||||||
"click a": "handler",
|
"click a": "handler",
|
||||||
@ -698,7 +697,7 @@ test( "_bind() with delegate", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
$.ui.testWidget();
|
$.ui.testWidget();
|
||||||
})
|
});
|
||||||
|
|
||||||
test( "._hoverable()", function() {
|
test( "._hoverable()", function() {
|
||||||
$.widget( "ui.testWidget", {
|
$.widget( "ui.testWidget", {
|
||||||
|
65
ui/jquery.ui.menu.js
vendored
65
ui/jquery.ui.menu.js
vendored
@ -37,53 +37,40 @@ $.widget( "ui.menu", {
|
|||||||
.attr({
|
.attr({
|
||||||
id: this.menuId,
|
id: this.menuId,
|
||||||
role: "menu"
|
role: "menu"
|
||||||
})
|
});
|
||||||
.bind( "click.menu", function( event ) {
|
this.element.bind("click.menu", function( event ) {
|
||||||
var item = $( event.target ).closest( ".ui-menu-item:has(a)" );
|
|
||||||
if ( self.options.disabled ) {
|
if ( self.options.disabled ) {
|
||||||
return false;
|
event.preventDefault();
|
||||||
}
|
|
||||||
if ( !item.length ) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
this._bind({
|
||||||
|
"click .ui-menu-item:has(a)": function( event ) {
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
var target = $( event.currentTarget );
|
||||||
// it's possible to click an item without hovering it (#7085)
|
// it's possible to click an item without hovering it (#7085)
|
||||||
if ( !self.active || ( self.active[ 0 ] !== item[ 0 ] ) ) {
|
if ( !this.active || ( this.active[ 0 ] !== target[ 0 ] ) ) {
|
||||||
self.focus( event, item );
|
this.focus( event, target );
|
||||||
}
|
}
|
||||||
self.select( event );
|
this.select( event );
|
||||||
})
|
},
|
||||||
.bind( "mouseover.menu", function( event ) {
|
"mouseover .ui-menu-item": function( event ) {
|
||||||
if ( self.options.disabled ) {
|
event.stopImmediatePropagation();
|
||||||
return;
|
var target = $( event.currentTarget );
|
||||||
}
|
|
||||||
var target = $( event.target ).closest( ".ui-menu-item" );
|
|
||||||
if ( target.length ) {
|
|
||||||
// Remove ui-state-active class from siblings of the newly focused menu item to avoid a jump caused by adjacent elements both having a class with a border
|
// Remove ui-state-active class from siblings of the newly focused menu item to avoid a jump caused by adjacent elements both having a class with a border
|
||||||
target.siblings().children( ".ui-state-active" ).removeClass( "ui-state-active" );
|
target.siblings().children( ".ui-state-active" ).removeClass( "ui-state-active" );
|
||||||
self.focus( event, target );
|
this.focus( event, target );
|
||||||
|
},
|
||||||
|
"mouseout .ui-menu-item": function( event ) {
|
||||||
|
this.blur( event );
|
||||||
|
},
|
||||||
|
"focus": function( event ) {
|
||||||
|
this.focus( event, $( event.target ).children( ".ui-menu-item:first" ) );
|
||||||
|
},
|
||||||
|
"blur": function( event ) {
|
||||||
|
this.collapseAll( event );
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.bind( "mouseout.menu", function( event ) {
|
|
||||||
if ( self.options.disabled ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var target = $( event.target ).closest( ".ui-menu-item" );
|
|
||||||
if ( target.length ) {
|
|
||||||
self.blur( event );
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.bind( "focus.menu", function( event ) {
|
|
||||||
if ( self.options.disabled ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.focus( event, $( event.target ).children( ".ui-menu-item:first" ) );
|
|
||||||
})
|
|
||||||
.bind( "blur.menu", function( event ) {
|
|
||||||
if ( self.options.disabled ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.collapseAll( event );
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
|
|
||||||
this.element.attr( "tabIndex", 0 ).bind( "keydown.menu", function( event ) {
|
this.element.attr( "tabIndex", 0 ).bind( "keydown.menu", function( event ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user