<commit_before>/**
 * ng-suggestion - v1.0.2 - Flexible AngularJS typeahead / autocomplete /
 * suggestion / predictive search directive
 *
 * @author <NAME> <<EMAIL>>
 */
(function(angular) {
  'use strict';

  angular
    .module('ng-suggestion', ['ng-dropdown'])
    .service('SuggestionService', [
      'DropdownService',
      function(DropdownService) {

        this.inputs = [];
        this.deleteHandlers = {};

        this.responseHandler = function(input) {
          return (response) => {
            input.loading = false;
            input.oldParams = input.params;
            if (response) {
              DropdownService.open(input.dropdown.id);
              if (input.responseProperty &&
                  response[input.responseProperty] &&
                  Array.isArray(response[input.responseProperty]) &&
                  response[input.responseProperty].length > 0) {
                input.options = response[input.responseProperty];
              } else if (Array.isArray(response) && response.length > 0) {
                input.options = response;
              } else {
                input.options = false;
              }
            } else {
              input.options = false;
            }
          };
        };

        this.keyUpHandler = function(input) {
          return ($event) => {
            if ($event.keyCode === 8 || $event.keyCode === 46) { // Backspace
              if (this.deleteHandlers[input.id]) {               // or Delete
                this.deleteHandlers[input.id]($event);
              }
            }

            if ($event.keyCode === 27) { // Esc or Tab
              input.element[0].blur();
            } else if (!input.model) {
              DropdownService.close(input.dropdown.id);
            } else if (input.oldParams !== input.params &&
              [9, 27, 40, 38, 13].indexOf($event.keyCode) === -1) {
              input.loading = true;
              if (input.responseProperty) {
                input.resource.get(input.params, this.responseHandler(input));
              } else {
                input.resource.query(input.params, this.responseHandler(input));
              }
            }
          };
        };

        this.keydownHandler = function(input) {
          return ($event) => {
            var currentOption = input.dropdown.currentOption;
            if (currentOption && $event.keyCode === 13) { // Enter
              input.dropdown.disableClick = false;
            }
          };
        };

        this.focusHandler = function(input) {
          return () => {
            input.dropdown.disableClick = true;
            if (input.model) {
              DropdownService.open(input.dropdown.id);
            }
          };
        };

        this.blurHandler = function(input) {
          return () => {
            if (!input.dropdown.isInsideMenu) {
              DropdownService.close(input.dropdown.id);
            } else {
              input.dropdown.disableClick = false;
            }
          };
        };

      }
    ])
    .directive('suggestion', [
      '$resource',
      'SuggestionService',
      function($resource, SuggestionService) {
        return {
          restrict: 'A',
          scope: {
            suggestion: '=?',
            model: '=suggestionModel',
            url: '=suggestionUrl',
            params: '=suggestionParams',
            dropdown: '=suggestionDropdown',
            responseProperty: '@?suggestionResponseProperty'
          },
          link: function($scope, $element) {
            var input = {<commit_msg>extend directive to accept and utilize new params<commit_after>/**
 * ng-suggestion - v1.0.2 - Flexible AngularJS typeahead / autocomplete /
 * suggestion / predictive search directive
 *
 * @author <NAME> <<EMAIL>>
 */
(function(angular) {
  'use strict';

  angular
    .module('ng-suggestion', ['ng-dropdown'])
    .service('SuggestionService', [
      'DropdownService',
      function(DropdownService) {

        this.inputs = [];
        this.deleteHandlers = {};

        this.responseHandler = function(input) {
          return (response) => {
            input.loading = false;
            input.oldParams = input.params;
            if (response) {
              DropdownService.open(input.dropdown.id);
              if (input.responseProperty &&
                  response[input.responseProperty] &&
                  Array.isArray(response[input.responseProperty]) &&
                  response[input.responseProperty].length > 0) {
                input.options = response[input.responseProperty];
              } else if (Array.isArray(response) && response.length > 0) {
                input.options = response;
              } else {
                input.options = false;
              }
            } else {
              input.options = false;
            }
          };
        };

        this.keyUpHandler = function(input) {
          return ($event) => {
            if ($event.keyCode === 8 || $event.keyCode === 46) { // Backspace
              if (this.deleteHandlers[input.id]) {               // or Delete
                this.deleteHandlers[input.id]($event);
              }
            }

            if ($event.keyCode === 27) { // Esc or Tab
              input.element[0].blur();
            } else if (!input.model) {
              DropdownService.close(input.dropdown.id);
            } else if (input.oldParams !== input.params &&
              [9, 27, 40, 38, 13].indexOf($event.keyCode) === -1) {
              input.loading = true;
              if (input.responseProperty) {
                input.resource.get(input.params, this.responseHandler(input));
              } else {
                input.resource.query(input.params, this.responseHandler(input));
              }
            }
          };
        };

        this.keydownHandler = function(input) {
          return ($event) => {
            var currentOption = input.dropdown.currentOption;
            var freeText = input.freeText;
            var enterAction = input.enterAction;
            if ($event.keyCode === 13 && ((currentOption && !freeText) || freeText)) { // Enter
              input.dropdown.disableClick = false;
              if (enterAction) {
                enterAction();
              }
            }
          };
        };

        this.focusHandler = function(input) {
          return () => {
            input.dropdown.disableClick = true;
            if (input.model) {
              DropdownService.open(input.dropdown.id);
            }
          };
        };

        this.blurHandler = function(input) {
          return () => {
            if (!input.dropdown.isInsideMenu) {
              DropdownService.close(input.dropdown.id);
            } else {
              input.dropdown.disableClick = false;
            }
          };
        };

      }
    ])
    .directive('suggestion', [
      '$resource',
      'SuggestionService',
      function($resource, SuggestionService) {
        return {
          restrict: 'A',
          scope: {
            suggestion: '=?',
            model: '=suggestionModel',
            url: '=suggestionUrl',
            params: '=suggestionParams',
            dropdown: '=suggestionDropdown',
            freeText: '=suggestionFreeText',
            enterAction: '=suggestionEnterAction',
            responseProperty: '@?suggestionResponseProperty'
          },
          link: function($scope, $element) {
            var input = {
{'fraction_non_alphanumeric': 0.12668355780770768, 'fraction_numerical': 0.0061341512201626884, 'mean_word_length': 1.494180246092451, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5865683', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1891, 'n_words': 338}