<commit_before>Darkswarm.directive 'mapSearch', ($timeout) ->
  # Install a basic search field in a map
  restrict: 'E'
  require: '^googleMap'
  replace: true
  template: '<input id="pac-input" placeholder="' + t('location_placeholder') + '"></input>'
  scope: {}
  link: (scope, elem, attrs, ctrl) ->
    $timeout =>
      map = ctrl.getMap()

      searchBox = scope.createSearchBox map
      scope.bindSearchResponse map, searchBox
      scope.biasResults map, searchBox


    scope.createSearchBox = (map) ->
      input = document.getElementById("pac-input")
      map.controls[google.maps.ControlPosition.TOP_LEFT].push input
      return new google.maps.places.SearchBox(input)

    scope.bindSearchResponse = (map, searchBox) ->
      google.maps.event.addListener searchBox, "places_changed", =>
        scope.showSearchResult map, searchBox

    scope.showSearchResult = (map, searchBox) ->
      places = searchBox.getPlaces()
      for place in places when place.geometry.viewport?
        map.fitBounds place.geometry.viewport
        scope.$apply ->
          model.$setViewValue elem.val()

    # Bias the SearchBox results towards places that are within the bounds of the
    # current map's viewport.
    scope.biasResults = (map, searchBox) ->
      google.maps.event.addListener map, "bounds_changed", ->
        bounds = map.getBounds()
        searchBox.setBounds bounds<commit_msg>When query changed (typing or autocomplete), update URL. When page loads, perform query search.<commit_after>Darkswarm.directive 'mapSearch', ($timeout, Search) ->
  # Install a basic search field in a map
  restrict: 'E'
  require: ['^googleMap', 'ngModel']
  replace: true
  template: '<input id="pac-input" ng-model="query" placeholder="' + t('location_placeholder') + '"></input>'
  scope: {}

  controller: ($scope) ->
    $scope.query = Search.search()

    $scope.$watch 'query', (query) ->
      Search.search query


  link: (scope, elem, attrs, ctrls) ->
    [ctrl, model] = ctrls
    scope.input = document.getElementById("pac-input")

    $timeout =>
      map = ctrl.getMap()

      searchBox = scope.createSearchBox map
      scope.bindSearchResponse map, searchBox
      scope.biasResults map, searchBox
      scope.performUrlSearch map

    scope.createSearchBox = (map) ->
      map.controls[google.maps.ControlPosition.TOP_LEFT].push scope.input
      return new google.maps.places.SearchBox(scope.input)

    scope.bindSearchResponse = (map, searchBox) ->
      google.maps.event.addListener searchBox, "places_changed", =>
        scope.showSearchResult map, searchBox

    scope.showSearchResult = (map, searchBox) ->
      places = searchBox.getPlaces()
      for place in places when place.geometry.viewport?
        map.fitBounds place.geometry.viewport
        scope.$apply ->
          model.$setViewValue elem.val()

    # When the map loads, and we have a search from ?query, perform that search
    scope.performUrlSearch = (map) ->
      google.maps.event.addListener map, "tilesloaded", =>
        google.maps.event.trigger(scope.input, 'focus');
        google.maps.event.trigger(scope.input, 'keydown', {keyCode: 13});

    # Bias the SearchBox results towards places that are within the bounds of the
    # current map's viewport.
    scope.biasResults = (map, searchBox) ->
      google.maps.event.addListener map, "bounds_changed", ->
        bounds = map.getBounds()
        searchBox.setBounds bounds
{'fraction_non_alphanumeric': 0.12027890761185357, 'fraction_numerical': 0.0005810575246949448, 'mean_word_length': 3.183475091130012, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, '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': '677795', 'n_tokens_mistral': 1006, 'n_tokens_neox': 977, 'n_words': 256}