forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
truncate.js
32 lines (31 loc) · 1.09 KB
/
truncate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
angular.module('openshiftConsole')
// Truncates text to a length, adding a tooltip and an ellipsis if truncated.
// Different than `text-overflow: ellipsis` because it allows for multiline text.
.directive('truncateLongText', function(truncateFilter) {
return {
restrict: 'E',
scope: {
content: '=',
limit: '=',
newlineLimit: '=',
useWordBoundary: '=',
expandable: '=',
prettifyJson: '=' // prettifies JSON blobs when expanded, only used if expandable is true
},
templateUrl: 'views/directives/truncate-long-text.html',
link: function(scope) {
scope.toggles = {expanded: false};
scope.$watch('content', function(content) {
if (content) {
scope.truncatedContent = truncateFilter(content, scope.limit, scope.useWordBoundary, scope.newlineLimit);
scope.truncated = scope.truncatedContent.length !== content.length;
}
else {
scope.truncatedContent = null;
scope.truncated = false;
}
});
}
};
});