{"size": 2966, "ext": "js", "max_stars_repo_path": "src/assets/js/search.js", "max_stars_repo_name": "admin-ch/styleguide", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/assets/js/search.js", "max_issues_repo_name": "admin-ch/styleguide", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/assets/js/search.js", "max_forks_repo_name": "admin-ch/styleguide", "max_forks_repo_forks_event_min_datetime": "2022-01-10T13:21:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-10T13:21:46.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 27.9811320755, "max_line_length": 79, "alphanum_fraction": 0.5053944707}
(function($) {
  'use strict';

  var datasets = [];
  $('.dropdown.yamm-fw').each(function() {
    var title = $('.dropdown-toggle', $(this)).html();
    var links = $('.dropdown-menu li a', $(this));
    var suggestions = [];
    links.each(function() {
        suggestions.push({
            title: $(this).html(),
            link: $(this).attr('href')
        });
    });
    if (!suggestions.length) {
      return;
    }
    var engine = new Bloodhound({
      initialize: true,
      local: suggestions,
      identify: function(obj) {
        return obj.link;
      },
      datumTokenizer: Bloodhound.tokenizers.obj.whitespace('title'),
      queryTokenizer: Bloodhound.tokenizers.whitespace
    });
    datasets.push({
      display: 'title',
      source: engine,
      templates: {
        empty: function() {
          return [
            '<li><h3>',
              title,
            '</h3></li>',
            '<li>',
              window.translations['global-search']['nothing-found'],
            '</li>',
          ].join('');
        },
        header: function() {
          return [
            '<li><h3>',
              title,
            '</h3></li>'
          ].join('');
        },
        dataset: '<ul><ul>',
        suggestion: function (data) {
          return '<li><a href="' + data.link + '">' + data.title + '</a></li>';
        }
      }
    });
  });

  function initTypeahead(element) {
    $('.search-input', element).typeahead({
      highlight: true,
      menu: $('.search-results .search-results-list', element),
      classNames: {
        suggestion: '',
        cursor: 'active'
      }
    }, datasets)
    .on('typeahead:selected', function (event, selection) {
  		event.preventDefault();
      $(this).typeahead('val', '')
        .closest('.global-search').removeClass('has-input');
  		window.location.replace(selection.link);
  	})
    .on('typeahead:open', function() {
      $(this).closest('.global-search').addClass('focused');
      console.log($(this).typeahead('val'));
    })
    .on('typeahead:close', function () {
      $(this).closest('.global-search').removeClass('focused');
    })
    .on('keyup', function (event) {
      if (event.keyCode === 27) { // ESC
        $(this).closest('form').trigger('reset');
      } else if ($(this).typeahead('val')) {
          $(this).closest('.global-search').addClass('has-input');
      } else {
        $(this).closest('.global-search').removeClass('has-input');
  		}
  	});

    $('form', element)
      .on('submit', function() {
        return false;
      })
      .on('reset', function() {
        $('.search-input', this).blur().typeahead('val', '');
        $(this).closest('.global-search').removeClass('has-input');
      });

    $('.search-reset', element).on('click', function() {
      $(this).closest('form').trigger('reset');
    });
  }

  initTypeahead($('.global-search-standard'));
  initTypeahead($('.global-search-mobile'));

})(jQuery);
