@@ -86,60 +86,63 @@ $.widget( "ui.menubar", {
86
86
// TODO menu var is only used on two places, doesn't quite justify the .each
87
87
menu = input . next ( that . options . menuElement ) ;
88
88
89
- input . bind ( "click.menubar focus.menubar mouseenter.menubar" , function ( event ) {
90
- // ignore triggered focus event
91
- if ( event . type === "focus" && ! event . originalEvent ) {
92
- return ;
93
- }
94
- event . preventDefault ( ) ;
95
- // TODO can we simplify or extractthis check? especially the last two expressions
96
- // there's a similar active[0] == menu[0] check in _open
97
- if ( event . type === "click" && menu . is ( ":visible" ) && that . active && that . active [ 0 ] === menu [ 0 ] ) {
98
- that . _close ( ) ;
99
- return ;
100
- }
101
- if ( ( that . open && event . type === "mouseenter" ) || event . type === "click" || that . options . autoExpand ) {
102
- if ( that . options . autoExpand ) {
103
- clearTimeout ( that . closeTimer ) ;
89
+ // might be a non-menu button
90
+ if ( menu . length ) {
91
+ input . bind ( "click.menubar focus.menubar mouseenter.menubar" , function ( event ) {
92
+ // ignore triggered focus event
93
+ if ( event . type === "focus" && ! event . originalEvent ) {
94
+ return ;
104
95
}
105
-
106
- that . _open ( event , menu ) ;
107
- }
108
- } )
109
- . bind ( "keydown" , function ( event ) {
110
- switch ( event . keyCode ) {
111
- case $ . ui . keyCode . SPACE :
112
- case $ . ui . keyCode . UP :
113
- case $ . ui . keyCode . DOWN :
114
- that . _open ( event , $ ( this ) . next ( ) ) ;
115
96
event . preventDefault ( ) ;
116
- break ;
117
- case $ . ui . keyCode . LEFT :
118
- that . previous ( event ) ;
119
- event . preventDefault ( ) ;
120
- break ;
121
- case $ . ui . keyCode . RIGHT :
122
- that . next ( event ) ;
123
- event . preventDefault ( ) ;
124
- break ;
125
- }
126
- } )
127
- . addClass ( "ui-button ui-widget ui-button-text-only ui-menubar-link" )
128
- . attr ( "role" , "menuitem" )
129
- . attr ( "aria-haspopup" , "true" )
130
- . wrapInner ( "<span class='ui-button-text'></span>" ) ;
97
+ // TODO can we simplify or extractthis check? especially the last two expressions
98
+ // there's a similar active[0] == menu[0] check in _open
99
+ if ( event . type === "click" && menu . is ( ":visible" ) && that . active && that . active [ 0 ] === menu [ 0 ] ) {
100
+ that . _close ( ) ;
101
+ return ;
102
+ }
103
+ if ( ( that . open && event . type === "mouseenter" ) || event . type === "click" || that . options . autoExpand ) {
104
+ if ( that . options . autoExpand ) {
105
+ clearTimeout ( that . closeTimer ) ;
106
+ }
131
107
132
- // TODO review if these options are a good choice, maybe they can be merged
133
- if ( that . options . menuIcon ) {
134
- input . addClass ( "ui-state-default" ) . append ( "<span class='ui-button-icon-secondary ui-icon ui-icon-triangle-1-s'></span>" ) ;
135
- input . removeClass ( "ui-button-text-only" ) . addClass ( "ui-button-text-icon-secondary" ) ;
136
- }
108
+ that . _open ( event , menu ) ;
109
+ }
110
+ } )
111
+ . bind ( "keydown" , function ( event ) {
112
+ switch ( event . keyCode ) {
113
+ case $ . ui . keyCode . SPACE :
114
+ case $ . ui . keyCode . UP :
115
+ case $ . ui . keyCode . DOWN :
116
+ that . _open ( event , $ ( this ) . next ( ) ) ;
117
+ event . preventDefault ( ) ;
118
+ break ;
119
+ case $ . ui . keyCode . LEFT :
120
+ that . previous ( event ) ;
121
+ event . preventDefault ( ) ;
122
+ break ;
123
+ case $ . ui . keyCode . RIGHT :
124
+ that . next ( event ) ;
125
+ event . preventDefault ( ) ;
126
+ break ;
127
+ }
128
+ } )
129
+ . attr ( "aria-haspopup" , "true" ) ;
137
130
138
- if ( ! that . options . buttons ) {
139
- // TODO ui-menubar-link is added above, not needed here?
140
- input . addClass ( "ui-menubar-link" ) . removeClass ( "ui-state-default" ) ;
131
+ // TODO review if these options (menuIcon and buttons) are a good choice, maybe they can be merged
132
+ if ( that . options . menuIcon ) {
133
+ input . addClass ( "ui-state-default" ) . append ( "<span class='ui-button-icon-secondary ui-icon ui-icon-triangle-1-s'></span>" ) ;
134
+ input . removeClass ( "ui-button-text-only" ) . addClass ( "ui-button-text-icon-secondary" ) ;
135
+ }
141
136
}
142
137
138
+ input
139
+ . addClass ( "ui-button ui-widget ui-button-text-only ui-menubar-link" )
140
+ . attr ( "role" , "menuitem" )
141
+ . wrapInner ( "<span class='ui-button-text'></span>" ) ;
142
+
143
+ if ( that . options . buttons ) {
144
+ input . removeClass ( "ui-menubar-link" ) . addClass ( "ui-state-default" ) ;
145
+ }
143
146
} ) ;
144
147
that . _on ( {
145
148
keydown : function ( event ) {
0 commit comments