2016-05-19 06:50:32 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.search')
|
|
|
|
.directive('searchInput', searchInput);
|
|
|
|
|
|
|
|
SearchInputController.$inject = ['$scope', '$location', '$window'];
|
|
|
|
|
|
|
|
function SearchInputController($scope, $location, $window) {
|
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
vm.searchFor = searchFor;
|
|
|
|
|
|
|
|
function searchFor(searchContent) {
|
|
|
|
$location
|
2016-06-16 08:10:35 +02:00
|
|
|
.path('/search')
|
2016-05-19 06:50:32 +02:00
|
|
|
.search({'q': searchContent});
|
|
|
|
$window.location.href = $location.url();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function searchInput() {
|
|
|
|
|
|
|
|
var directive = {
|
|
|
|
'restrict': 'E',
|
2016-06-16 08:10:35 +02:00
|
|
|
'templateUrl': '/static/resources/js/components/search/search-input.directive.html',
|
2016-05-19 06:50:32 +02:00
|
|
|
'scope': {
|
|
|
|
'searchInput': '=',
|
|
|
|
},
|
|
|
|
'link': link,
|
|
|
|
'controller': SearchInputController,
|
|
|
|
'controllerAs': 'vm',
|
|
|
|
'bindToController': true
|
|
|
|
};
|
|
|
|
return directive;
|
|
|
|
|
|
|
|
function link(scope, element, attrs, ctrl) {
|
|
|
|
element
|
|
|
|
.find('input[type="text"]')
|
|
|
|
.on('keydown', keydownHandler);
|
|
|
|
|
|
|
|
function keydownHandler(e) {
|
|
|
|
if(e.keyCode === 13) {
|
|
|
|
ctrl.searchFor($(this).val());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|