kibana-123
Version:
Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic
42 lines (37 loc) • 1.11 kB
JavaScript
import $ from 'jquery';
import truncText from 'trunc-text';
import truncHTML from 'trunc-html';
import uiModules from 'ui/modules';
import truncatedTemplate from 'ui/directives/partials/truncated.html';
import 'angular-sanitize';
const module = uiModules.get('kibana', ['ngSanitize']);
module.directive('kbnTruncated', function ($compile) {
return {
restrict: 'E',
scope: {
source: '@',
length: '@',
isHtml: '@'
},
template: truncatedTemplate,
link: function ($scope, $element, attrs) {
const source = $scope.source;
const max = $scope.length;
const truncated = $scope.isHtml
? truncHTML(source, max).html
: truncText(source, max);
$scope.content = truncated;
if (source === truncated) {
return;
}
$scope.truncated = true;
$scope.expanded = false;
$scope.action = 'more';
$scope.toggle = () => {
$scope.expanded = !$scope.expanded;
$scope.content = $scope.expanded ? source : truncated;
$scope.action = $scope.expanded ? 'less' : 'more';
};
}
};
});