Skip to content

Commit f519bc0

Browse files
committed
Menubar review
1 parent 66b96cb commit f519bc0

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

tests/visual/menu/menubar.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
22
* jQuery UI menubar
3-
*
4-
* backported from Michael Lang's fork: http://www.nexul.com/prototypes/toolbar/demo.html
3+
*
4+
* TODO move to jquery.ui.menubar.js
55
*/
66
(function($) {
77

8-
// TODO take non-menubar buttons into account
8+
// TODO code formatting
99
$.widget("ui.menubar", {
1010
options: {
1111
buttons: false,
@@ -23,12 +23,14 @@ $.widget("ui.menubar", {
2323
this.element.addClass('ui-menubar ui-widget-header ui-helper-clearfix').attr("role", "menubar");
2424
this._focusable(items);
2525
this._hoverable(items);
26+
// TODO elm is used just once, so the each probably isn't nedded anymore
2627
items.next("ul").each(function(i, elm) {
2728
$(elm).menu({
2829
select: function(event, ui) {
2930
ui.item.parents("ul.ui-menu:last").hide();
3031
self._trigger( "select", event, ui );
3132
self._close();
33+
// TODO what is this targetting? there's probably a better way to access it
3234
$(event.target).prev().focus();
3335
}
3436
}).hide()
@@ -60,6 +62,8 @@ $.widget("ui.menubar", {
6062
return;
6163
}
6264
event.preventDefault();
65+
// TODO can we simplify or extractthis check? especially the last two expressions
66+
// there's a similar active[0] == menu[0] check in _open
6367
if (event.type == "click" && menu.is(":visible") && self.active && self.active[0] == menu[0]) {
6468
self._close();
6569
return;
@@ -90,19 +94,22 @@ $.widget("ui.menubar", {
9094
.attr("role", "menuitem")
9195
.attr("aria-haspopup", "true")
9296
.wrapInner("<span class='ui-button-text'></span>");
93-
97+
98+
// TODO review if these options are a good choice, maybe they can be merged
9499
if (o.menuIcon) {
95100
input.addClass("ui-state-default").append("<span class='ui-button-icon-secondary ui-icon ui-icon-triangle-1-s'></span>");
96101
input.removeClass("ui-button-text-only").addClass("ui-button-text-icon-secondary");
97102
}
98103

99104
if (!o.buttons) {
105+
// TODO ui-menubar-link is added above, not needed here?
100106
input.addClass('ui-menubar-link').removeClass('ui-state-default');
101107
};
102108

103109
});
104110
self._bind({
105111
keydown: function(event) {
112+
// TODO merge the two ifs
106113
if (event.keyCode == $.ui.keyCode.ESCAPE) {
107114
if (self.active && self.active.menu("left", event) !== true) {
108115
var active = self.active;
@@ -117,6 +124,7 @@ $.widget("ui.menubar", {
117124
self._close( event );
118125
}, 100);
119126
},
127+
// TODO change order, focusin first
120128
focusin :function( event ) {
121129
clearTimeout(self.closeTimer);
122130
}
@@ -150,8 +158,7 @@ $.widget("ui.menubar", {
150158
.removeAttr("aria-hidden", "true")
151159
.removeAttr("aria-expanded", "false")
152160
.removeAttr("tabindex")
153-
.unbind("keydown", "blur")
154-
;
161+
.unbind("keydown", "blur");
155162
},
156163

157164
_close: function() {
@@ -182,12 +189,13 @@ $.widget("ui.menubar", {
182189
})
183190
.removeAttr("aria-hidden").attr("aria-expanded", "true")
184191
.menu("focus", event, menu.children("li").first())
192+
// TODO need a comment here why both events are triggered
185193
.focus()
186-
.focusin()
187-
;
194+
.focusin();
188195
this.open = true;
189196
},
190197

198+
// TODO refactor this and the next three methods
191199
_prev: function( event, button ) {
192200
button.attr("tabIndex", -1);
193201
var prev = button.parent().prevAll("li").children( ".ui-button" ).eq( 0 );
@@ -209,7 +217,8 @@ $.widget("ui.menubar", {
209217
firstItem.removeAttr("tabIndex")[0].focus();
210218
}
211219
},
212-
220+
221+
// TODO rename to parent
213222
_left: function(event) {
214223
var prev = this.active.parent().prevAll("li:eq(0)").children( ".ui-menu" ).eq( 0 );
215224
if (prev.length) {
@@ -220,6 +229,7 @@ $.widget("ui.menubar", {
220229
}
221230
},
222231

232+
// TODO rename to child (or something like that)
223233
_right: function(event) {
224234
var next = this.active.parent().nextAll("li:eq(0)").children( ".ui-menu" ).eq( 0 );
225235
if (next.length) {

0 commit comments

Comments
 (0)