Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
fix(macAutocomplete): Fixed menu not positioned correctly
Browse files Browse the repository at this point in the history
Fixed offset getting calculated before animation completes
  • Loading branch information
adrianlee44 committed May 22, 2014
1 parent 14b28c8 commit 9ffc2e7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/directives/autocomplete.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9ffc2e7

Please sign in to comment.