Selectmenu: code cleanup

This commit is contained in:
Felix Nagel 2011-09-24 02:04:06 +02:00
parent bb4291457c
commit d89e9b41a9

View File

@ -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 ) { open: function( event ) {
var self = this, var self = this,
options = this.options; options = this.options;
@ -227,22 +205,16 @@ $.widget( "ui.selectmenu", {
self.listWrap.addClass( self.widgetBaseClass + '-open' ); self.listWrap.addClass( self.widgetBaseClass + '-open' );
// self.newelement.blur(); self.list.focus().menu( "focus", null, currentItem );
self.list.focus().menu( "focus", null, currentItem )
// currentItem.focus();
if ( !options.dropdown ) { if ( !options.dropdown ) {
// center current item
if ( self.list.css("overflow") == "auto" ) { if ( self.list.css("overflow") == "auto" ) {
self.list.scrollTop( self.list.scrollTop() + currentItem.position().top - self.list.outerHeight()/2 + currentItem.outerHeight()/2 ); 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); 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, { $.extend( options.position, {
my: "left top", my: "left top",
@ -251,8 +223,6 @@ $.widget( "ui.selectmenu", {
}); });
} }
// console.log(options.position);
self.listWrap.position( $.extend({ self.listWrap.position( $.extend({
of: this.newelementWrap of: this.newelementWrap
}, options.position )); }, options.position ));
@ -302,15 +272,26 @@ $.widget( "ui.selectmenu", {
).appendTo( ul ); ).appendTo( ul );
}, },
_destroy: function() { _previous: function() {
clearTimeout( this.searching ); this.list.menu( "focus", null, this._getCurrenItem() );
this.element this.list.menu("previous");
.removeClass( "ui-autocomplete-input" ) },
.removeAttr( "autocomplete" )
.removeAttr( "role" ) _next: function() {
.removeAttr( "aria-autocomplete" ) this.list.menu( "focus", null, this._getCurrenItem() );
.removeAttr( "aria-haspopup" ); this.list.menu("next");
this.menu.element.remove(); },
_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 ) { _setOption: function( key, value ) {
@ -337,6 +318,9 @@ $.widget( "ui.selectmenu", {
return data; return data;
}, },
_destroy: function() {
},
_value: function( newValue ) { _value: function( newValue ) {
if (arguments.length) { if (arguments.length) {
this.element[0].value = newValue; this.element[0].value = newValue;