--- /dev/null
+<form>
+ <div class='form-group has-icon'>
+ <input placeholder='Search...' type='text' class='form-control search-input'
+ ng-model-options='{ debounce: 300 }' ng-model='query'
+ ng-keydown='update($event)' ng-change='search()'>
+ <span class='glyphicon glyphicon-search form-control-icon text-muted'></span>
+ </div>
+ <div ng-if='results.length > 0' class='search-results'>
+ <div class='card-list'>
+ <search-card ng-click='selectEnter()' ng-class='{active: activeItem == $index}' ng-mouseover='setActive($index)' mentity='mentity' ng-repeat='mentity in results' />
+ </div>
+ </div>
+</form>
</div>
</div>
<div class='col-xs-7'>
- <form ng-controller='SearchCtrl as searchCtrl' >
- <div class='form-group has-icon'>
- <input placeholder='Search...' type='text' class='form-control search-input'
- ng-model-options='{ debounce: 300 }' ng-model='query'
- ng-keydown='update($event)' ng-change='search()'>
- <span class='glyphicon glyphicon-search form-control-icon text-muted'></span>
- </div>
- <div ng-if='results.length > 0' class='search-results'>
- <div class='card-list'>
- <search-card ng-click='selectEnter()' ng-class='{active: activeItem == $index}' ng-mouseover='setActive($index)' mentity='mentity' ng-repeat='mentity in results' />
- </div>
- </div>
- </form>
+ <search-field />
</div>
<div class='col-xs-2'>
<user-menu />
angular
.module('ui', [ 'model' ])
- .controller('SearchCtrl', ['Model', '$routeParams', '$scope', '$location', function(Model, $routeParams, $scope, $location) {
+ .controller('SearchCtrl', function(Model, $routeParams, $scope, $location, $document) {
+
$scope.query = '';
$scope.reset = function() {
}
$scope.reset();
- }])
+ })
+
+ .directive('searchField', function($document) {
+ return {
+ restrict: 'E',
+ replace: true,
+ controller: 'SearchCtrl',
+ controllerAs: 'searchCtrl',
+ templateUrl: '/directives/search/field.html',
+ link: function ($scope, element, attrs) {
+ $document.bind('click', function (event) {
+ var isChild = $(element).has(event.target).length > 0;
+ var isSelf = element[0] == event.target;
+ var isInside = isChild || isSelf;
+ if (!isInside) {
+ $scope.reset();
+ $scope.$apply();
+ }
+ });
+ }
+ };
+ })
.directive('searchCard', function() {
return {