Created
June 13, 2014 10:09
-
-
Save guilbep/72860b004dd8c13b5322 to your computer and use it in GitHub Desktop.
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
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