<commit_before>
function debounce(func, wait) {
  var timeout;
  return function() {
    var context = this, args = arguments;
    clearTimeout(timeout);
    timeout = setTimeout(function() {
      timeout = null;
      func.apply(context, args);
    }, wait || 300);
  };
};


//--------------------------------------------------------------------------------
// location prompt
//--------------------------------------------------------------------------------

$(function() {
  var locationMarker = $('#request-location');
  var locationOffset = parseInt(locationMarker.data('offset') || 0);

  function checkScroll(e)
  {
    if ($(window).scrollTop() > locationMarker.offset().top - locationOffset) {
      askLocation();
      $(window).off('scroll', checkScroll);
    }
  }

  function askLocation()
  {
    if (!("geolocation" in navigator)) {
      return;
    }

    navigator.geolocation.getCurrentPosition(function(position) {
      // :TODO: call API
      // (position.coords.latitude, position.coords.longitude);
    }, function() {
      // :TODO:
      console.error("Geo fail");
    });
  }

  checkScroll();
  $(window).on('scroll', checkScroll);
});


// ----------------- LEGISLATORS CALL ----------------------------


var legislatorTemplate = $('#legislator-template').html();

// Legislators needs to be brought down dynamically

var legislators = {
  'H6V': {
    name: '<NAME>',
    title: 'Senator',
    image: 'H6V'
  },
  'YE4': {
    name: '<NAME>',
    title: 'Senator',
    image: 'YE4'
  },
  '2L6': {
    name: '<NAME>',
    title: 'Senator',
    image: '2L6'
  }
};

legislators = {};

$.ajax({
  url: "http://legislators-locator.herokuapp.com/",
  jsonp: "callback",
  dataType: "jsonp",
  data: {
      lat: '-27.529993400000002',
      lng: '153.0397888'
  },
  // work with the response
  success: function( response ) {
      console.log( response ); // server response
  }
});

var renderLegislators = function(legislators) {
  _.each(legislators, function (legislator) {
    $('.legislators').append(_.template(legislatorTemplate, legislator));
  })
};

renderLegislators(legislators);

// ----------------- FORM SUBMISSION ----------------------

$('.postcode-lookup').on('submit', function(ev){
  console.log('asd');
  return false;
});

<commit_msg>hookup location response{<commit_after>
function debounce(func, wait) {
  var timeout;
  return function() {
    var context = this, args = arguments;
    clearTimeout(timeout);
    timeout = setTimeout(function() {
      timeout = null;
      func.apply(context, args);
    }, wait || 300);
  };
};


//--------------------------------------------------------------------------------
// location prompt
//--------------------------------------------------------------------------------

$(function() {
  var locationMarker = $('#request-location');
  var locationOffset = parseInt(locationMarker.data('offset') || 0);

  function checkScroll(e)
  {
    if ($(window).scrollTop() > locationMarker.offset().top - locationOffset) {
      askLocation();
      $(window).off('scroll', checkScroll);
    }
  }

  function askLocation()
  {
    if (!("geolocation" in navigator)) {
      return;
    }

    navigator.geolocation.getCurrentPosition(function(position) {
      $.ajax({
        url: "http://legislators-locator.herokuapp.com/",
        jsonp: "callback",
        dataType: "jsonp",
        data: {
          lat: position.coords.latitude,
          lng: position.coords.longitude
        },
        // work with the response
        success: renderLegislators
      });
    }, function() {
      // :TODO:
      console.error("Geo fail");
    });
  }

  checkScroll();
  $(window).on('scroll', checkScroll);
});


// ----------------- LEGISLATORS CALL ----------------------------


var legislatorTemplate = $('#legislator-template').html();

var renderLegislators = function(legislators) {
  _.each(legislators, function (legislator) {
    $('.legislators').append(_.template(legislatorTemplate, legislator));
  })
};

renderLegislators(legislators);

// ----------------- FORM SUBMISSION ----------------------

$('.postcode-lookup').on('submit', function(ev){
  console.log('asd');
  return false;
});


{'fraction_non_alphanumeric': 0.2666349809885932, 'fraction_numerical': 0.010218631178707225, 'mean_word_length': 1.9745583038869259, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '3649271', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1213, 'n_words': 233}