Permalink
Browse files

Selectmenu: code cleanup

  • Loading branch information...
1 parent bb42914 commit d89e9b41a9605db3f3d64c30cf511965a749a1f0 @fnagel fnagel committed Sep 24, 2011
Showing with 29 additions and 45 deletions.
  1. +29 −45 ui/jquery.ui.selectmenu.js
View
@@ -186,28 +186,6 @@ $.widget( "ui.selectmenu", {
},
- _previous: function() {
- this.list.menu( "focus", null, this._getCurrenItem() );
- this.list.menu("previous");
- },
-
- _next: function() {
- this.list.menu( "focus", null, this._getCurrenItem() );
- this.list.menu("next");
- },
-
- _getCurrenItem: function() {
- return this.list.find( "li" ).not( '.ui-selectmenu-optgroup' ).eq( this._index() );
- },
-
- _toggle: function( event ) {
- if ( this.opened ) {
- this.close( event );
- } else {
- this.open( event );
- }
- },
-
open: function( event ) {
var self = this,
options = this.options;
@@ -227,32 +205,24 @@ $.widget( "ui.selectmenu", {
self.listWrap.addClass( self.widgetBaseClass + '-open' );
- // self.newelement.blur();
- self.list.focus().menu( "focus", null, currentItem )
- // currentItem.focus();
+ self.list.focus().menu( "focus", null, currentItem );
if ( !options.dropdown ) {
+ // center current item
if ( self.list.css("overflow") == "auto" ) {
self.list.scrollTop( self.list.scrollTop() + currentItem.position().top - self.list.outerHeight()/2 + currentItem.outerHeight()/2 );
}
- // console.log( self.newelement.offset().top );
- // console.log( currentItem.offset().top );
+
+ // calculate offset
var _offset = (self.list.offset().top - currentItem.offset().top + (self.newelement.outerHeight() - currentItem.outerHeight()) / 2);
- // console.log( currentItem );
- // console.log( currentItem.position().top );
- // console.log( _offset );
-
-
$.extend( options.position, {
my: "left top",
at: "left top",
offset: "0 " + _offset
});
}
-
- // console.log(options.position);
-
+
self.listWrap.position( $.extend({
of: this.newelementWrap
}, options.position ));
@@ -302,17 +272,28 @@ $.widget( "ui.selectmenu", {
).appendTo( ul );
},
- _destroy: function() {
- clearTimeout( this.searching );
- this.element
- .removeClass( "ui-autocomplete-input" )
- .removeAttr( "autocomplete" )
- .removeAttr( "role" )
- .removeAttr( "aria-autocomplete" )
- .removeAttr( "aria-haspopup" );
- this.menu.element.remove();
+ _previous: function() {
+ this.list.menu( "focus", null, this._getCurrenItem() );
+ this.list.menu("previous");
},
-
+
+ _next: function() {
+ this.list.menu( "focus", null, this._getCurrenItem() );
+ this.list.menu("next");
+ },
+
+ _getCurrenItem: function() {
+ return this.list.find( "li" ).not( '.ui-selectmenu-optgroup' ).eq( this._index() );
+ },
+
+ _toggle: function( event ) {
+ if ( this.opened ) {
+ this.close( event );
+ } else {
+ this.open( event );
+ }
+ },
+
_setOption: function( key, value ) {
this._super( "_setOption", key, value );
if ( key === "appendTo" ) {
@@ -337,6 +318,9 @@ $.widget( "ui.selectmenu", {
return data;
},
+ _destroy: function() {
+ },
+
_value: function( newValue ) {
if (arguments.length) {
this.element[0].value = newValue;

1 comment on commit d89e9b4

Member

fnagel commented on d89e9b4 Oct 11, 2011

Thanks but this method has been renamed to _getSelectedItem.

Please note the selectmenu widget is reviewed currently: #492

Please sign in to comment.