Added a css based truncate directive

This commit is contained in:
Rashid Khan 2014-03-26 15:09:19 -07:00
parent 4f35fd62f4
commit 1881bfdd00

View file

@ -0,0 +1,37 @@
define(function (require) {
var module = require('modules').get('kibana/directives');
var $ = require('jquery');
var _ = require('lodash');
module.directive('cssTruncate', function ($compile) {
return {
restrict: 'A',
scope: {},
link: function ($scope, $elem, attrs) {
$elem.css({
overflow: 'hidden',
'white-space': 'nowrap',
'text-overflow': 'ellipsis',
'word-break': 'break-all',
});
if (!_.isUndefined(attrs.cssTruncateExpandable)) {
$elem.css({'cursor': 'pointer'});
$elem.bind('click', function () {
if ($elem.css('white-space') !== 'normal') {
$elem.css({'white-space': 'normal'});
} else {
$elem.css({'white-space': 'nowrap'});
}
});
}
$scope.$on('$destroy', function () {
$elem.unbind('click');
$elem.unbind('mouseenter');
});
}
};
});
});