<commit_before>var controlsModule = (function(window, $) {

    /*Global variables within the module scope*/
    var _controlBarContainer;
    var _controlBarLowerContainer;
    var _table;
    var _options = {
        "startDate": null,
        "endDate": null
    };

    /**
     * @param {object} domContainer
     */
    function _init(domContainer, domContainer2) {
        if (!!domContainer) {
            _controlBarContainer = domContainer;
            _setDataUpdated();
            _setDraggingMouse();
            _setInputAddress();
            _setSlider();
            _setDateRange();
        } else {
            console.log("Upper controls container doesn't exist"); //Error
        }

        if (!!domContainer2) {
            _controlBarLowerContainer = domContainer2;

            _table = _controlBarLowerContainer.find('#example').DataTable({
                "ajax": {
                    "url": "empty.json",
                    "dataSrc": ""
                },
                "dom": '<"table-buttons"<"table-buttons"Bf>l>t<"table-buttons"ip>',
                "oLanguage": {
                   "sSearch": "Filter results:"
                 },
                "buttons": [{ extend: 'colvis', text: 'Select Columns'}],
                "fixedHeader": {
                    header: true,
                    footer: true
                },
                "columns": [{
                  "data": "incidntnum",
                  "title": "Incident#",
                  "name": "incidntnum",
                }, {
                  "data": "date",
                  "title": "Date",
                  "name": "date",
                  "render": function(data, type, row, meta) {
                    return moment(data).format('l')
                  },
                  "visible": false
                }, {
                  "data": "time",
                  "title": "Time",
                  "name": "time",
                  "visible": false
                }, {
                  "data": "address",
                  "title": "Address",
                  "name": "address",
                  "visible": false
                }, {
                  "data": "pddistrict",
                  "title": "District",
                  "name": "pddistrict",
                  "visible": false
                }, {
                  "className": "mobile",
                  "data": "category",
                  "title": "Category",
                  "name": "category",
                }, {
                  "data": "descript",
                  "title": "Description",
                  "name": "descript",
                }, {
                  "className": "mobile tablet",
                  "data": "resolution",
                  "title": "Resolution",
                  "name": "resolution",
                }],
                "pageLength": 50,
                "footerCallback": function(tfoot, data, start, end, display) {
                  var dupHeaderRow = $(this.api().table().header()).children('tr:first').clone()
                  // $(tfoot).html(dupHeaderRow.html());
                }
            });
        } else {
            console.log("Lower controls container doesn't exist");
        }
    }


    function _setInputAddress() {
        $('.typeahead').typeahead({
            source: function (query, process) {
              addresses = [];
              resourcesModule.getAutoSuggestionsFromService(query, function(data){
                  $.each(data, function (i, address) {
                      addresses.push(address.text);
                  });
                  process(addresses);
              });
            },
            updater: function(item) {
                clickedIndex = $('.typeahead').find('.active').index();
                var acFeatures = resourcesModule.getLatestAutocompleteFeatures();

                //Use the map module to change the user pin's location
                mapModule.plotUserLocation(acFeatures[clickedIndex]);
                mapModule.centerMapOnLocation(acFeatures[clickedIndex]);

                //Hide the suggestions list
                $(this).parent().hide();
                controlsModule.searchCrime(mapModule.getUserLocation());
                return item;
            },
            minLength: 4, items: 10
        });
    }

    function _setSlider() {
        _controlBarContainer.find('#range-slider').noUiSlider({
            start: [urlSearch.getRadius("ft")],
            step: 1,
            connect: 'lower',
            range: {
                'min': [0],
                'max': [5280]
            }
        });
        _controlBarContainer.find('#range-slider').on({
            "slide": function() {<commit_msg>Enhance search quality and highlight on an input address.<commit_after>var controlsModule = (function(window, $) {

    /*Global variables within the module scope*/
    var _controlBarContainer;
    var _controlBarLowerContainer;
    var _table;
    var _options = {
        "startDate": null,
        "endDate": null
    };

    /**
     * @param {object} domContainer
     */
    function _init(domContainer, domContainer2) {
        if (!!domContainer) {
            _controlBarContainer = domContainer;
            _setDataUpdated();
            _setDraggingMouse();
            _setInputAddress();
            _setSlider();
            _setDateRange();
        } else {
            console.log("Upper controls container doesn't exist"); //Error
        }

        if (!!domContainer2) {
            _controlBarLowerContainer = domContainer2;

            _table = _controlBarLowerContainer.find('#example').DataTable({
                "ajax": {
                    "url": "empty.json",
                    "dataSrc": ""
                },
                "dom": '<"table-buttons"<"table-buttons"Bf>l>t<"table-buttons"ip>',
                "oLanguage": {
                   "sSearch": "Filter results:"
                 },
                "buttons": [{ extend: 'colvis', text: 'Select Columns'}],
                "fixedHeader": {
                    header: true,
                    footer: true
                },
                "columns": [{
                  "data": "incidntnum",
                  "title": "Incident#",
                  "name": "incidntnum",
                }, {
                  "data": "date",
                  "title": "Date",
                  "name": "date",
                  "render": function(data, type, row, meta) {
                    return moment(data).format('l')
                  },
                  "visible": false
                }, {
                  "data": "time",
                  "title": "Time",
                  "name": "time",
                  "visible": false
                }, {
                  "data": "address",
                  "title": "Address",
                  "name": "address",
                  "visible": false
                }, {
                  "data": "pddistrict",
                  "title": "District",
                  "name": "pddistrict",
                  "visible": false
                }, {
                  "className": "mobile",
                  "data": "category",
                  "title": "Category",
                  "name": "category",
                }, {
                  "data": "descript",
                  "title": "Description",
                  "name": "descript",
                }, {
                  "className": "mobile tablet",
                  "data": "resolution",
                  "title": "Resolution",
                  "name": "resolution",
                }],
                "pageLength": 50,
                "footerCallback": function(tfoot, data, start, end, display) {
                  var dupHeaderRow = $(this.api().table().header()).children('tr:first').clone()
                  // $(tfoot).html(dupHeaderRow.html());
                }
            });
        } else {
            console.log("Lower controls container doesn't exist");
        }
    }


    function _setInputAddress() {
        $('.typeahead').typeahead({
            source: function (query, process) {
              addresses = [];
              resourcesModule.getAutoSuggestionsFromService(query, function(data){
                  $.each(data, function (i, address) {
                      addresses.push(address.text);
                  });
                  process(addresses);
              });
            },
            updater: function(item) {
                clickedIndex = $('.typeahead').find('.active').index();
                var acFeatures = resourcesModule.getLatestAutocompleteFeatures();

                //Use the map module to change the user pin's location
                mapModule.plotUserLocation(acFeatures[clickedIndex]);
                mapModule.centerMapOnLocation(acFeatures[clickedIndex]);

                //Hide the suggestions list
                $(this).parent().hide();
                controlsModule.searchCrime(mapModule.getUserLocation());
                return item;
            },
            matcher: function (item) {
                return true; //set candidate list of addresses at "typehead"
            },
            highlighter: function(item) {
                var queries = $.grep(this.query.split(" "), function(x){return x;}); //remove empty string
                var ii=0, back_ii=0;
                var res = "";

                queries.forEach(function(a_query) {
                    ii = item.toLowerCase().indexOf(a_query.toLowerCase(), back_ii); //ii: index of item
                    if (ii < 0) { return; }
                    var a_str = item.substr(ii, a_query.length);
                    var highlight_str = '<strong>' + item.substr(ii, a_str.length) + '</strong>';
                    res += item.substr(back_ii, ii - back_ii) + highlight_str;
                    back_ii = ii + a_str.length;
                });
                res += item.substr(back_ii, item.length - ii);
                return res;
            },
            minLength: 4, items: 10
        });
    }

    function _setSlider() {
        _controlBarContainer.find('#range-slider').noUiSlider({
            start: [urlSearch.getRadius("ft")],
            step: 1,
            connect: 'lower',
            range: {
                'min': [0],
                'max': [5280]
            }
        });
        _controlBarContainer.find('#range-slider').on({
            "slide": function() {
{'fraction_non_alphanumeric': 0.13165934695436318, 'fraction_numerical': 0.002959709757494749, 'mean_word_length': 1.2435210965945598, 'pattern_counts': {'":': 90, '<': 12, '<?xml version=': 0, '>': 11, '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': '5660100', 'n_tokens_mistral': 2680, 'n_tokens_neox': 2478, 'n_words': 513}