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

Commit

Permalink
fix(macTooltip): Fixed multiple tooltips getting appended to body whe…
Browse files Browse the repository at this point in the history
…n triggering it multiple times in a short period of time

Fixes #157
  • Loading branch information
adrianlee44 committed Mar 4, 2014
1 parent 5cce157 commit a45c75b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/directives/tooltip.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ angular.module("Mac").directive "macTooltip", [

opts = util.extendAttributes "macTooltip", defaults, attrs

showTip = (event) ->
showTip = ->
return true if disabled or not text

tip =
if opts.inside then element else angular.element(document.body)

## Check if the tooltip still exist, remove if it does
removeTip(0)

tooltip = angular.element """<div class="tooltip #{opts.direction}"><div class="tooltip-message">#{text}</div></div>"""
tip.append tooltip

Expand Down Expand Up @@ -84,16 +88,17 @@ angular.module("Mac").directive "macTooltip", [
tooltip.addClass "visible"
return true

removeTip = (event) ->
removeTip = (delay = 100) ->
if tooltip?
tooltip.removeClass "visible"
$timeout ->
tooltip.remove()
, 100, false
tooltip?.remove()
tooltip = null
, delay, false
return true

toggle = (event) ->
if tooltip? then removeTip(event) else showTip(event)
toggle = ->
if tooltip? then removeTip() else showTip()

attrs.$observe "macTooltip", (value) ->
if value?
Expand All @@ -108,7 +113,7 @@ angular.module("Mac").directive "macTooltip", [
element.bind "click", toggle
when "hover"
element.bind "mouseenter", showTip
element.bind "mouseleave click", removeTip
element.bind "mouseleave click", -> removeTip()

enabled = true

Expand All @@ -117,5 +122,5 @@ angular.module("Mac").directive "macTooltip", [
disabled = value

scope.$on "$destroy", ->
removeTip() if tooltip?
removeTip(0) if tooltip?
]

0 comments on commit a45c75b

Please sign in to comment.