Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
feat(autocomplete): adds support for md-autocomplete-snap to specif…
Browse files Browse the repository at this point in the history
…y parent element for autocomplete vertical snap
  • Loading branch information
Robert Messerle committed Apr 8, 2015
1 parent e8fc3b4 commit 15d1db7
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/components/autocomplete/js/autocompleteController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,22 @@

function positionDropdown () {
if (!elements) return $timeout(positionDropdown, 0, false);
var rect = elements.wrap.getBoundingClientRect(),
var hrect = elements.wrap.getBoundingClientRect(),
vrect = elements.snap.getBoundingClientRect(),
root = elements.root.getBoundingClientRect(),
top = rect.bottom - root.top,
bot = root.height - rect.top,
left = rect.left - root.left,
width = rect.width,
top = vrect.bottom - root.top,
bot = root.height - vrect.top,
left = hrect.left - root.left,
width = hrect.width,
styles = { left: left + 'px', width: width + 'px' };
if (top > bot && root.height - rect.bottom - MENU_PADDING < MAX_HEIGHT) {
if (top > bot && root.height - hrect.bottom - MENU_PADDING < MAX_HEIGHT) {
styles.top = 'auto';
styles.bottom = bot + 'px';
styles.maxHeight = Math.min(MAX_HEIGHT, rect.top - root.top - MENU_PADDING) + 'px';
styles.maxHeight = Math.min(MAX_HEIGHT, hrect.top - root.top - MENU_PADDING) + 'px';
} else {
styles.top = top + 'px';
styles.bottom = 'auto';
styles.maxHeight = Math.min(MAX_HEIGHT, root.height - rect.bottom - MENU_PADDING) + 'px';
styles.maxHeight = Math.min(MAX_HEIGHT, root.height - hrect.bottom - MENU_PADDING) + 'px';
}
elements.$.ul.css(styles);
}
Expand Down Expand Up @@ -115,9 +116,17 @@
wrap: $element.find('md-autocomplete-wrap')[0],
root: document.body
};
elements.snap = getSnapTarget();
elements.$ = getAngularElements(elements);
}

function getSnapTarget () {
for (var element = $element, max = 100; element.length; element = element.parent()) {
if (angular.isDefined(element.attr('md-autocomplete-snap'))) return element[0];
}
return elements.wrap;
}

function getAngularElements (elements) {
var obj = {};
for (var key in elements) {
Expand Down

0 comments on commit 15d1db7

Please sign in to comment.