Created
January 27, 2014 01:16
-
-
Save janhartigan/8641753 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
/** | |
* 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