Skip to content

Commit d98d2de

Browse files
SteveTheTechieHarris
authored andcommitted
Switch to using offsetTop and offsetHeight in _setMenuHeight()
Eliminate need for _getBCRHeight() and _jqHeightFix()
1 parent 66cd932 commit d98d2de

File tree

1 file changed

+10
-33
lines changed

1 file changed

+10
-33
lines changed

src/jquery.multiselect.js

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@
11171117
if ( /\d/.test(optionHeight) ) {
11181118
// Deduct height of header & border/padding to find height available for checkboxes.
11191119
var $header = self.$header.filter(':visible');
1120-
var headerHeight = $header.outerHeight(true) + self._jqHeightFix($header);
1120+
var headerHeight = $header.outerHeight(true);
11211121
var menuBorderPaddingHt = this.$menu.outerHeight(false) - this.$menu.height();
11221122
var cbBorderPaddingHt = this.$checkboxes.outerHeight(false) - this.$checkboxes.height();
11231123

@@ -1133,13 +1133,19 @@
11331133

11341134
var overflowSetting = 'hidden';
11351135
var itemCount = 0;
1136-
var ulHeight = 4; // Adjustment for hover height included here.
1136+
var hoverAdjust = 4; // Adjustment for hover height included here.
1137+
var ulHeight = hoverAdjust;
1138+
var ulTop = -1;
11371139

1138-
// The following adds up item heights. If the height sum exceeds the option height or if the number
1140+
// The following determines the how many items are visible per the menuHeight option.
1141+
// If the visible height calculation exceeds the calculated maximum height or if the number
11391142
// of item heights summed equal or exceed the native select size attribute, the loop is aborted.
11401143
// If the loop is aborted, this means that the menu must be scrolled to see all the items.
11411144
self.$checkboxes.find('li:not(.ui-multiselect-optgroup),a').filter(':visible').each( function() {
1142-
ulHeight += $(this).outerHeight(true) + self._jqHeightFix(this);
1145+
if (ulTop < 0) {
1146+
ulTop = this.offsetTop;
1147+
}
1148+
ulHeight = this.offsetTop + this.offsetHeight - ulTop + hoverAdjust;
11431149
if (useSelectSize && ++itemCount >= elSelectSize || ulHeight > maxHeight) {
11441150
overflowSetting = 'auto';
11451151
if (!useSelectSize) {
@@ -1169,20 +1175,6 @@
11691175
return domRect.right - domRect.left;
11701176
},
11711177

1172-
/**
1173-
* Calculate accurate outerHeight(false) using getBoundingClientRect()
1174-
* Note that this presumes that the element is visible in the layout.
1175-
* @param {node} DOM node or jQuery equivalent to get height for.
1176-
* @returns {float} Decimal floating point value for the height.
1177-
*/
1178-
_getBCRHeight: function(elem) {
1179-
if (!elem || !!elem.jquery && !elem[0]) {
1180-
return null;
1181-
}
1182-
var domRect = !!elem.jquery ? elem[0].getBoundingClientRect() : elem.getBoundingClientRect();
1183-
return domRect.bottom - domRect.top;
1184-
},
1185-
11861178
/**
11871179
* Calculate jQuery width correction factor to fix floating point round-off errors.
11881180
* Note that this presumes that the element is visible in the layout.
@@ -1198,21 +1190,6 @@
11981190
: this._getBCRWidth(elem) - $(elem).outerWidth(false);
11991191
},
12001192

1201-
/**
1202-
* Calculate jQuery height correction factor to fix floating point round-off errors.
1203-
* Note that this presumes that the element is visible in the layout.
1204-
* @param {node} DOM node or jQuery equivalent to get height for.
1205-
* @returns {float} Correction value for the height--typically a decimal < 1.0
1206-
*/
1207-
_jqHeightFix: function(elem) {
1208-
if (!elem || !!elem.jquery && !elem[0]) {
1209-
return null;
1210-
}
1211-
return !!elem.jquery
1212-
? this._getBCRHeight(elem[0]) - elem.outerHeight(false)
1213-
: this._getBCRHeight(elem) - $(elem).outerHeight(false);
1214-
},
1215-
12161193
/**
12171194
* Moves focus up or down the options list
12181195
* @param {number} which key that triggered the traversal

0 commit comments

Comments
 (0)