Skip to content

Instantly share code, notes, and snippets.

@guilbep
Created June 13, 2014 10:09
Show Gist options
  • Save guilbep/72860b004dd8c13b5322 to your computer and use it in GitHub Desktop.
Save guilbep/72860b004dd8c13b5322 to your computer and use it in GitHub Desktop.
define(['directives/directives-module'], function(module) {
module.directive('xngTooltip', function($parse) {
return {
restrict: 'A',
priority: 0,
scope: true,
link: function postLink(scope, element, attrs, ctrl) {
var getter = $parse(attrs.xngTooltip),
setter = getter.assign,
value = getter(scope);
scope.$watch(attrs.xngTooltip, function(newValue, oldValue) {
if (newValue !== oldValue) {
value = newValue;
}
});
if (!!attrs.unique) {
element.on('show', function(ev) {
angular('.tooltip.in').each(function() {
var _this = $(this);
var tooltip = _this.data('tooltip');
if (tooltip && !tooltip.$element.is(element)) {
_this.tooltip('hide');
}
});
});
}
element.tooltip({
title: function() {
return angular.isFunction(value) ? value.apply(null, arguments) : value;
},
html: true
});
}
};
});
return module;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment