Menu: Remove most event.stopImmediatePropagation() to allow proper event bubbling

This commit is contained in:
kborchers 2012-04-14 15:33:48 -04:00
parent d22edc8d05
commit 26d6952bd2

61
ui/jquery.ui.menu.js vendored
View File

@ -13,7 +13,8 @@
*/ */
(function($) { (function($) {
var idIncrement = 0; var idIncrement = 0,
currentEventTarget;
$.widget( "ui.menu", { $.widget( "ui.menu", {
version: "@VERSION", version: "@VERSION",
@ -66,16 +67,22 @@ $.widget( "ui.menu", {
event.preventDefault(); event.preventDefault();
}, },
"click .ui-menu-item:has(a)": function( event ) { "click .ui-menu-item:has(a)": function( event ) {
event.stopImmediatePropagation(); var target = $( event.target );
// Don't select disabled menu items if ( target[0] != currentEventTarget ) {
if ( !$( event.target ).closest( ".ui-menu-item" ).is( ".ui-state-disabled" ) ) { currentEventTarget = target[0];
this.select( event ); target.one( "click", function( event ) {
// Redirect focus to the menu with a delay for firefox currentEventTarget = "";
this._delay(function() { });
if ( !this.element.is(":focus") ) { // Don't select disabled menu items
this.element.focus(); if ( !target.closest( ".ui-menu-item" ).is( ".ui-state-disabled" ) ) {
} this.select( event );
}, 20 ); // Redirect focus to the menu with a delay for firefox
this._delay(function() {
if ( !this.element.is(":focus") ) {
this.element.focus();
}
}, 20 );
}
} }
}, },
"mouseover .ui-menu-item": function( event ) { "mouseover .ui-menu-item": function( event ) {
@ -158,65 +165,49 @@ $.widget( "ui.menu", {
case $.ui.keyCode.PAGE_UP: case $.ui.keyCode.PAGE_UP:
this.previousPage( event ); this.previousPage( event );
event.preventDefault(); event.preventDefault();
event.stopImmediatePropagation();
break; break;
case $.ui.keyCode.PAGE_DOWN: case $.ui.keyCode.PAGE_DOWN:
this.nextPage( event ); this.nextPage( event );
event.preventDefault(); event.preventDefault();
event.stopImmediatePropagation();
break; break;
case $.ui.keyCode.HOME: case $.ui.keyCode.HOME:
this._move( "first", "first", event ); this._move( "first", "first", event );
event.preventDefault(); event.preventDefault();
event.stopImmediatePropagation();
break; break;
case $.ui.keyCode.END: case $.ui.keyCode.END:
this._move( "last", "last", event ); this._move( "last", "last", event );
event.preventDefault(); event.preventDefault();
event.stopImmediatePropagation();
break; break;
case $.ui.keyCode.UP: case $.ui.keyCode.UP:
this.previous( event ); this.previous( event );
event.preventDefault(); event.preventDefault();
event.stopImmediatePropagation();
break; break;
case $.ui.keyCode.DOWN: case $.ui.keyCode.DOWN:
this.next( event ); this.next( event );
event.preventDefault(); event.preventDefault();
event.stopImmediatePropagation();
break; break;
case $.ui.keyCode.LEFT: case $.ui.keyCode.LEFT:
if (this.collapse( event )) { this.collapse( event );
event.stopImmediatePropagation();
}
event.preventDefault(); event.preventDefault();
break; break;
case $.ui.keyCode.RIGHT: case $.ui.keyCode.RIGHT:
if (this.expand( event )) { this.expand( event );
event.stopImmediatePropagation();
}
event.preventDefault(); event.preventDefault();
break; break;
case $.ui.keyCode.ENTER: case $.ui.keyCode.ENTER:
if ( this.active.children( "a[aria-haspopup='true']" ).length ) { if ( this.active.children( "a[aria-haspopup='true']" ).length ) {
if ( this.expand( event ) ) { this.expand( event );
event.stopImmediatePropagation();
}
} }
else { else {
this.select( event ); this.select( event );
event.stopImmediatePropagation();
} }
event.preventDefault(); event.preventDefault();
break; break;
case $.ui.keyCode.ESCAPE: case $.ui.keyCode.ESCAPE:
if ( this.collapse( event ) ) { this.collapse( event );
event.stopImmediatePropagation();
}
event.preventDefault(); event.preventDefault();
break; break;
default: default:
event.stopPropagation();
clearTimeout( this.filterTimer ); clearTimeout( this.filterTimer );
var match, var match,
prev = this.previousFilter || "", prev = this.previousFilter || "",
@ -303,7 +294,7 @@ $.widget( "ui.menu", {
focus: function( event, item ) { focus: function( event, item ) {
var nested, borderTop, paddingTop, offset, scroll, elementHeight, itemHeight; var nested, borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;
this.blur( event ); this.blur( event, event.type == "focus" );
if ( this._hasScroll() ) { if ( this._hasScroll() ) {
borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0; borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0;
@ -342,8 +333,10 @@ $.widget( "ui.menu", {
this._trigger( "focus", event, { item: item } ); this._trigger( "focus", event, { item: item } );
}, },
blur: function( event ) { blur: function( event, fromFocus ) {
clearTimeout( this.timer ); if ( !fromFocus ) {
clearTimeout( this.timer );
}
if ( !this.active ) { if ( !this.active ) {
return; return;