<commit_before>App.Map.Actions.Search = function() {
  App.Map.Actions.Action.apply(this, arguments);
  this.container = $('#search');
  this.initViewModel();
  this.ui = this.viewModel.ui;
 };

App.inherits(App.Map.Actions.Search, App.Map.Actions.Action);

App.Map.Actions.Search.prototype.initViewModel = function() {
  this.viewModel = new App.ViewModels.Search(this.container);
  ko.applyBindings(this.viewModel, this.container[0]);
  this.viewModel.rendered();
};

App.Map.Actions.Search.prototype.execute = function() {
  
  var input = this.ui.field[0];
  var map = App.Map.instance();
  var autocomplete = new google.maps.places.Autocomplete(input);

  autocomplete.bindTo('bounds', map);

  var infowindow = new google.maps.InfoWindow();
  var marker = new google.maps.Marker({
    map: map
  });

  google.maps.event.addListener(autocomplete, 'place_changed', function() {

    infowindow.close();
    marker.setVisible(false);

    var place = autocomplete.getPlace();
    if (!place.geometry) {
      // Inform the user that the place was not found and return.
      input.className = 'notfound';
      return;
    }

    // If the place has a geometry, then present it on a map.
    if (place.geometry.viewport) {
      map.fitBounds(place.geometry.viewport);
    } else {
      map.setCenter(place.geometry.location);
      map.setZoom(17);  // Why 17? Because it looks good.
    }
    var image = new google.maps.MarkerImage(
        place.icon,
        new google.maps.Size(71, 71),
        new google.maps.Point(0, 0),
        new google.maps.Point(17, 34),
        new google.maps.Size(35, 35));
    marker.setIcon(image);
    marker.setPosition(place.geometry.location);

    var address = '';
    if (place.address_components) {
      address = [
        (place.address_components[0] && place.address_components[0].short_name || ''),
        (place.address_components[1] && place.address_components[1].short_name || ''),
        (place.address_components[2] && place.address_components[2].short_name || '')
      ].join(' ');
    }

    infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
    infowindow.open(map, marker);
  });

  this.ui.show();
};

App.Map.Actions.Search.prototype.reset = function() {
  App.Map.Actions.Action.prototype.reset.apply(this, arguments);
  this.ui.reset();
}<commit_msg>Switched to using bootstrap typeahed instead of using googles autocomplete widget<commit_after>App.Map.Actions.Search = function() {
  App.Map.Actions.Action.apply(this, arguments);
  this.container = $('#search');
  this.initViewModel();
  this.ui = this.viewModel.ui;
 };

App.inherits(App.Map.Actions.Search, App.Map.Actions.Action);

App.Map.Actions.Search.prototype.initViewModel = function() {
  this.viewModel = new App.ViewModels.Search(this.container);
  ko.applyBindings(this.viewModel, this.container[0]);
  this.viewModel.rendered();
};

App.Map.Actions.Search.prototype.execute = function() {

  this.ui.show();
  
  var service = new google.maps.places.AutocompleteService();
  var geocoder = new google.maps.Geocoder();
  var map = App.Map.instance();

  $(this.ui.field).typeahead({
    source: function(query, process) {
      service.getPlacePredictions({ input: query }, function(predictions, status) {
        if (status != google.maps.places.PlacesServiceStatus.OK) {
          console.log(status);
          return;
        }
        process($.map(predictions, function(prediction) {
          return prediction.description;
        }));
      });
    },
    updater: function (item) {
      geocoder.geocode({ address: item }, function(results, status) {
        if (status != google.maps.GeocoderStatus.OK) {
          alert('Cannot find address');
          return;
        }
        map.setCenter(results[0].geometry.location);
        map.setZoom(12); 
      });
      return item;
    }
  });
};

App.Map.Actions.Search.prototype.reset = function() {
  App.Map.Actions.Action.prototype.reset.apply(this, arguments);
  this.ui.reset();
}
{'fraction_non_alphanumeric': 0.15388446215139442, 'fraction_numerical': 0.007470119521912351, 'mean_word_length': 3.228421052631579, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '11027', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1243, 'n_words': 219}