-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Menubar #829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Menubar #829
Changes from 1 commit
0f33062
82d0056
15bd67f
d4ca89b
f30c853
ec67b65
c57319c
36b5135
1a9f136
ab98a00
2fe73a1
baf9882
0700982
2500c96
bb87639
b74695a
706d882
8237fb2
1af1f8c
908fea5
bb8e2e0
0efe66e
fdc200d
aafdc17
1e8089b
09d51e8
a4a95cc
b2a3814
bab98f2
79b06b2
480de7f
56f6469
100f552
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Per @jzaefferer, keyboard behavior was broken, this should be fixed now.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,8 +32,8 @@ $.widget( "ui.menubar", { | |
| }, | ||
| _create: function() { | ||
| var that = this, subMenus; | ||
| this.menuItems = this.element.children( this.options.items ); | ||
| this.items = this.menuItems.children( "button, a" ); | ||
| this.menuItems = this.element.children( this.options.items ); // Top-level <li>s | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments always go above the line.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, these comments are all technically incorrect. The markup is configurable, use menu terminology, not tag names. |
||
| this.items = this.menuItems.children( "button, a" ); // Links in those top-level <li>s | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment |
||
|
|
||
| this.menuItems | ||
| .addClass( "ui-menubar-item" ) | ||
|
|
@@ -46,7 +46,7 @@ $.widget( "ui.menubar", { | |
| .attr( "role", "menubar" ); | ||
| this._focusable( this.items ); | ||
| this._hoverable( this.items ); | ||
| subMenus = this.items.siblings( this.options.menuElement ) | ||
| subMenus = this.items.siblings( this.options.menuElement ) // sub-contained <ul> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment |
||
| .menu({ | ||
| position: { | ||
| within: this.options.position.within | ||
|
|
@@ -115,7 +115,7 @@ $.widget( "ui.menubar", { | |
| case $.ui.keyCode.SPACE: | ||
| case $.ui.keyCode.UP: | ||
| case $.ui.keyCode.DOWN: | ||
| this._open( event, $( this ).next() ); | ||
| that._open( event, $(event.target).next() ); | ||
| event.preventDefault(); | ||
| break; | ||
| case $.ui.keyCode.LEFT: | ||
|
|
@@ -130,35 +130,47 @@ $.widget( "ui.menubar", { | |
| }; | ||
|
|
||
| // might be a non-menu button | ||
| if ( menu.length ) { | ||
| that._on( input, { | ||
| click: mouseBehaviorCallback, | ||
| focus: mouseBehaviorCallback, | ||
| mouseenter: mouseBehaviorCallback, | ||
| keydown: keyboardBehaviorCallback | ||
| }); | ||
| that._on( input, { | ||
| click: mouseBehaviorCallback, | ||
| focus: mouseBehaviorCallback, | ||
| mouseenter: mouseBehaviorCallback, | ||
| keydown: keyboardBehaviorCallback | ||
| }); | ||
|
|
||
| input.attr( "aria-haspopup", "true" ); | ||
| input.attr( "aria-haspopup", "true" ); | ||
|
|
||
| // TODO review if these options (menuIcon and buttons) are a good choice, maybe they can be merged | ||
| if ( that.options.menuIcon ) { | ||
| input.addClass( "ui-state-default" ).append( "<span class='ui-button-icon-secondary ui-icon ui-icon-triangle-1-s'></span>" ); | ||
| input.removeClass( "ui-button-text-only" ).addClass( "ui-button-text-icon-secondary" ); | ||
| } | ||
| } else { | ||
| // TODO review if these options (menuIcon and buttons) are a good choice, maybe they can be merged | ||
| if ( that.options.menuIcon ) { | ||
| input.addClass( "ui-state-default" ).append( "<span class='ui-button-icon-secondary ui-icon ui-icon-triangle-1-s'></span>" ); | ||
| input.removeClass( "ui-button-text-only" ).addClass( "ui-button-text-icon-secondary" ); | ||
| } | ||
|
|
||
| if ( !menu.length ) { | ||
| that._off( input, "click mouseenter keydown"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space before closing paren. |
||
| that._hoverable( input ); | ||
| that._on( input, { | ||
| click: function( event ) { | ||
| this._close(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spacing |
||
| }, | ||
|
|
||
| mouseenter: function( event ) { | ||
| if ( this.open ) { | ||
| this._close(); | ||
| } | ||
| }, | ||
| keydown: function( event ) { | ||
| switch ( event.keyCode ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably just use |
||
| case $.ui.keyCode.LEFT: | ||
| this.previous( event ); | ||
| event.preventDefault(); | ||
| break; | ||
| case $.ui.keyCode.RIGHT: | ||
| this.next( event ); | ||
| event.preventDefault(); | ||
| break; | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| input | ||
| .addClass( "ui-button ui-widget ui-button-text-only ui-menubar-link" ) | ||
| .attr( "role", "menuitem" ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scottgonzalez @jzaefferer When I look at this
_create()method, it seems there's a lot of initializing sub-tasks going on.menuItems$.ui.menus underneath all of thesemenuItemsmenuItemsand on the sub-menu itemsCombine with the jQuery 'dot-chaining' syntax, the method seems to strain easy readability (in my book). This makes the contribution bar higher (IMNSHO) and makes testing / debugging harder. Maybe this isn't so for jQuery gurus such as yourselves, but I think the code would be more approachable if the long methods used intention-revealing sub-methods. I don't see this done elsewhere in the jQuery UI plugin set, but I wanted to get your thoughts on why this is or if this is just my relative unfamiliarity with plugin design.
Questions:
_create()-homed activities into intention-revealing sub-methods?vardeclaration in the sub-method and thus chaining becomes less attractive (given the "only onevar" statement) style ruleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to split up
_create()if the split makes sense. I don't see how the one-var rule has any impact on chaining method calls.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do that in another request, then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uninitialized vars at the top, on their own line: