$(document).ready(function() {
  var supervisor_provider = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: '/employees?q=%QUERY'
  });

  supervisor_provider.initialize();

  $('.typeahead-supervisor').typeahead(null, {
    name: 'supervisor',
    displayKey: 'value',
    source: supervisor_provider.ttAdapter(),
    templates: {
      empty: [
      '<div class="empty-message">',
      $.i18n._('notice_supervisor_not_found'),
      '</div>'
      ].join('\n'),
      suggestion: Handlebars.compile([
        '<p class="element-data">{{value}}</p>',
        '<p class="academy-unit">{{academy_unit}}</p>'
        ].join(''))
    }
  }).on('typeahead:selected', function(event, datum) {
    $(event.target).closest("div").children().last().val(datum.id);
  });
  $('.typeahead.input-sm').siblings('input.tt-hint').addClass('hint-small');
  $('.typeahead.input-lg').siblings('input.tt-hint').addClass('hint-large');

});
var supervisor_autocomplete = function() {
  var supervisor_provider = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: '/employees?q=%QUERY'
  });

  supervisor_provider.initialize();

  $('.typeahead-supervisor').typeahead(null, {
    name: 'supervisor',
    displayKey: 'value',
    source: supervisor_provider.ttAdapter(),
    templates: {
      empty: [
      '<div class="empty-message">',
      $.i18n._('notice_supervisor_not_found'),
      '</div>'
      ].join('\n'),
      suggestion: Handlebars.compile([
        '<p class="element-data">{{value}}</p>',
        '<p class="academy-unit">{{academy_unit}}</p>'
        ].join(''))
    }
  }).on('typeahead:selected', function(event, datum) {
    $(event.target).closest("div").children().last().val(datum.id);
  });
  $('.typeahead.input-sm').siblings('input.tt-hint').addClass('hint-small');
  $('.typeahead.input-lg').siblings('input.tt-hint').addClass('hint-large');
};

$(document).ready(function() {
  supervisor_autocomplete();
});
Move supervisor autocomplete into function
Move supervisor autocomplete into function

Change-Id: Iebcd27893f1801084ab8b39753b9c779bab16ead
