aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.menu.js
diff options
context:
space:
mode:
authorJörn Zaefferer <joern.zaefferer@gmail.com>2011-07-28 15:47:32 +0200
committerJörn Zaefferer <joern.zaefferer@gmail.com>2011-07-28 15:47:59 +0200
commit02aad7b0ae8c752eb24f99d7a6a06aeeb5d17367 (patch)
treea7cbf3b32b4fd1902395eb253faa3c35b28ba02b /ui/jquery.ui.menu.js
parent5a45f483d73578dd147229d412998bba4a44c35b (diff)
downloadjquery-ui-02aad7b0ae8c752eb24f99d7a6a06aeeb5d17367.tar.gz
jquery-ui-02aad7b0ae8c752eb24f99d7a6a06aeeb5d17367.zip
Widget delegation: Update menu to use _bind with delegation. Clean up test.
Diffstat (limited to 'ui/jquery.ui.menu.js')
-rw-r--r--ui/jquery.ui.menu.js77
1 files changed, 32 insertions, 45 deletions
diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js
index c55ae75c9..7cfa61f86 100644
--- a/ui/jquery.ui.menu.js
+++ b/ui/jquery.ui.menu.js
@@ -37,53 +37,40 @@ $.widget( "ui.menu", {
.attr({
id: this.menuId,
role: "menu"
- })
- .bind( "click.menu", function( event ) {
- var item = $( event.target ).closest( ".ui-menu-item:has(a)" );
- if ( self.options.disabled ) {
- return false;
- }
- if ( !item.length ) {
- return;
- }
+ });
+ this.element.bind("click.menu", function( event ) {
+ if ( self.options.disabled ) {
+ event.preventDefault();
+ }
+ });
+ 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)
- if ( !self.active || ( self.active[ 0 ] !== item[ 0 ] ) ) {
- self.focus( event, item );
- }
- self.select( event );
- })
- .bind( "mouseover.menu", function( event ) {
- if ( self.options.disabled ) {
- return;
- }
- 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
- target.siblings().children( ".ui-state-active" ).removeClass( "ui-state-active" );
- self.focus( event, target );
+ if ( !this.active || ( this.active[ 0 ] !== target[ 0 ] ) ) {
+ this.focus( event, target );
}
- })
- .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.select( event );
+ },
+ "mouseover .ui-menu-item": function( event ) {
+ event.stopImmediatePropagation();
+ var target = $( event.currentTarget );
+ // 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" );
+ 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 );
+ }
+ });
+
this.refresh();
this.element.attr( "tabIndex", 0 ).bind( "keydown.menu", function( event ) {