Created
May 16, 2015 20:05
-
-
Save JonnyBurger/f9ad90e65e09d4e404cc to your computer and use it in GitHub Desktop.
Tooltip directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tooltip directive | |
.directive 'ngTooltip', () -> | |
return { | |
restrict: 'A' | |
link: (scope, elem, attrs) -> | |
if attrs.onlyLogout? and scope.$parent.$parent.$parent.user | |
return | |
tooltip = $('<div>') | |
elem.bind 'mouseenter', (event) -> | |
if attrs.onlyEmptyList? and scope.tracks?.length isnt 0 | |
return | |
tooltip.addClass 'tooltip' | |
offset = elem.offset() | |
width = elem.outerWidth() | |
height = elem.outerHeight() | |
tooltip.text attrs.ngTooltip | |
$('body').append tooltip | |
if attrs.ngTooltipBelow? | |
top = offset.top + Math.floor(tooltip.outerHeight()) + 6 - 4 | |
tooltip.addClass 'tooltip-below' | |
else | |
top = offset.top - Math.floor(tooltip.outerHeight()) - 6 - 4 | |
if attrs.ngTooltipLeft? | |
left = Math.floor(offset.left) + Math.floor(width/2) - 10 | |
tooltip.addClass 'tooltip-left' | |
else | |
left = Math.floor(offset.left) + Math.floor(width/2) - Math.floor(tooltip.outerWidth()/2) | |
tooltip.css { | |
left: left | |
top: top | |
} | |
elem.bind 'mouseleave', () -> | |
tooltip.remove() | |
if attrs.ngTooltipUpdate? | |
elem.bind 'click', () -> | |
setTimeout -> | |
tooltip.text attrs.ngTooltip | |
if attrs.ngTooltipRemove? | |
elem.bind 'click', () -> | |
tooltip.remove() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment