<commit_before>//Free up the $ for jQuery, just in case
(function ($) {
   $.fn.gnsearch = function () {
      /**
       * @var Object reference the search box more easily within methods
       */
      var $input = this;

      /**
       * @var Object container for the results (not the input itself)
       */
      $input.container = $("#" + $input.attr('data-container'));

      /**
       * @var int maximum number of results to display at once
       */
      $input.results = $input.attr('data-results');

      /**
       * @var Object throbber image; this not only makes it easy to reference, but also preloads it
       * TODO do not use a specific path
       */
      $input.throbber = $("<img>",
         {
            src: '/wp-content/plugins/gn-search/media/throbber.gif',
            alt: 'Please Wait...',
            'class': 'gn-throbber'
         }
      );

      /**
       * @var current ajax request
       * Initialize this with the abort method so keyup does not freak out
       */
      $input.jqxhr = {abort: function () { $.noop(); }};

      //Nothing to put results in, so don't show the input either
      if (!$input.container || !$input.container.length) {
         return;
      }

      $input.show();

      $input.on('keyup', function () {
         //Cancel the last request so as not to give the server a little break
         $input.jqxhr.abort();

         if ($input.val().length >= $input.attr('data-chars')) {
            $input.initSearch($input.val());
         }
      });

      $input.initSearch = function (term) {
         $input.container
            .hide()
            .empty()
            .after($input.throbber)
         ;

         $input.jqxhr = $.getJSON(GnSearch.ajaxurl, {term: term, action: 'gnsearch', limit: $input.attr('data-limit')})
            .done($input.success)
            .fail($input.failure)
            .always($input.always)
         ;
      };

      /**#@+
       * Handle Ajax results
       */
      $input.success = function (json) {
         if (!json.status) {
            $input.failure();
         }
         else if (json.status == 'success') {
            $input.displayResults(json.response);
         }
         else if (json.status == 'error') {
            $input.displayError(json.msg);
         }
         //Unknown response, so display it as a normal error
         else {
            $input.failure();
         }
      };

      $input.failure = function () {
         $input.container.show().html('<span class="gn-search-error">Error trying to get results</span>');
      };

      $input.always = function () {
         $input.throbber.detach();
      }
      /**#@-*/

      /**#@+
       * Update the container based on results
       */
      $input.displayResults = function (news) {
         //TODO if the results are too long for the container, it would be nice to cut them off with a ...
         $.each(news, function (index) {
            //IE really hates 'class' not used in its intended context
            var clss = 'gn-search-result';

            if ($input.results != 0 && index + 1 > $input.results) {
               clss = 'gn-search-result-extra';
            }
            $input.container.append(
               $("<a>", {href: this.url, text: this.title, 'class': clss})
            );
         });
         var $extralinks = $('.gn-search-result-extra', $input.container);
         if ($extralinks.length) {
            $("<div>", {text: 'Show More...', 'class': 'gn-show-extra'})
               .on('click', function () {
                  $(this).hide();
                  $extralinks.css('display', 'block');
               })
               .appendTo($input.container)
            ;
         }
         $input.container.show();
      };

      $input.displayError = function (err) {
         $input.container.show().html('<span class="gn-search-error">' + err + '</span>');
      }
      /**#@-*/
   };

   $(function () {
      //TODO do this separately so we can use a different ID or element
      $("#gn-search").gnsearch();
   });
})(jQuery);
<commit_msg>Minor improvements to JS:<commit_after>//Free up the $ for jQuery, just in case
(function ($) {
   $.fn.gnsearch = function () {
      /**
       * @var Object reference the search box more easily within methods
       */
      var $input = this;

      /**
       * @var Object container for the results (not the input itself)
       */
      $input.container = $("#" + $input.attr('data-container'));
      //Nothing to put results in, so don't show the input either
      if (!$input.container || !$input.container.length) {
         return;
      }

      /**
       * @var int maximum number of results to display at once
       */
      $input.results = $input.attr('data-results');

      /**
       * @var Object throbber image; this not only makes it easy to reference, but also preloads it
       * TODO do not use a specific path
       */
      $input.throbber = $("<img>",
         {
            src: '/wp-content/plugins/gn-search/media/throbber.gif',
            alt: 'Please Wait...',
            'class': 'gn-throbber'
         }
      );

      /**
       * @var current ajax request
       * Initialize this with the abort method so keyup does not freak out
       */
      $input.jqxhr = {abort: function () { $.noop(); }};

      $input.show();

      $input.on('keyup', function () {
         //Cancel the last request to give the server a little break
         $input.jqxhr.abort();

         if ($input.val().length >= $input.attr('data-chars')) {
            $input.initSearch($input.val());
         }
      });

      $input.initSearch = function (term) {
         $input.container
            .hide()
            .empty()
            .after($input.throbber)
         ;

         $input.jqxhr = $.getJSON(GnSearch.ajaxurl, {term: term, action: 'gnsearch', limit: $input.attr('data-limit')})
            .done($input.success)
            .fail($input.failure)
            .always($input.always)
         ;
      };

      /**#@+
       * Handle Ajax results
       */
      $input.success = function (json) {
         if (!json.status) {
            $input.failure();
         }
         else if (json.status == 'success') {
            $input.displayResults(json.response);
         }
         else if (json.status == 'error') {
            $input.displayError(json.msg);
         }
         //Unknown response, so display it as a normal error
         else {
            $input.failure();
         }
      };

      $input.failure = function () {
         $input.container.show().html('<span class="gn-search-error">Error trying to get results</span>');
      };

      $input.always = function () {
         $input.throbber.detach();
      }
      /**#@-*/

      /**#@+
       * Update the container based on results
       */
      $input.displayResults = function (news) {
         //TODO if the results are too long for the container, it would be nice to cut them off with a ...
         $.each(news, function (index) {
            //IE really hates 'class' not used in its intended context
            var clss = 'gn-search-result';

            if ($input.results != 0 && index + 1 > $input.results) {
               clss = 'gn-search-result-extra';
            }
            $input.container.append(
               $("<a>", {href: this.url, text: this.title, 'class': clss})
            );
         });
         var $extralinks = $('.gn-search-result-extra', $input.container);
         if ($extralinks.length) {
            $("<div>", {text: 'Show More...', 'class': 'gn-show-extra'})
               .on('click', function () {
                  $(this).hide();
                  $extralinks.css('display', 'block');
               })
               .appendTo($input.container)
            ;
         }
         $input.container.show();
      };

      $input.displayError = function (err) {
         $input.container.show().html('<span class="gn-search-error">' + err + '</span>');
      }
      /**#@-*/
   };

   $(function () {
      //TODO do this separately so we can use a different ID or element
      $("#gn-search").gnsearch();
   });
})(jQuery);

{'fraction_non_alphanumeric': 0.15626145387904702, 'fraction_numerical': 0.0004886988393402566, 'mean_word_length': 1.6304627249357326, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, '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': '4697241', 'n_tokens_mistral': 2340, 'n_tokens_neox': 2288, 'n_words': 598}