Skip to content

Commit 58c7c34

Browse files
committed
Resize menu based on list length
The menu is now sized based on the height of all the available options or the height option, whichever is less.
1 parent f14d61f commit 58c7c34

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/jquery.multiselect.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@
225225
this.labels = menu.find('label');
226226
this.inputs = this.labels.children('input');
227227

228-
// set widths
229228
this._setButtonWidth();
230-
this._setMenuWidth();
231229

232230
// remember default value
233231
this.button[0].defaultValue = this.update();
@@ -517,6 +515,28 @@
517515
m.outerWidth(this.options.menuWidth || width);
518516
},
519517

518+
_setMenuHeight: function() {
519+
var headerHeight = this.menu.children(".ui-multiselect-header:visible").outerHeight(true);
520+
var ulHeight = 0;
521+
this.menu.find(".ui-multiselect-checkboxes li").each(function(idx, li) {
522+
ulHeight += $(li).outerHeight(true);
523+
});
524+
if(ulHeight > this.options.height) {
525+
this.menu.children("ui-multiselect-checkboxes").css("overflow", "auto");
526+
ulHeight = this.options.height;
527+
} else {
528+
this.menu.children("ui-multiselect-checkboxes").css("overflow", "hidden");
529+
}
530+
531+
this.menu.children("ui-multiselect-checkboxes").height(ulHeight);
532+
this.menu.height(ulHeight + headerHeight);
533+
},
534+
535+
_resizeMenu: function() {
536+
this._setMenuWidth();
537+
this._setMenuHeight();
538+
},
539+
520540
// move up or down within the menu
521541
_traverse: function(which, start) {
522542
var $start = $(start);
@@ -653,6 +673,7 @@
653673
// show the menu, maybe with a speed/effect combo
654674
$.fn.show.apply(menu, args);
655675

676+
this._resizeMenu();
656677
// positon
657678
this.position();
658679

@@ -787,7 +808,8 @@
787808
menu.find('a.ui-multiselect-none span').eq(-1).text(value);
788809
break;
789810
case 'height':
790-
menu.find('ul').last().height(parseInt(value, 10));
811+
this.options[key] = value;
812+
this._setMenuHeight();
791813
break;
792814
case 'minWidth':
793815
case 'menuWidth':

0 commit comments

Comments
 (0)