Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0f33062
Adds unit test: correct sub-menu-less menu item event behavior
Nov 19, 2012
82d0056
Convert from bind() to _on()
Nov 19, 2012
15bd67f
menubar: remove remaining bind() calls; code standards compliance.
Nov 20, 2012
d4ca89b
menubar: rm stray, empty conditional
Dec 1, 2012
f30c853
menubar: rm namespacing on events in _on
Dec 3, 2012
ec67b65
menubar: decompose _create
Dec 4, 2012
c57319c
Revert "menubar: decompose _create"
Dec 8, 2012
36b5135
menubar: spacing / style fix
Dec 8, 2012
1a9f136
menubar: add visual test
Dec 8, 2012
ab98a00
menubar: restore keyboard navigation
Dec 8, 2012
2fe73a1
menubar: keyboard focus / mouse interaction
Dec 8, 2012
baf9882
menubar: more spaces
Dec 8, 2012
0700982
menubar: visual test: add to index page
Dec 9, 2012
2500c96
menubar: kbd / mouse interaction
Dec 9, 2012
bb87639
menubar: spacing and formatting
Dec 10, 2012
b74695a
menubar: rm erroneously committed .orig file
Dec 10, 2012
706d882
menubar: spacing
Dec 10, 2012
8237fb2
menubar: massive refactor for readability
Dec 30, 2012
1af1f8c
meubar: formatting per JQuery style guide
Jan 17, 2013
908fea5
menubar: mark active menuItem with .ui-state-focus
Jan 18, 2013
bb8e2e0
menubar: re-open submenu when returning to it after hover on menu-les…
Jan 18, 2013
0efe66e
menubar: relocate focus event onto *item* v. menuItem
Jan 18, 2013
fdc200d
menubar: fix pixel-shifting visual error
Jan 18, 2013
aafdc17
menubar: apply drop-down glyph only on menus w/ subMenu
Jan 20, 2013
1e8089b
LEFT cursor in an expanded menu approximates ESCAPE
Mar 14, 2013
09d51e8
Remove unused variable: seenFirstItem
Mar 16, 2013
a4a95cc
Do not remove tabIndex varaible
Mar 16, 2013
b2a3814
rm stray debugger
Mar 16, 2013
bab98f2
Change selector for next .ui-menubar-link -> .ui-button
Mar 16, 2013
79b06b2
Repair LEFT cursor
Mar 22, 2013
480de7f
Refactor _move by menuItems knowing their neighbors
Mar 22, 2013
56f6469
Method rename
Mar 22, 2013
100f552
Correct submenus triggering bad focusout behavior
Mar 22, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
menubar: spacing and formatting
  • Loading branch information
Steven G. Harms committed Dec 10, 2012
commit bb87639f88c3c6cfd44a0e5f14e1856ac274917b
22 changes: 11 additions & 11 deletions ui/jquery.ui.menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ $.widget( "ui.menubar", {
},
_create: function() {
var that = this, subMenus;
Copy link
Copy Markdown
Author

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.

  • We're initializing menuItems
  • We're instantiating a $.ui.menus underneath all of these menuItems
  • We're setting behavior on the menuItems and on the sub-menu items
  • We're defining callbacks that are applied on the sub-menu items....
  • etc.

Combine 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:

  1. Is it against jQuery standard to split these _create()-homed activities into intention-revealing sub-methods?
  2. Doing so might mean that you have a single var declaration in the sub-method and thus chaining becomes less attractive (given the "only one var" statement) style rule

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Author

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.

Copy link
Copy Markdown
Member

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:

var subMenus,
    that = this;

this.menuItems = this.element.children( this.options.items ); // Top-level <li>s
this.items = this.menuItems.children( "button, a" ); // Links in those top-level <li>s
// Top-level elements containing the submenu-triggering elem
this.menuItems = this.element.children( this.options.items );
// Links or buttons in menuItems, triggers of the submenus
this.items = this.menuItems.children( "button, a" );

this.menuItems
.addClass( "ui-menubar-item" )
Expand All @@ -46,7 +48,8 @@ $.widget( "ui.menubar", {
.attr( "role", "menubar" );
this._focusable( this.items );
this._hoverable( this.items );
subMenus = this.items.siblings( this.options.menuElement ) // sub-contained <ul>
// Sub-contained container, typically a <ul>
subMenus = this.items.siblings( this.options.menuElement )
.menu({
position: {
within: this.options.position.within
Expand Down Expand Up @@ -149,7 +152,7 @@ $.widget( "ui.menubar", {
}

if ( !menu.length ) {
that._off( input, "click mouseenter keydown");
that._off( input, "click mouseenter keydown" );
that._hoverable( input );
that._on( input, {
click: function( event ) {
Expand All @@ -161,15 +164,12 @@ $.widget( "ui.menubar", {
}
},
keydown: function( event ) {
switch ( event.keyCode ) {
case $.ui.keyCode.LEFT:
if ( event.keyCode === $.ui.keyCode.LEFT ) {
this.previous( event );
event.preventDefault();
break;
case $.ui.keyCode.RIGHT:
} else if ( event.keyCode === $.ui.keyCode.RIGHT ) {
this.next( event );
event.preventDefault();
break;
}
}
});
Expand All @@ -189,7 +189,7 @@ $.widget( "ui.menubar", {
var active = that.active;
that.active.blur();
that._close( event );
$(event.target).blur().mouseleave();
$( event.target ).blur().mouseleave();
active.prev().focus();
}
},
Expand Down Expand Up @@ -233,7 +233,7 @@ $.widget( "ui.menubar", {
.removeAttr( "role" )
.removeAttr( "aria-haspopup" )
// TODO unwrap?
.children( "span.ui-button-text" ).each( function( i, e ) {
.children( "span.ui-button-text" ).each(function( i, e ) {
var item = $( this );
item.parent().html( item.html() );
})
Expand Down
Loading