<commit_before>/**
 * View responsible for exposing the permit filters to the user.
 */
define(
    ["backbone", "underscore", "jquery", "refLocation", "collection/regions",
     "utils", "api/arcgis", "api/places", "appState", "config"],

    function(B, _, $, refLocation, regions, $u, arcgis, places, appState, config) {
        "use strict";

        return B.View.extend({
            el: document.body,

            initialize: function(options) {
                this.mapView = options.mapView;
                this.listenTo(refLocation, "change:radius",
                              this.updateRadius)
                    .listenTo(refLocation, "change:geolocating",
                              this.toggleGeolocating)
                    .listenTo(refLocation, "change:address",
                              this.maybeUpdateAddress);

                this.buildRegionSelection();

                appState.onStateKeyChange("showmenu", function(show, oldValue) {
                    if (_.isString(show))
                        this.toggleSideMenu(show == "1");
                }, this, true);

                appState.onStateKeyChange(
                    "fa",
                    this.showAttributeFilters, this);

                $("#filter-text").val(appState.getKey("f.text"));

                appState.onStateKeyChange("f", function(filters) {
                    this.onFiltersChange(filters);
                }, this);

                // Google Places Autocomplete setup:
                var self = this,
                    placesOptions = {types: ["geocode"]},
                    input = $("#ref-address-form input")[0];

                places.setup(input, placesOptions)
                    .done(function(ac) {
                        self.placesSetup(ac, input);
                        $(input).keypress(function(e) {
                            if (e.which == 13) {
                                e.preventDefault();
                                input.blur();
                            }
                        });
                    });
            },

            placesSetup: function(ac, input) {
                var self = this;

                google.maps.event.addListener(ac, "place_changed", function() {
                    self.onPlaceChanged(ac, input);
                });

                this.listenTo(
                    regions, "regionBounds",
                    function(bounds) {
                        var gbounds = $u.gBounds(bounds);
                        ac.setBounds(gbounds);
                    });
            },

            toggleSideMenu: function(show) {
                $("#show-filters-button").toggle(!show);
                $("#hide-filters-button").toggle(show);
                $("#side-menu")
                    .toggleClass("expanded", show)
                    .toggleClass("collapsed", !show);

                if (show) {
                    var self = this;
                    if (!this._hideHandler) {
                        var handler = _.bind(function(e) {
                            if (!$(e.target).closest("#map-container,#side-menu").length) {
                                appState.setHashKey("showmenu", "0", true);
                                $(document.body).unbind("click", handler);
                                delete self._hideHandler;
                            }
                        }, this);
                        $(document.body).click(handler);
                        this._hideHandler = null;
                    }
                }
            },

            events: {
                //"submit #ref-address-form": "submitAddress",
                "focus #ref-address-form": "removeGuessClass",
                "click #geolocate": "geolocate",
                "click #reset": "clearInputs",
                "click #reset-filter-bounds": "clearFilterBounds",
                // Should this be preserved for other methods of input?
                // "change #filter-text": "filterText",
                "keyup #filter-text": "filterText",
                "search #filter-text": "filterText",<commit_msg>Press ESC during address search/completion to exit<commit_after>/**
 * View responsible for exposing the permit filters to the user.
 */
define(
    ["backbone", "underscore", "jquery", "refLocation", "collection/regions",
     "utils", "api/arcgis", "api/places", "appState", "config"],

    function(B, _, $, refLocation, regions, $u, arcgis, places, appState, config) {
        "use strict";

        return B.View.extend({
            el: document.body,

            initialize: function(options) {
                this.mapView = options.mapView;
                this.listenTo(refLocation, "change:radius",
                              this.updateRadius)
                    .listenTo(refLocation, "change:geolocating",
                              this.toggleGeolocating)
                    .listenTo(refLocation, "change:address",
                              this.maybeUpdateAddress);

                this.buildRegionSelection();

                /**
                   Filters are all stored in the app state, which is 'persisted'
                   in the location hash. Changes to filters must therefore pass
                   through appState first. Here, we subscribe to filter changes
                   made on appState and update the GUI appropriately.
                 */
                appState.onStateKeyChange("showmenu", function(show, oldValue) {
                    if (_.isString(show))
                        this.toggleFiltersMenu(show == "1");
                }, this, true);

                appState.onStateKeyChange(
                    "fa",
                    this.showAttributeFilters, this);

                $("#filter-text").val(appState.getKey("f.text"));

                appState.onStateKeyChange("f", function(filters) {
                    this.onFiltersChange(filters);
                }, this);

                // Google Places Autocomplete setup:
                var self = this,
                    placesOptions = {types: ["geocode"]},
                    input = $("#ref-address-form input")[0];

                places.setup(input, placesOptions)
                    .done(function(ac) {
                        self.placesSetup(ac, input);
                        $(input).keypress(function(e) {
                            if (e.which === 13) {
                                e.preventDefault();
                                input.blur();
                            }
                        }).keyup(function(e) {
                            if (e.which === 27) {
                                e.preventDefault();
                                input.blur();
                            }
                        });
                    });
            },

            /**
               Callback to complete the setup of the Google Places API once it
               has fully loaded.
             */
            placesSetup: function(ac, input) {
                var self = this;

                google.maps.event.addListener(ac, "place_changed", function() {
                    self.onPlaceChanged(ac, input);
                });

                // Restrict the Places query to the bounds of the currently
                // active region(s).
                this.listenTo(
                    regions, "regionBounds",
                    function(bounds) {
                        var gbounds = $u.gBounds(bounds);
                        ac.setBounds(gbounds);
                    });
            },

            toggleFiltersMenu: function(show) {
                $("#show-filters-button").toggle(!show);
                $("#hide-filters-button").toggle(show);
                $("#side-menu")
                    .toggleClass("expanded", show)
                    .toggleClass("collapsed", !show);

                if (show) {
                    var self = this;
                    if (!this._hideHandler) {
                        var handler = _.bind(function(e) {
                            if (!$(e.target).closest("#map-container,#side-menu").length) {
                                appState.setHashKey("showmenu", "0", true);
                                $(document.body).unbind("click", handler);
                                delete self._hideHandler;
                            }
                        }, this);
                        $(document.body).click(handler);
                        this._hideHandler = null;
                    }
                }
            },

            // NOTE Many of these filters do not appear in the UI at this time.
            // They are preserve here for possible later use, since most or all
            // generate the correct Proposal query and have backend support.
            events: {
                //"submit #ref-address-form": "submitAddress",
                "focus #ref-address-form": "removeGuessClass",
                "click #geolocate": "geolocate",
                "click #reset": "clearInputs",
                "click #reset-filter-bounds": "clearFilterBounds",
                // Should this be preserved for other methods of input?
                // "change #filter-text": "filterText",
                "keyup #filter-text": "filterText",
                "search #filter-text": "filterText",
{'fraction_non_alphanumeric': 0.11318143100511073, 'fraction_numerical': 0.0012776831345826234, 'mean_word_length': 1.15633608815427, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, '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': '5305176', 'n_tokens_mistral': 2272, 'n_tokens_neox': 2089, 'n_words': 465}