// there has to be just one item that has tabindex
$.widget( "ui.menubar", {
version: "@VERSION",
- options: {
- buttons: false,
- menuIcon: false
- },
+ options: {
+ buttons: false,
+ menuIcon: false
+ },
_create: function() {
var that = this;
var items = this.items = this.element.children( "li" )
var input = $(this),
// TODO menu var is only used on two places, doesn't quite justify the .each
menu = input.next( "ul" );
-
+
input.bind( "click.menubar focus.menubar mouseenter.menubar", function( event ) {
// ignore triggered focus event
if ( event.type == "focus" && !event.originalEvent ) {
return;
}
- event.preventDefault();
+ event.preventDefault();
// TODO can we simplify or extractthis check? especially the last two expressions
// there's a similar active[0] == menu[0] check in _open
if ( event.type == "click" && menu.is( ":visible" ) && that.active && that.active[0] == menu[0] ) {
if ( ( that.open && event.type == "mouseenter" ) || event.type == "click" ) {
that._open( event, menu );
}
- })
+ })
.bind( "keydown", function( event ) {
switch ( event.keyCode ) {
case $.ui.keyCode.SPACE:
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 ( !that.options.buttons ) {
// TODO ui-menubar-link is added above, not needed here?
input.addClass( "ui-menubar-link" ).removeClass( "ui-state-default" );
- };
+ };
});
that._bind( {
}
});
},
-
+
_destroy : function() {
var items = this.element.children( "li" )
.removeClass( "ui-menubar-item" )
.removeAttr( "role", "presentation" )
.children( "button, a" );
-
+
this.element
.removeClass( "ui-menubar ui-widget-header ui-helper-clearfix" )
.removeAttr( "role", "menubar" )
.unbind( ".menubar" );
-
+
items
.unbind( ".menubar" )
.removeClass( "ui-button ui-widget ui-button-text-only ui-menubar-link ui-state-default" )
.removeAttr( "tabindex" )
.unbind( ".menubar" );
},
-
+
_close: function() {
if ( !this.active || !this.active.length )
return;
this.active = null;
this.open = false;
},
-
+
_open: function( event, menu ) {
// on a single-button menubar, ignore reopening the same menu
if ( this.active && this.active[0] == menu[0] ) {
.focusin();
this.open = true;
},
-
+
// TODO refactor this and the next three methods
_prev: function( event, button ) {
button.attr( "tabIndex", -1 );
lastItem.removeAttr( "tabIndex" )[0].focus();
}
},
-
+
_next: function( event, button ) {
button.attr( "tabIndex", -1 );
var next = button.parent().nextAll( "li" ).children( ".ui-button" ).eq( 0 );
this._open( event, lastItem );
}
},
-
+
// TODO rename to child (or something like that)
_right: function( event ) {
var next = this.active.parent().nextAll( "li:eq(0)" ).children( ".ui-menu" ).eq( 0 );