_create: function() {
var self = this;
var items = this.items = this.element.children("button, a");
+ items.slice(1).attr("tabIndex", -1);
var o = this.options;
this.element.addClass('ui-menubar ui-widget-header ui-helper-clearfix');
event.stopPropagation();
switch (event.keyCode) {
case $.ui.keyCode.LEFT:
- self.left(event);
+ self._left(event);
event.preventDefault();
break;
case $.ui.keyCode.RIGHT:
- self.right(event);
+ self._right(event);
event.preventDefault();
break;
};
}).blur(function() {
- $(this).hide().prev().removeClass("ui-state-active").removeAttr("tabIndex");
- self.timer = setTimeout(function() {
- self.open = false;
- }, 13);
+ self._close();
});
});
items.each(function() {
})
.bind( "keydown", function( event ) {
switch ( event.keyCode ) {
+ case $.ui.keyCode.SPACE:
case $.ui.keyCode.UP:
case $.ui.keyCode.DOWN:
self._open( event, $( this ).next() );
event.preventDefault();
break;
+ case $.ui.keyCode.LEFT:
+ self._prev( event, $( this ) );
+ event.preventDefault();
+ break;
+ case $.ui.keyCode.RIGHT:
+ self._next( event, $( this ) );
+ event.preventDefault();
+ break;
}
})
.addClass("ui-button ui-widget ui-button-text-only ui-menubar-link")
});
self._bind(document, {
click: function(event) {
- !$(event.target).closest(".ui-menubar").length && self._close();
+ self.open && !$(event.target).closest(".ui-menubar").length && self._close();
}
})
self._bind({
},
_close: function() {
- this.items.next("ul").hide();
- this.items.removeClass("ui-state-active").removeAttr("tabIndex");
- this.open = false;
+ this.active.menu("closeAll").hide();
+ this.active.prev().removeClass("ui-state-active").removeAttr("tabIndex");
+ this.active = null;
+ var self = this;
+ // delay for the next focus event to see it as still "open"
+ self.timer = setTimeout(function() {
+ self.open = false;
+ }, 13);
},
_open: function(event, menu) {
+ // TODO refactor with _close
if (this.active) {
this.active.menu("closeAll").hide();
this.active.prev().removeClass("ui-state-active").removeAttr("tabIndex");
}).focus();
},
- left: function(event) {
+ _prev: function( event, button ) {
+ button.attr("tabIndex", -1);
+ var prev = button.prevAll( ".ui-button" ).eq( 0 );
+ if (prev.length) {
+ prev.removeAttr("tabIndex")[0].focus();
+ } else {
+ this.element.children(".ui-button:last").removeAttr("tabIndex")[0].focus();
+ }
+ },
+
+ _next: function( event, button ) {
+ button.attr("tabIndex", -1);
+ var next = button.nextAll( ".ui-button" ).eq( 0 );
+ if (next.length) {
+ next.removeAttr("tabIndex")[0].focus();
+ } else {
+ this.element.children(".ui-button:first").removeAttr("tabIndex")[0].focus();
+ }
+ },
+
+ _left: function(event) {
var prev = this.active.prevAll( ".ui-menu" ).eq( 0 );
if (prev.length) {
this._open(event, prev);
}
},
- right: function(event) {
+ _right: function(event) {
var next = this.active.nextAll( ".ui-menu" ).eq( 0 );
if (next.length) {
this._open(event, next);