<commit_before>
import Dom_ from '../../utility/dom';
import {utils as utils_} from '../../../core/utils/utils';

//get rid of compiler mess
var dom = Dom_;
var utils = utils_;


var UIControlSearch = function(ui, visible) {
    this.ui = ui;
    this.browser = ui.browser;
    
    var element = this.browser.config.controlSearchElement;
    if (element) {
        if (typeof element === 'string') {
            element = document.getElementById(element);
        }
    }
    
    this.control = this.ui.addControl('search',
      '<div class="vts-search">'
      + '<div class="vts-search-input"><input type="text" id="vts-search-input" autocomplete="off" spellcheck="false" placeholder="Search location..."></div>'      
      + '<div id="vts-search-list" class="vts-search-list"></div>'      
      + '</div>', visible, element);

    this.input = this.control.getElement('vts-search-input');
    
    //this.input.on("change", this.onChange.bind(this));
    this.input.on('input', this.onChange.bind(this));
    this.input.on('keydown', this.onKeyUp.bind(this));
    this.input.on('focus', this.onFocus.bind(this));
    this.input.on('mousedown', this.onDrag2.bind(this));
    this.input.on('mousewheel', this.onDrag.bind(this));

    this.list = this.control.getElement('vts-search-list');
    this.list.on('mousedown', this.onDrag2.bind(this));
    this.list.on('mousewheel', this.onDrag.bind(this));

    this.mapControl = this.ui.getMapControl();
    this.mapElement = this.mapControl.getMapElement();
    this.mapElement.on('mousedown', this.onDrag.bind(this), window);
    this.mapElement.on('mousewheel', this.onDrag.bind(this), window);

    this.ignoreDrag = false; 

    this.urlTemplate = 'https://www.windy.com/search/get/v1.0/{value}?lang=en-US&hash=b0f07fGWSGdsx-l';
    this.data = [];
    this.lastSearch = '';
    this.itemIndex = -1;
    this.searchCounter = 0;
    this.coordsSrs = '+proj=longlat +datum=WGS84 +nodefs';

    this.initialValueUsed = false;

    if (this.browser.config.controlSearchValue) {
        this.initialValueUsed = true;
        this.input.getElement().value = this.browser.config.controlSearchValue;
        this.onChange();
    }
};


UIControlSearch.prototype.processTemplate = function(str, obj) {
    return str.replace(/\{([$a-zA-Z0-9][$a-zA-Z0-9]*)\}/g, function(s, match) {
        return (match in obj ? obj[match] : s);
    });
};


UIControlSearch.prototype.showList = function() {
    this.list.setStyle('display', 'block');
};


UIControlSearch.prototype.hideList = function() {
    //this.data = {};
    this.list.setStyle('display', 'none');
};


UIControlSearch.prototype.moveSelector = function(delta) {
    //this.data = {};
    this.itemIndex += delta;

    if (this.itemIndex >= this.data.length) {
        this.itemIndex = this.data.length - 1;
    }
    
    if (this.itemIndex < 0) {
        this.itemIndex = 0;
    }
    
    this.updateList({'data' : this.data});
};


UIControlSearch.prototype.updateList = function(json) {
    if (json['data']) {
        var item;
        var list = '';
        var data = json['data'];
        data = data.slice(0,10);
        this.data = data;

        for (var i = 0, li = data.length; i < li; i++) {
            item = data[i];

            if (this.itemIndex == i) {
                list += '<div id="vts-search-item' + i + '"'+ ' class="vts-search-listitem-selected">' + item['title'] + ' ' + (item['region'] ? item['region'] : '') + '</div>';
            } else {
                list += '<div id="vts-search-item' + i + '"'+ ' class="vts-search-listitem">' + item['title'] + ' ' + (item['region'] ? item['region'] : '') + '</div>';
            }
                
        }
        
        this.list.setHtml(list);

        for (i = 0, li = data.length; i < li; i++) {
            var id = 'vts-search-item' + i;
            item = this.control.getElement(id);
            
            if (item) {
                item.on('click', this.onSelectItem.bind(this, i));
                item.on('mouseenter', this.onHoverItem.bind(this, i));
            }
        }

        if (!this.initialValueUsed) {
            this.showList();
        }
    } else {
        this.hideList();
    }
};


UIControlSearch.prototype.onSelectItem = function(index) {
    var map = this.browser.getMap();
    if (map == null) {
        return;
    }

    var pos = map.getPosition();
    //var coords = map.getPositionCoords(pos);                

    var item = this.data[index];
    if (item) {
        var coords = [item['lon'], item['lat']];
        
        //conver coords from location srs to map navigation srs         <commit_msg>fixed search position height mode<commit_after>
import Dom_ from '../../utility/dom';
import {utils as utils_} from '../../../core/utils/utils';

//get rid of compiler mess
var dom = Dom_;
var utils = utils_;


var UIControlSearch = function(ui, visible) {
    this.ui = ui;
    this.browser = ui.browser;
    
    var element = this.browser.config.controlSearchElement;
    if (element) {
        if (typeof element === 'string') {
            element = document.getElementById(element);
        }
    }
    
    this.control = this.ui.addControl('search',
      '<div class="vts-search">'
      + '<div class="vts-search-input"><input type="text" id="vts-search-input" autocomplete="off" spellcheck="false" placeholder="Search location..."></div>'      
      + '<div id="vts-search-list" class="vts-search-list"></div>'      
      + '</div>', visible, element);

    this.input = this.control.getElement('vts-search-input');
    
    //this.input.on("change", this.onChange.bind(this));
    this.input.on('input', this.onChange.bind(this));
    this.input.on('keydown', this.onKeyUp.bind(this));
    this.input.on('focus', this.onFocus.bind(this));
    this.input.on('mousedown', this.onDrag2.bind(this));
    this.input.on('mousewheel', this.onDrag.bind(this));

    this.list = this.control.getElement('vts-search-list');
    this.list.on('mousedown', this.onDrag2.bind(this));
    this.list.on('mousewheel', this.onDrag.bind(this));

    this.mapControl = this.ui.getMapControl();
    this.mapElement = this.mapControl.getMapElement();
    this.mapElement.on('mousedown', this.onDrag.bind(this), window);
    this.mapElement.on('mousewheel', this.onDrag.bind(this), window);

    this.ignoreDrag = false; 

    this.urlTemplate = 'https://www.windy.com/search/get/v1.0/{value}?lang=en-US&hash=b0f07fGWSGdsx-l';
    this.data = [];
    this.lastSearch = '';
    this.itemIndex = -1;
    this.searchCounter = 0;
    this.coordsSrs = '+proj=longlat +datum=WGS84 +nodefs';

    this.initialValueUsed = false;

    if (this.browser.config.controlSearchValue) {
        this.initialValueUsed = true;
        this.input.getElement().value = this.browser.config.controlSearchValue;
        this.onChange();
    }
};


UIControlSearch.prototype.processTemplate = function(str, obj) {
    return str.replace(/\{([$a-zA-Z0-9][$a-zA-Z0-9]*)\}/g, function(s, match) {
        return (match in obj ? obj[match] : s);
    });
};


UIControlSearch.prototype.showList = function() {
    this.list.setStyle('display', 'block');
};


UIControlSearch.prototype.hideList = function() {
    //this.data = {};
    this.list.setStyle('display', 'none');
};


UIControlSearch.prototype.moveSelector = function(delta) {
    //this.data = {};
    this.itemIndex += delta;

    if (this.itemIndex >= this.data.length) {
        this.itemIndex = this.data.length - 1;
    }
    
    if (this.itemIndex < 0) {
        this.itemIndex = 0;
    }
    
    this.updateList({'data' : this.data});
};


UIControlSearch.prototype.updateList = function(json) {
    if (json['data']) {
        var item;
        var list = '';
        var data = json['data'];
        data = data.slice(0,10);
        this.data = data;

        for (var i = 0, li = data.length; i < li; i++) {
            item = data[i];

            if (this.itemIndex == i) {
                list += '<div id="vts-search-item' + i + '"'+ ' class="vts-search-listitem-selected">' + item['title'] + ' ' + (item['region'] ? item['region'] : '') + '</div>';
            } else {
                list += '<div id="vts-search-item' + i + '"'+ ' class="vts-search-listitem">' + item['title'] + ' ' + (item['region'] ? item['region'] : '') + '</div>';
            }
                
        }
        
        this.list.setHtml(list);

        for (i = 0, li = data.length; i < li; i++) {
            var id = 'vts-search-item' + i;
            item = this.control.getElement(id);
            
            if (item) {
                item.on('click', this.onSelectItem.bind(this, i));
                item.on('mouseenter', this.onHoverItem.bind(this, i));
            }
        }

        if (!this.initialValueUsed) {
            this.showList();
        }
    } else {
        this.hideList();
    }
};


UIControlSearch.prototype.onSelectItem = function(index) {
    var map = this.browser.getMap();
    if (map == null) {
        return;
    }

    var pos = map.getPosition();
    //var coords = map.getPositionCoords(pos);                
    pos = map.convertPositionHeightMode(pos, "float", true);

    var item = this.data[index];
    if (item) {
        var coords = [item['lon'], item['lat']];
        
        //conver coords from location srs to map navigation srs         
{'fraction_non_alphanumeric': 0.1789496202802439, 'fraction_numerical': 0.004920312332869826, 'mean_word_length': 2.3987640857869867, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5428224', 'n_tokens_mistral': 3099, 'n_tokens_neox': 3028, 'n_words': 530}