From 9ffc2e72affff72f3dd4f76b87990d58a70d1e05 Mon Sep 17 00:00:00 2001 From: Adrian Lee Date: Thu, 22 May 2014 02:19:30 -0700 Subject: [PATCH] fix(macAutocomplete): Fixed menu not positioned correctly Fixed offset getting calculated before animation completes --- src/directives/autocomplete.coffee | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/directives/autocomplete.coffee b/src/directives/autocomplete.coffee index 958cc63..8c12325 100644 --- a/src/directives/autocomplete.coffee +++ b/src/directives/autocomplete.coffee @@ -144,12 +144,13 @@ angular.module("Mac").directive "macAutocomplete", [ @name appendMenu @description Adding menu to DOM + @param {Function} callback Callback after enter animation completes ### - appendMenu = -> + appendMenu = (callback) -> if inside - $animate.enter menuEl, undefined, element + $animate.enter menuEl, undefined, element, callback else - $animate.enter menuEl, angular.element(document.body) + $animate.enter menuEl, angular.element(document.body), undefined, callback element.bind "blur", clickHandler @@ -177,18 +178,22 @@ angular.module("Mac").directive "macAutocomplete", [ Calculate the style include position and width for menu ### positionMenu = -> - if $menuScope.items.length > 0 + return if $menuScope.items.length is 0 + + appendMenu -> + parentOffset = menuEl.offset() + $menuScope.style = element.offset() - $menuScope.style.top += element.outerHeight() + $menuScope.style.left -= parentOffset.left + $menuScope.style.top += element.outerHeight() - parentOffset.top $menuScope.style.minWidth = element.outerWidth() + # Add 'px' to left and top angular.forEach $menuScope.style, (value, key) -> if not isNaN(+value) and angular.isNumber +value value = "#{value}px" $menuScope.style[key] = value - appendMenu() - ### @function @name updateItem