<commit_before>// see: http://stackoverflow.com/questions/1909441/jquery-keyup-delay
var delay = (function(){
  var timer = 0;
  return function(callback, ms){
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
  };
})();

Meteor.startup(function () {
  Template[getTemplate('search')].helpers({
    canSearch: function () {
      return canView(Meteor.user());
    },
    searchQuery: function () {
      return Session.get("searchQuery");
    },
    searchQueryEmpty: function () {
      return !!Session.get("searchQuery") ? '' : 'empty';
    }
  });

  Template[getTemplate('search')].events({
    'keyup, search .search-field': function(e){
      e.preventDefault();
      var val = $(e.target).val(),
          $search = $('.search'); 
      if(val==''){
        // if search field is empty, just do nothing and show an empty template 
        $search.addClass('empty');
        Session.set('searchQuery', '');
        Router.go('/search', null, {replaceState: true});
      }else{
        // if search field is not empty, add a delay to avoid firing new searches for every keystroke 
        delay(function(){
          Session.set('searchQuery', val);
          $search.removeClass('empty');

          // Update the querystring.
          var opts = {query: 'q=' + encodeURIComponent(val)};
          // if we're already on the search page, do a replaceState. Otherwise,
          // just use the pushState default.
          if(getCurrentRoute().indexOf('/search') === 0) {
            opts.replaceState = true;
          }
          Router.go('search', null, opts);

        }, 700 );
      }<commit_msg>Make search selector more selective<commit_after>// see: http://stackoverflow.com/questions/1909441/jquery-keyup-delay
var delay = (function(){
  var timer = 0;
  return function(callback, ms){
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
  };
})();

Meteor.startup(function () {
  Template[getTemplate('search')].helpers({
    canSearch: function () {
      return canView(Meteor.user());
    },
    searchQuery: function () {
      return Session.get("searchQuery");
    },
    searchQueryEmpty: function () {
      return !!Session.get("searchQuery") ? '' : 'empty';
    }
  });

  Template[getTemplate('search')].events({
    'keyup .search-field, search .search-field': function(e){
      e.preventDefault();
      var val = $(e.target).val(),
          $search = $('.search'); 
      if(val==''){
        // if search field is empty, just do nothing and show an empty template 
        $search.addClass('empty');
        Session.set('searchQuery', '');
        Router.go('/search', null, {replaceState: true});
      }else{
        // if search field is not empty, add a delay to avoid firing new searches for every keystroke 
        delay(function(){
          Session.set('searchQuery', val);
          $search.removeClass('empty');

          // Update the querystring.
          var opts = {query: 'q=' + encodeURIComponent(val)};
          // if we're already on the search page, do a replaceState. Otherwise,
          // just use the pushState default.
          if(getCurrentRoute().indexOf('/search') === 0) {
            opts.replaceState = true;
          }
          Router.go('search', null, opts);

        }, 700 );
      }
{'fraction_non_alphanumeric': 0.15613608748481167, 'fraction_numerical': 0.007290400972053463, 'mean_word_length': 2.480972515856237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7145464', 'n_tokens_mistral': 952, 'n_tokens_neox': 911, 'n_words': 239}