<commit_before>(function($) {
  var _options;

  var _boundingBoxes;
  var _map;
  var _mapZones = {};
  var _transitions = {};

  var _loader;
  var _needsLoader = 0;

  var clearZones = function() {
    $.each(_mapZones, function(i, zone) {
      $.each(zone, function(j, polygon) {
        polygon.setMap(null);
      });
    });

    _mapZones = {};
  };

  var onInfoWindow = function(olsonName, utcOffset, tzName) {
    return '<h1>' + olsonName + '<br/>[' + tzName + ':' +
      (utcOffset / 60 / 60) + ']</h1>';
  };

  var slugifyName = function(name) {
    return name.toLowerCase().replace(/[^a-z0-9]/g, '_');
  };

  var drawZone = function(name, lat, lng) {
    if (_mapZones[name]) {
      return;
    }

    $.get(_options.jsonRootUrl + 'polygons/' + name + '.json', function(data) {
      _needsLoader--;
      if (_needsLoader === 0 && _loader) {
        _loader.remove();
        _loader = null;
      }

      data = typeof data === 'string' ? JSON.parse(data) : data;

      var inZone = false;
      var allCoords = [];
      var maxPoints = 0;
      var centroid;
      var selectedZoneName;
      _mapZones[name] = [];
      _transitions[name] = data.transitions;

      $.each(data.polygons, function(i, polygon) {
        // Ray casting counter for hit testing.
        var rayTest = 0;
        var lastPoint = polygon.points[polygon.points.length - 1];

        var coords = [];
        $.each(polygon.points, function(j, point) {
          coords.push(new google.maps.LatLng(point.y, point.x));

          // Ray casting test
          if ((lastPoint.y <= lat && point.y >= lat) ||
            (lastPoint.y > lat && point.y < lat)) {
            var slope = (point.x - lastPoint.x) / (point.y - lastPoint.y);
            var testPoint = slope * (lat - lastPoint.y) + lastPoint.x;
            if (testPoint < lng) {
              rayTest++;
            }
          }

          lastPoint = point;
        });

        allCoords.push(coords);

        // If the count is odd, we are in the polygon
        var odd = (rayTest % 2 === 1);
        inZone |= odd;
        if (odd) {
          selectedZoneName = polygon.name;

          // Hack to get the centroid of the largest polygon - we just check
          // which has the most edges
          if (polygon.points.length > maxPoints) {
            centroid = polygon.centroid;
            maxPoints = polygon.points.length;
          }
        }
      });

      if (inZone) {
        $.each(allCoords, function(i, coords) {
          var mapPolygon = new google.maps.Polygon({
            paths: coords,
            strokeColor: '#ff0000',
            strokeOpacity: 0.7,
            strokeWeight: 1,
            fillColor: '#ffcccc',
            fillOpacity: 0.5
          });
          mapPolygon.setMap(_map);

          _mapZones[name].push(mapPolygon);
        });

        if (_map.lastInfoWindow) {
          _map.lastInfoWindow.close();
        }

        var id = slugifyName(data.name);

        // Figure out the UTC offset
        var transitions = _transitions[name][selectedZoneName];
        var now = new Date().getTime();
        var utcOffset = 0;
        var tzName = '';
        $.each(transitions, function(i, transition) {
          if (transition.time < now) {
            utcOffset = transition.utc_offset;
            tzName = transition.tzname;
          }
        });

        var infowindow = new google.maps.InfoWindow({
          content: '<div id="' + id + '" class="timezone-picker-infowindow">' +
            _options.onInfoWindow(selectedZoneName, utcOffset, tzName) +
            '<div class="timezone-picker-buttons">' +
            '<button>Use Timezone</button><button>Cancel</button>' +
            '</div>' +
            '</div>',
          maxWidth: 500
        });

        google.maps.event.addListener(infowindow, 'domready', function() {
          // HACK: Put rounded corners on the infowindow
          $('#' + id).parent().parent().parent().prev().css('border-radius',
            '5px');
          $('#' + id + ' button:eq(0)').click(function(e) {
            if (e.which > 1) {
              return;
            }

            if (_options.onSelected) {
              _options.onSelected(selectedZoneName, utcOffset, tzName);
            }

            e.preventDefault();
            return false;
          });

          $('#' + id + ' button:eq(1)').click(function(e) {
            if (e.which > 1) {
              return;
            }
            infowindow.close();
            e.preventDefault();
            return false;
          });
        });
        infowindow.setPosition(new google.maps.LatLng(
          centroid[1],
          centroid[0]
        ));
        infowindow.open(_map);

        _map.lastInfoWindow = infowindow;
      }
    });
  };

  var methods = {
    init: function(options) {
      var self = this;

      // Populate the options and set defaults
      _options = options || {};
      _options.initialZoom = _options.initialZoom || 2;
      _options.initialLat = _options.initialLat || 0;
      _options.initialLng = _options.initialLng || 0;
      _options.strokeColor = _options.strokeColor || '#ff0000';
      _options.strokeWeight = _options.strokeWeight || 2;
      _options.strokeOpacity = _options.strokeOpacity || 0.7;
      _options.fillColor = _options.fillColor || '#ffcccc';
      _options.fillOpacity = _options.fillOpacity || 0.5;
      _options.jsonRootUrl = _options.jsonRootUrl || 'tz_json/';
      _options.onInfoWindow = _options.onInfoWindow || onInfoWindow;

      // Create the maps instance
      _map = new google.maps.Map(self.get(0), {
        zoom: _options.initialZoom,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: new google.maps.LatLng(_options.initialLat, _options.initialLng)
      });<commit_msg>allow clicking on sub-timezones to get info window<commit_after>(function($) {
  var _options;

  var _boundingBoxes;
  var _map;
  var _mapZones = {};
  var _transitions;

  var _loader;
  var _needsLoader = 0;

  var clearZones = function() {
    $.each(_mapZones, function(i, zone) {
      $.each(zone, function(j, polygon) {
        polygon.setMap(null);
      });
    });

    _mapZones = {};
  };

  var onInfoWindow = function(olsonName, utcOffset, tzName) {
    return '<h1>' + olsonName + '<br/>[' + tzName + ':' +
      (utcOffset / 60 / 60) + ']</h1>';
  };

  var showInfoWindow = function(polygon) {
    // Hack to get the centroid of the largest polygon - we just check
    // which has the most edges
    var maxPoints = 0;
    if (polygon.points.length > maxPoints) {
      centroid = polygon.centroid;
      maxPoints = polygon.points.length;
    }

    if (_map.lastInfoWindow) {
      _map.lastInfoWindow.close();
    }

    var selectedZoneName = polygon.name;
    var id = slugifyName(selectedZoneName);

    // Figure out the UTC offset
    var transitions = _transitions[selectedZoneName];
    var now = new Date().getTime();
    var utcOffset = 0;
    var tzName = '';
    $.each(transitions, function(i, transition) {
      if (transition.time < now) {
        utcOffset = transition.utc_offset;
        tzName = transition.tzname;
      }
    });

    var infowindow = new google.maps.InfoWindow({
      content: '<div id="' + id + '" class="timezone-picker-infowindow">' +
        _options.onInfoWindow(selectedZoneName, utcOffset, tzName) +
        '<div class="timezone-picker-buttons">' +
        '<button>Use Timezone</button><button>Cancel</button>' +
        '</div>' +
        '</div>',
      maxWidth: 500
    });

    google.maps.event.addListener(infowindow, 'domready', function() {
      // HACK: Put rounded corners on the infowindow
      $('#' + id).parent().parent().parent().prev().css('border-radius',
        '5px');
      $('#' + id + ' button:eq(0)').click(function(e) {
        if (e.which > 1) {
          return;
        }

        if (_options.onSelected) {
          _options.onSelected(selectedZoneName, utcOffset, tzName);
        }

        e.preventDefault();
        return false;
      });

      $('#' + id + ' button:eq(1)').click(function(e) {
        if (e.which > 1) {
          return;
        }
        infowindow.close();
        e.preventDefault();
        return false;
      });
    });
    infowindow.setPosition(new google.maps.LatLng(
      centroid[1],
      centroid[0]
    ));
    infowindow.open(_map);

    _map.lastInfoWindow = infowindow;
  };

  var slugifyName = function(name) {
    return name.toLowerCase().replace(/[^a-z0-9]/g, '_');
  };

  var drawZone = function(name, lat, lng) {
    if (_mapZones[name]) {
      return;
    }

    $.get(_options.jsonRootUrl + 'polygons/' + name + '.json', function(data) {
      _needsLoader--;
      if (_needsLoader === 0 && _loader) {
        _loader.remove();
        _loader = null;
      }

      data = typeof data === 'string' ? JSON.parse(data) : data;

      var inZone = false;
      var allPolygons = [];
      var selectedPolygon;
      _mapZones[name] = [];
      _transitions = data.transitions;

      $.each(data.polygons, function(i, polygon) {
        // Ray casting counter for hit testing.
        var rayTest = 0;
        var lastPoint = polygon.points[polygon.points.length - 1];

        var coords = [];
        $.each(polygon.points, function(j, point) {
          coords.push(new google.maps.LatLng(point.y, point.x));

          // Ray casting test
          if ((lastPoint.y <= lat && point.y >= lat) ||
            (lastPoint.y > lat && point.y < lat)) {
            var slope = (point.x - lastPoint.x) / (point.y - lastPoint.y);
            var testPoint = slope * (lat - lastPoint.y) + lastPoint.x;
            if (testPoint < lng) {
              rayTest++;
            }
          }

          lastPoint = point;
        });

        allPolygons.push({
          polygon: polygon,
          coords: coords
        });

        // If the count is odd, we are in the polygon
        var odd = (rayTest % 2 === 1);
        inZone |= odd;
        if (odd) {
          selectedPolygon = polygon;
        }
      });

      if (inZone) {
        $.each(allPolygons, function(i, polygonInfo) {
          var mapPolygon = new google.maps.Polygon({
            paths: polygonInfo.coords,
            strokeColor: '#ff0000',
            strokeOpacity: 0.7,
            strokeWeight: 1,
            fillColor: '#ffcccc',
            fillOpacity: 0.5
          });
          mapPolygon.setMap(_map);

          google.maps.event.addListener(mapPolygon, 'click', function() {
            showInfoWindow(polygonInfo.polygon);
          });

          _mapZones[name].push(mapPolygon);
        });

        showInfoWindow(selectedPolygon);
      }
    });
  };

  var methods = {
    init: function(options) {
      var self = this;

      // Populate the options and set defaults
      _options = options || {};
      _options.initialZoom = _options.initialZoom || 2;
      _options.initialLat = _options.initialLat || 0;
      _options.initialLng = _options.initialLng || 0;
      _options.strokeColor = _options.strokeColor || '#ff0000';
      _options.strokeWeight = _options.strokeWeight || 2;
      _options.strokeOpacity = _options.strokeOpacity || 0.7;
      _options.fillColor = _options.fillColor || '#ffcccc';
      _options.fillOpacity = _options.fillOpacity || 0.5;
      _options.jsonRootUrl = _options.jsonRootUrl || 'tz_json/';
      _options.onInfoWindow = _options.onInfoWindow || onInfoWindow;

      // Create the maps instance
      _map = new google.maps.Map(self.get(0), {
        zoom: _options.initialZoom,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        center: new google.maps.LatLng(_options.initialLat, _options.initialLng)
      });
{'fraction_non_alphanumeric': 0.13902147971360382, 'fraction_numerical': 0.008182748039549948, 'mean_word_length': 1.9696279422930905, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, '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': '890855', 'n_tokens_mistral': 3738, 'n_tokens_neox': 3583, 'n_words': 754}