<commit_before>/**
 * script.js
 * HappyOperator.com
 */


// Typeahead
var companies = new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  remote: '/companies/search/%QUERY'
});
companies.initialize();
$('#input-name').typeahead({
  minLength: 1,
  highlight: true,
},
{
  name: 'companies',
  displayKey: 'name',
  source: companies.ttAdapter()
});

// Serialize form for submission as JSON object.
//   Snippet via http://jsfiddle.net/sxGtM/3/
$.fn.serializeObject = function(){
  var o = {};
  var a = this.serializeArray();
  $.each(a, function() {
    if (o[this.name] !== undefined) {
      if (!o[this.name].push) {
          o[this.name] = [o[this.name]];
      }
      o[this.name].push(this.value || '');
    } else {
      o[this.name] = this.value || '';
    }
  });
  return o;
};

$(document).ready(function(){

  // Faster scrolling
  //   via <thecssninja.com/javascript/pointer-events-60fps>.
  var body = document.body, timer;
  window.addEventListener('scroll', function(){
    clearTimeout(timer);
    if(!body.classList.contains('disable-hover'))
      body.classList.add('disable-hover')
    timer = setTimeout(function(){
      body.classList.remove('disable-hover')
    }, 500);
  }, false);

  // Focus forward/back
  $(".form-fields").on("focus", ".text-input", function(){
    var target = $(this).parent('li');
    target
      //.removeClass('hidden')
      .nextAll('li').addClass('hidden');
    $.smoothScroll({
      offset: -focusHeight,
      scrollTarget: target,
      speed: 200
    });
    //delay(200);
    target.addClass('active')
    console.log('focused.');
  });
  $('.form-fields .text-input').on('blur', function(e){
    console.log('.text-input blur: parent removeClass active');
    $(this).parent().removeClass('active');
  });
  $('.form-fields label').on('click', function(e){
    console.log('click will result in focus.');
    $(this).next('.text-input').focus();
  });
  $('.form-fields .next').on('click', function(e){
    console.log('button click will result in focus.');
    $(this).parentsUntil('li.active').first().parent()
      .next('li.hidden .text-input').focus();
  });
  $(document).on('typeahead:closed', function(){
    console.log('typeahead:closed');
    $('li.active').removeClass('active')
      .next('li').find('.text-input').first()
      .focus();
  });
  $('.form-fields .text-input').bind('keydown', function(event){
    if((event.keyCode==9 && event.shiftKey) || event.keyCode==38) {
      // Use [Shift+Tab, Up] to iterate up.
      $(this).parent()
        //.addClass('hidden')
        .prev('li').find('.text-input').first().focus();
      event.preventDefault();
    } else if(event.keyCode==9 || event.keyCode==13 || event.keyCode==40) {
      // Use [Tab, Enter, Down] to iterate down.
      var dataNext = $(this).data('next');
      console.log(dataNext);
      if(!(dataNext=="")) {
        $('li.hidden').first().removeClass('hidden');
        $(dataNext).focus();
      } else {
        $(this).parent().next('li')
          .removeClass('hidden')
          .find('.text-input').first().focus();
      }
      event.preventDefault();
    } 
  });

  // Initialize state
  var focusHeight = $('.form-fields input').first().offset().top;
  console.log('focusHeight = ' + focusHeight);
  $('#input-name').focus();

  // Mask input
  $("[type='tel']").mask("(999) 999-9999", {placeholder: " ", completed: function(){
    $(this).parent().next('li')
      .removeClass('hidden')
      .find('.text-input').first().focus();
  }});

  // Submit data
  $('#submit').on('click', function(e){

    // Build the payload
    var payload = {};<commit_msg>Removes the autoadvance after entering your phone number. That was dumb.<commit_after>/**
 * script.js
 * HappyOperator.com
 */


// Typeahead
var companies = new Bloodhound({
  datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
  queryTokenizer: Bloodhound.tokenizers.whitespace,
  remote: '/companies/search/%QUERY'
});
companies.initialize();
$('#input-name').typeahead({
  minLength: 1,
  highlight: true,
},
{
  name: 'companies',
  displayKey: 'name',
  source: companies.ttAdapter()
});

// Serialize form for submission as JSON object.
//   Snippet via http://jsfiddle.net/sxGtM/3/
$.fn.serializeObject = function(){
  var o = {};
  var a = this.serializeArray();
  $.each(a, function() {
    if (o[this.name] !== undefined) {
      if (!o[this.name].push) {
          o[this.name] = [o[this.name]];
      }
      o[this.name].push(this.value || '');
    } else {
      o[this.name] = this.value || '';
    }
  });
  return o;
};

$(document).ready(function(){

  // Faster scrolling
  //   via <thecssninja.com/javascript/pointer-events-60fps>.
  var body = document.body, timer;
  window.addEventListener('scroll', function(){
    clearTimeout(timer);
    if(!body.classList.contains('disable-hover'))
      body.classList.add('disable-hover')
    timer = setTimeout(function(){
      body.classList.remove('disable-hover')
    }, 500);
  }, false);

  // Focus forward/back
  $(".form-fields").on("focus", ".text-input", function(){
    var target = $(this).parent('li');
    target
      //.removeClass('hidden')
      .nextAll('li').addClass('hidden');
    $.smoothScroll({
      offset: -focusHeight,
      scrollTarget: target,
      speed: 200
    });
    //delay(200);
    target.addClass('active')
    console.log('focused.');
  });
  $('.form-fields .text-input').on('blur', function(e){
    console.log('.text-input blur: parent removeClass active');
    $(this).parent().removeClass('active');
  });
  $('.form-fields label').on('click', function(e){
    console.log('click will result in focus.');
    $(this).next('.text-input').focus();
  });
  $('.form-fields .next').on('click', function(e){
    console.log('button click will result in focus.');
    $(this).parentsUntil('li.active').first().parent()
      .next('li.hidden .text-input').focus();
  });
  $(document).on('typeahead:closed', function(){
    console.log('typeahead:closed');
    $('li.active').removeClass('active')
      .next('li').find('.text-input').first()
      .focus();
  });
  $('.form-fields .text-input').bind('keydown', function(event){
    if((event.keyCode==9 && event.shiftKey) || event.keyCode==38) {
      // Use [Shift+Tab, Up] to iterate up.
      $(this).parent()
        //.addClass('hidden')
        .prev('li').find('.text-input').first().focus();
      event.preventDefault();
    } else if(event.keyCode==9 || event.keyCode==13 || event.keyCode==40) {
      // Use [Tab, Enter, Down] to iterate down.
      var dataNext = $(this).data('next');
      console.log(dataNext);
      if(!(dataNext=="")) {
        $('li.hidden').first().removeClass('hidden');
        $(dataNext).focus();
      } else {
        $(this).parent().next('li')
          .removeClass('hidden')
          .find('.text-input').first().focus();
      }
      event.preventDefault();
    } 
  });

  // Initialize state
  var focusHeight = $('.form-fields input').first().offset().top;
  console.log('focusHeight = ' + focusHeight);
  $('#input-name').focus();

  // Mask input
  $("[type='tel']").mask("(999) 999-9999", {placeholder: " "});

  // Submit data
  $('#submit').on('click', function(e){

    // Build the payload
    var payload = {};
{'fraction_non_alphanumeric': 0.21808799565453557, 'fraction_numerical': 0.00841933731667572, 'mean_word_length': 3.0893947806774014, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2252701', 'n_tokens_mistral': 2394, 'n_tokens_neox': 2331, 'n_words': 407}