Skip to content

Instantly share code, notes, and snippets.

@janhartigan
Created January 27, 2014 01:16
Show Gist options
  • Save janhartigan/8641753 to your computer and use it in GitHub Desktop.
Save janhartigan/8641753 to your computer and use it in GitHub Desktop.
/**
* Ellipsis Title Directive
*/
angular.module('common').directive('ellipsisTitle', function()
{
return {
link: function(scope, element, attrs)
{
//watch for changes to the provided value
scope.$watch(attrs.ellipsisTitle, function(newValue, oldValue)
{
//if the offset width is less than the scroll width, add the title
//otherwise remove it
if (element[0].offsetWidth < element[0].scrollWidth)
element.attr('title', scope[attrs.ellipsisTitle] ? scope[attrs.ellipsisTitle] : element.text());
else
element.removeAttr('title');
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment