{"size": 1442, "ext": "js", "max_stars_repo_path": "App/JavaScript/Src/search-input.js", "max_stars_repo_name": "splintercode/angular-search", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "App/JavaScript/Src/search-input.js", "max_issues_repo_name": "splintercode/angular-search", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "App/JavaScript/Src/search-input.js", "max_forks_repo_name": "splintercode/angular-search", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 36.9743589744, "max_line_length": 126, "alphanum_fraction": 0.4486823856}
﻿(function() {
    'use strict';

    var appDirectives = angular.module('app.directives');

    appDirectives.directive('searchInput', ['searchService', function(searchService) {
        return {
            restrict: 'E',
            transclude: true,
            replace: true,
            scope: {
                results: '=ngModel',
                query: '=value',
            },
            template: [
                '<form name="searchForm" novalidate ng-submit="search(searchForm.$valid, query)">',
                    '<input type="search" ng-model="query" placeholder="Search" class="search-form__input" required />',
                    '<button type="submit" class="btn search-form__btn">',
                        '<span ng-show="!isLoading">Search</span><i ng-show="isLoading" class="animate-spin icon-spin1"></i>',
                    '</button>',
                '</form>'
            ].join(''),
            link: function(scope) {
                scope.isLoading = false;

                scope.search = function(valid, query) {
                    if (valid) {
                        scope.isLoading = true;
                        searchService.search(query).then(function(results) {
                            scope.results = results.data.d.results[0];
                            scope.isLoading = false;
                        });
                    }
                };
            }
        };
    }]);
}());
