<commit_before>/**
 * The Searchbox module.
 *
 * @return searchbox class (extends Backbone.View).
 */
define([
  'underscore',
  'backbone',
  'handlebars',
  'keymaster',
  'map/presenters/controls/SearchboxPresenter',
  'text!map/templates/controls/searchbox.handlebars'
], function(_, Backbone, Handlebars, keymaster, Presenter, tpl) {

  'use strict';

  var SearchboxModel = Backbone.Model.extend({
    defaults:{
      hidden: true
    }
  });




  var Searchbox = Backbone.View.extend({

    el: '#control-searchbox',

    template: Handlebars.compile(tpl),

    events: {
      'click' : 'onClick'
    },

    initialize: function(map) {
      this.map = map;
      this.model = new SearchboxModel();
      this.presenter = new Presenter(this);
      _.bindAll(this, 'setAutocomplete', 'onPlaceSelected');

      this.render();
      //cacheVars
      this.$input = this.$el.find('input');

      this.setListeners();
      this.setAutocomplete();

    },

    checkSearchType: function(address) {
      var isLatLong = function(address) {
        return (address.includes("º") || address.includes("°")) && address.includes("'") && address.includes("\"") && (address.includes("W") || address.includes("E")) && (address.includes("N") || address.includes("S"));
      }
      var isDegrees = function(address) {
        address = address.split(',');
        if (!!address && address.length != 2) return false;
        if (~~((address[0] + address[1]) * -1) === 0) return false; //avoid mistakes with coordinates, degrees have no letters, so everything must be numbers ~~NaN will be 0

        var degrees = new Uint8Array(new ArrayBuffer(2));
        degrees[0] = ~~address[0].split('.');
        degrees[1] = ~~address[1].split('.');
        if (degrees[0] <= 90 && degrees[1] <= 180) {
          return true;
        }
        return false;
      }
      if (isLatLong(address)) {
        //user typed a latitude and longitude coordinates

      } else if (isDegrees(address)) {
        //user typed a degrees coordinates

      } else {
        //user typed a regular address

      }
    },

    setListeners: function(){
      this.$input.on('keyup', _.bind(function(e){
        if (e.keyCode === 27) {
          this.model.set('hidden', false);
          this.toggleSearch();
        } else {
          if (! !! e.target.value) return;
          this.checkSearchType(e.target.value);
        }
      }, this ));

      google.maps.event.addListener(this.map, 'click',_.bind(function() {
        this.model.set('hidden', false);
        this.toggleSearch();
      }, this));
    },

    render: function(){
      this.$el.html(this.template);
    },
<commit_msg>Map: search box toggle tab<commit_after>/**
 * The Searchbox module.
 *
 * @return searchbox class (extends Backbone.View).
 */
define([
  'underscore',
  'backbone',
  'handlebars',
  'keymaster',
  'map/presenters/controls/SearchboxPresenter',
  'text!map/templates/controls/searchbox.handlebars'
], function(_, Backbone, Handlebars, keymaster, Presenter, tpl) {

  'use strict';

  var SearchboxModel = Backbone.Model.extend({
    defaults:{
      hidden: true
    }
  });




  var Searchbox = Backbone.View.extend({

    el: '#control-searchbox',

    template: Handlebars.compile(tpl),

    events: {
      'click' : 'onClick',
      'click .searching-kinds' : '_setType'
    },

    initialize: function(map) {
      this.map = map;
      this.model = new SearchboxModel();
      this.presenter = new Presenter(this);
      _.bindAll(this, 'setAutocomplete', 'onPlaceSelected');

      this.render();
      //cacheVars
      this.$input = this.$el.find('input');

      this.setListeners();
      this.setAutocomplete();

    },

    checkSearchType: function(address) {
      var isLatLong = function(address) {
        return (address.includes("º") || address.includes("°")) && address.includes("'") && address.includes("\"") && (address.includes("W") || address.includes("E")) && (address.includes("N") || address.includes("S"));
      }
      var isDegrees = function(address) {
        address = address.split(',');
        if (!!address && address.length != 2) return false;
        if (~~((address[0] + address[1]) * -1) === 0) return false; //avoid mistakes with coordinates, degrees have no letters, so everything must be numbers ~~NaN will be 0

        var degrees = new Uint8Array(new ArrayBuffer(2));
        degrees[0] = ~~address[0].split('.');
        degrees[1] = ~~address[1].split('.');
        if (degrees[0] <= 90 && degrees[1] <= 180) {
          return true;
        }
        return false;
      }
      if (isLatLong(address)) {
        //user typed a latitude and longitude coordinates

      } else if (isDegrees(address)) {
        //user typed a degrees coordinates

      } else {
        //user typed a regular address

      }
    },

    _setType: function(e) {
      var $target = $(e.target);
      if ($target.hasClass('selected')) return;

      $(e.target).parent().find('.selected').removeClass('selected');
      $target.addClass('selected');
      var type = $target.data('kind');
      this.$searchbox.find('.search.selected').removeClass('selected');
      this.$searchbox.find('.search.'+type).addClass('selected');
    },
    setListeners: function(){
      this.$input.on('keyup', _.bind(function(e){
        if (e.keyCode === 27) {
          this.model.set('hidden', false);
          this.toggleSearch();
        } else {
          if (! !! e.target.value) return;
          this.checkSearchType(e.target.value);
        }
      }, this ));

      google.maps.event.addListener(this.map, 'click',_.bind(function() {
        this.model.set('hidden', false);
        this.toggleSearch();
      }, this));
    },

    render: function(){
      this.$el.html(this.template);
      this.$searchbox = $('.search-box');
    },

{'fraction_non_alphanumeric': 0.17042735042735044, 'fraction_numerical': 0.0071794871794871795, 'mean_word_length': 2.585171568627451, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4937274', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1750, 'n_words': 372}