Skip to content

Commit

Permalink
make use of the new _position method
Browse files Browse the repository at this point in the history
  • Loading branch information
fnagel committed Jul 10, 2013
1 parent 02762b0 commit ab2659d
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions selectmenu/jquery.ui.selectmenu.popupStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,24 @@ $.widget( "ui.selectmenu", $.ui.selectmenu, {
}
},

open: function( event ) {
if ( this.options.disabled ) {
return;
_position: function() {
if ( !this.options.popup ) {
this._super();
}

if ( this.options.popup && this.items ) {
var currentItem;

this.isOpen = true;
this._toggleAttr();

currentItem = this._getSelectedItem();
// center current item
if ( this.menu.outerHeight() < this.menu.prop( "scrollHeight" ) ) {
this.menuWrap.css( "left" , -10000 );
this.menu.scrollTop( this.menu.scrollTop() + currentItem.position().top - this.menu.outerHeight() / 2 + currentItem.outerHeight() / 2 );
this.menuWrap.css( "left" , "auto" );
}

this.menuWrap.position( $.extend( {}, this.options.position, {
of: this.button,
my: "left top" + ( this.menu.offset().top - currentItem.offset().top + ( this.button.outerHeight() - currentItem.outerHeight() ) / 2 ),
at: "left top"
} ) );

this._on( this.document, this._documentClick );

this._trigger( "open", event );
} else {
this._super();
currentItem = this._getSelectedItem();
// center current item
if ( this.menu.outerHeight() < this.menu.prop( "scrollHeight" ) ) {
this.menuWrap.css( "left" , -10000 );
this.menu.scrollTop( this.menu.scrollTop() + currentItem.position().top - this.menu.outerHeight() / 2 + currentItem.outerHeight() / 2 );
this.menuWrap.css( "left" , "auto" );
}

this.menuWrap.position( $.extend( {}, this.options.position, {
of: this.button,
my: "left top" + ( this.menu.offset().top - currentItem.offset().top + ( this.button.outerHeight() - currentItem.outerHeight() ) / 2 ),
at: "left top"
} ) );
},

_toggleAttr: function(){
Expand Down

0 comments on commit ab2659d

Please sign in to comment.