<commit_before>class GoogleMapsAutocompleteInput < SimpleForm::Inputs::StringInput
  include ActionView::Helpers::TagHelper
  def input
    gmap_id = input_html_options.delete(:gmap_id)
    input = @builder.text_field(attribute_name, input_html_options)
    (input + content_tag('script', script_text(gmap_id, input).html_safe)).html_safe
  end

  private

  def script_text(gmap_id, tag)
    "$(document).ready(function(){
      if(typeof google == 'undefined')
        return;
      var selector = '#{gmap_id}';
      if(selector.length > 0){
        selector = '#' + selector;
      }
      window.gmap = new GoogleMap({selector: selector});
      input = $('#{tag}');
      var id = input.attr('id');
      var location = input.val();
      window.googleAutocomplete = new GmapAutocomplete('#' + id, gmap);
      gmap.apply();
      googleAutocomplete.apply();
      if(location.length > 0){
        gmap.setMarker('address', location);
      }
    })"
  end
end<commit_msg>SimpleForm input add apply parameter in order to have ability to not apply googlemaps on input creation. Global autocomplete oject renamed to gmapsAutocomplete.<commit_after>class GoogleMapsAutocompleteInput < SimpleForm::Inputs::StringInput
  include ActionView::Helpers::TagHelper
  def input
    gmap_id = input_html_options.delete(:gmap_id)
    apply = input_html_options.delete(:apply)
    input = @builder.text_field(attribute_name, input_html_options)
    (input + content_tag('script', script_text(gmap_id, input, apply).html_safe)).html_safe
  end

  private

  def script_text(gmap_id, tag, apply = true)
    "$(document).ready(function(){
      if(typeof google == 'undefined')
        return;
      var selector = '#{gmap_id}';
      if(selector.length > 0){
        selector = '#' + selector;
      }
      window.gmap = new GoogleMap({selector: selector});
      input = $('#{tag}');
      var id = input.attr('id');
      var location = input.val();
      window.gmapAutocomplete = new GmapAutocomplete('#' + id, gmap);
      if(#{apply}){
        gmap.apply();
        gmapAutocomplete.apply();
      }
      if(location.length > 0){
        gmap.setMarker('address', location);
      }
    })"
  end
end
{'fraction_non_alphanumeric': 0.13330300272975432, 'fraction_numerical': 0.0018198362147406734, 'mean_word_length': 3.3202357563850686, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4032367', 'n_tokens_mistral': 680, 'n_tokens_neox': 667, 'n_words': 143}