Skip to content

Commit faa73a1

Browse files
author
dwu300
committed
fixed a bug in Dropdown which caused an Error, except you are using jQuery. Especially the function getClosestAncestor(). See issue #43
1 parent a8a30a3 commit faa73a1

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

js/dropdown.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,9 @@
427427
if (alignments.spaceOnTop > alignments.spaceOnBottom) {
428428
verticalAlignment = 'bottom';
429429
idealHeight += alignments.spaceOnTop;
430-
idealYPos -= this.options.coverTrigger ? alignments.spaceOnTop - 20 : alignments.spaceOnTop - 20 + triggerBRect.height;
430+
idealYPos -= this.options.coverTrigger
431+
? alignments.spaceOnTop - 20
432+
: alignments.spaceOnTop - 20 + triggerBRect.height;
431433
} else {
432434
idealHeight += alignments.spaceOnBottom;
433435
}
@@ -527,8 +529,25 @@
527529
* Place dropdown
528530
*/
529531
_placeDropdown() {
532+
/**
533+
* Get closest ancestor that satisfies the condition
534+
* @param {Element} el Element to find ancestors on
535+
* @param {Function} condition Function that given an ancestor element returns true or false
536+
* @returns {Element} Return closest ancestor or null if none satisfies the condition
537+
*/
538+
const getClosestAncestor = function(el, condition) {
539+
let ancestor = el.parentNode;
540+
while (ancestor !== null && !$(ancestor).is(document)) {
541+
if (condition(ancestor)) {
542+
return ancestor;
543+
}
544+
ancestor = ancestor.parentNode;
545+
}
546+
return null;
547+
};
548+
530549
// Container here will be closest ancestor with overflow: hidden
531-
let closestOverflowParent = M.getClosestAncestor(this.dropdownEl, (ancestor) => {
550+
let closestOverflowParent = getClosestAncestor(this.dropdownEl, (ancestor) => {
532551
return $(ancestor).css('overflow') !== 'visible';
533552
});
534553
// Fallback

js/global.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -167,36 +167,6 @@ M.escapeHash = function(hash) {
167167
return hash.replace(/(:|\.|\[|\]|,|=|\/)/g, '\\$1');
168168
};
169169

170-
/**
171-
* Get closest ancestor that satisfies the condition
172-
* @param {Element} el Element to find ancestors on
173-
* @param {Function} condition Function that given an ancestor element returns true or false
174-
* @returns {Element} Return closest ancestor or null if none satisfies the condition
175-
*/
176-
M.getClosestAncestor = function(el, condition) {
177-
let ancestor = el.parentNode;
178-
while (ancestor !== null && !$(ancestor).is(document)) {
179-
if (condition(ancestor)) {
180-
return ancestor;
181-
}
182-
ancestor = ancestor.parentNode;
183-
}
184-
return null;
185-
};
186-
187-
M.elementOrParentIsFixed = function(element) {
188-
let $element = $(element);
189-
let $checkElements = $element.add($element.parents());
190-
let isFixed = false;
191-
$checkElements.each(function() {
192-
if ($(this).css('position') === 'fixed') {
193-
isFixed = true;
194-
return false;
195-
}
196-
});
197-
return isFixed;
198-
};
199-
200170
/**
201171
* @typedef {Object} Edges
202172
* @property {Boolean} top If the top edge was exceeded

0 commit comments

Comments
 (0)