diff options
author | Felix Nagel <info@felixnagel.com> | 2013-09-29 15:33:14 +0200 |
---|---|---|
committer | Felix Nagel <info@felixnagel.com> | 2013-09-29 15:33:14 +0200 |
commit | f2d06bf06391a746b030b5f6af532ed5aeaea0a2 (patch) | |
tree | 91e538b99eaed65268c103433a2009348c18276a /ui/jquery.ui.selectmenu.js | |
parent | b1532ed4aebfb45d96e096d0c163838fa6e42394 (diff) | |
download | jquery-ui-f2d06bf06391a746b030b5f6af532ed5aeaea0a2.tar.gz jquery-ui-f2d06bf06391a746b030b5f6af532ed5aeaea0a2.zip |
Selectmenu: add widthMenu and widthButton options
Diffstat (limited to 'ui/jquery.ui.selectmenu.js')
-rw-r--r-- | ui/jquery.ui.selectmenu.js | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js index a5f9485bd..7d7c3fb98 100644 --- a/ui/jquery.ui.selectmenu.js +++ b/ui/jquery.ui.selectmenu.js @@ -29,6 +29,8 @@ $.widget( "ui.selectmenu", { at: "left bottom", collision: "none" }, + widthButton: null, + widthMenu: null, // callbacks change: null, @@ -74,7 +76,6 @@ $.widget( "ui.selectmenu", { "class": "ui-selectmenu-button ui-widget ui-state-default ui-corner-all", tabindex: tabindex || this.options.disabled ? -1 : 0, id: this.ids.button, - width: this.element.outerWidth(), role: "combobox", "aria-expanded": "false", "aria-autocomplete": "list", @@ -91,7 +92,9 @@ $.widget( "ui.selectmenu", { "class": "ui-selectmenu-text" }) .appendTo( this.button ); + this._setText( this.buttonText, this.element.find( "option:selected" ).text() ); + this._setOption( "widthButton", this.options.widthButton ); this._on( this.button, this._buttonEvents ); this._hoverable( this.button ); @@ -110,8 +113,7 @@ $.widget( "ui.selectmenu", { // Wrap menu this.menuWrap = $( "<div>", { - "class": "ui-selectmenu-menu ui-front", - outerWidth: this.button.outerWidth() + "class": "ui-selectmenu-menu ui-front" }) .append( this.menu ) .appendTo( this._appendTo() ); @@ -203,6 +205,7 @@ $.widget( "ui.selectmenu", { this.isOpen = true; this._toggleAttr(); + this._resizeMenu(); this._position(); this._on( this.document, this._documentClick ); @@ -440,6 +443,12 @@ $.widget( "ui.selectmenu", { this.button.attr( "tabindex", 0 ); } } + if ( key === "widthButton" ) { + if ( !value ) { + value = this.element.outerWidth(); + } + this.button.outerWidth( value ); + } }, _appendTo: function() { @@ -471,6 +480,13 @@ $.widget( "ui.selectmenu", { this.button.attr( "aria-expanded", this.isOpen ); }, + _resizeMenu: function() { + this.menu.outerWidth( this.options.widthMenu || Math.max( + this.button.outerWidth(), + this.menu.width( "" ).outerWidth() + ) ); + }, + _getCreateOptions: function() { return { disabled: this.element.prop( "disabled" ) }; }, |