Skip to content
Permalink
Browse files

Selectmenu: minor improvements and cleanup

  • Loading branch information
fnagel committed Jan 20, 2012
1 parent 08de75c commit 04d9900c5e45be6eabecdff269648d677b79ff3b
Showing with 19 additions and 23 deletions.
  1. +19 −23 ui/jquery.ui.selectmenu.js
@@ -105,8 +105,8 @@ $.widget( "ui.selectmenu", {
if ( this.options.dropdown ) {
var setWidth = this.button.outerWidth();
} else {
var text = this.button.find( "span.ui-button-text");
var setWidth = text.width() + parseFloat( text.css( "padding-left" ) ) || 0 + parseFloat( text.css( "margin-left" ) || 0 );
var text = this.button.find( "span.ui-button-text"),
setWidth = text.width() + parseFloat( text.css( "padding-left" ) ) || 0 + parseFloat( text.css( "margin-left" ) || 0 );
}

// wrap menu
@@ -119,8 +119,7 @@ $.widget( "ui.selectmenu", {
// init menu widget
this.menu.menu({
select: function( event, ui ) {
var flag = false,
item = ui.item.data( "item.selectmenu" ),
var item = ui.item.data( "item.selectmenu" ),
oldIndex = that.element[0].selectedIndex;

that._setIndex( item.index );
@@ -147,6 +146,9 @@ $.widget( "ui.selectmenu", {
})
// change ARIA role
.attr( 'role', 'menubox' );

// change menu styles?
this._setOption( "dropdown", this.options.dropdown );

// document click closes menu
this._bind( document, {
@@ -172,9 +174,6 @@ $.widget( "ui.selectmenu", {
this.menu.find( "li" ).not( '.ui-selectmenu-optgroup' ).find( 'a' ).attr( 'role', 'option' );
this.menu.attr( "aria-activedescendant" , this.menu.find( "li.ui-menu-item a" ).eq( this.element[0].selectedIndex ).attr( "id" ) );

// change styles?
this._setOption( "dropdown", this.options.dropdown );

// transfer disabled state
if ( this.element.attr( 'disabled' ) ) {
this.disable();
@@ -184,14 +183,10 @@ $.widget( "ui.selectmenu", {
},

open: function( event ) {
var currentItem = this._getSelectedItem();

if ( !this.options.disabled ) {
if ( this.options.dropdown ) {
this.button
.addClass( 'ui-corner-top' )
.removeClass( 'ui-corner-all' );
}
var currentItem = this._getSelectedItem();

this._toggleButtonStyle();

this.menuWrap.addClass( 'ui-selectmenu-open' );
this.menu.attr("aria-hidden", false);
@@ -203,12 +198,11 @@ $.widget( "ui.selectmenu", {
}, 1);

if ( !this.options.dropdown ) {
// calculate offset
var _offset = ( this.menu.offset().top - currentItem.offset().top + ( this.button.outerHeight() - currentItem.outerHeight() ) / 2);
$.extend( this.options.position, {
my: "left top",
at: "left top",
offset: "0 " + _offset
// calculate offset
offset: "0 " + ( this.menu.offset().top - currentItem.offset().top + ( this.button.outerHeight() - currentItem.outerHeight() ) / 2 )
});
}

@@ -225,11 +219,7 @@ $.widget( "ui.selectmenu", {

close: function( event, focus ) {
if ( this.isOpen ) {
if ( this.options.dropdown ) {
this.button
.addClass( 'ui-corner-all' )
.removeClass( 'ui-corner-top' );
}
this._toggleButtonStyle();

this.menuWrap.removeClass( 'ui-selectmenu-open' );
this.menu.attr("aria-hidden", true);
@@ -309,8 +299,8 @@ $.widget( "ui.selectmenu", {
},

_buttonEvents: {
// init Menu on first focus
focus: function( event ) {
// init Menu on first focus
this.refresh();
this.button.unbind( "focus." + this.widgetName )
},
@@ -399,6 +389,12 @@ $.widget( "ui.selectmenu", {
}
}
},

_toggleButtonStyle: function() {
if ( this.options.dropdown ) {
this.button.toggleClass( 'ui-corner-top', !this.isOpen ).toggleClass( 'ui-corner-all', this.isOpen );
}
},

_readOptions: function() {
var data = [];

0 comments on commit 04d9900

Please sign in to comment.
You can’t perform that action at this time.