aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Nagel <info@felixnagel.com>2012-01-20 01:30:16 +0100
committerFelix Nagel <info@felixnagel.com>2012-01-20 01:30:16 +0100
commit04d9900c5e45be6eabecdff269648d677b79ff3b (patch)
treeafdd7637342e3107dd159e30949ac1812b80c24d
parent08de75cbec6f676bf2a9f96867c5e1df44d7d759 (diff)
downloadjquery-ui-04d9900c5e45be6eabecdff269648d677b79ff3b.tar.gz
jquery-ui-04d9900c5e45be6eabecdff269648d677b79ff3b.zip
Selectmenu: minor improvements and cleanup
-rw-r--r--ui/jquery.ui.selectmenu.js42
1 files changed, 19 insertions, 23 deletions
diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js
index 081f5386c..389bc1983 100644
--- a/ui/jquery.ui.selectmenu.js
+++ b/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 = [];