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
50 lines (38 loc) • 1.13 kB
JavaScript
import _ from 'lodash';
import 'ui/notify/directives';
import uiModules from 'ui/modules';
let typeahead = uiModules.get('kibana/typeahead');
typeahead.directive('kbnTypeaheadInput', function ($rootScope) {
return {
restrict: 'A',
require: ['^ngModel', '^kbnTypeahead'],
link: function ($scope, $el, $attr, deps) {
let model = deps[0];
let typeaheadCtrl = deps[1];
typeaheadCtrl.setInputModel(model);
// disable browser autocomplete
$el.attr('autocomplete', 'off');
// handle keypresses
$el.on('keydown', function (ev) {
typeaheadCtrl.keypressHandler(ev);
digest();
});
// update focus state based on the input focus state
$el.on('focus', function () {
typeaheadCtrl.setFocused(true);
digest();
});
$el.on('blur', function () {
typeaheadCtrl.setFocused(false);
digest();
});
// unbind event listeners
$scope.$on('$destroy', function () {
$el.off();
});
function digest() {
$rootScope.$$phase || $scope.$digest();
}
}
};
});