<commit_before>/*global define*/
define('views/map', [
      'jquery'
    , 'underscore'
    , 'backbone'
    , 'leaflet'
    , 'text!partials/map.html'
    , 'models/map'
    , 'views/marker'
], function($,_,Backbone,L,mapPartial,MapModel,MarkerView) {
    'use strict';
    var MapView = Backbone.View.extend({
        id:      'map',
        tagName: 'div',
        initialize: function(args) {
            var that = this;
            that.config = args.config;
            that.model = new MapModel(args);
            that.router = args.router;
        }
        , render: function () {
            var that = this;
            if ($('#' + that.id).children().length > 0) return;
            // put div#map in place
            // note: map.json has the @id value: {"id" : "map"}
            $('body').append(mapPartial);
            // Leaflet config
            this.model.init().done(function() {
                var col       = that.model.get('collection');
                var mapconfig = that.model.get('mapconfig');
                var map       = new L.Map(mapconfig.id, mapconfig.map);
                var openpopup = {};
                var popupid = function(latlng) {
                    return latlng.lat.toString()
                         + latlng.lng.toString()
                };
                that.configureMap(map,mapconfig,openpopup,popupid);
                // let map render while markers are added
                map.invalidateSize();
                window.setTimeout(function() {
                    col.forEach(function(markerModel) {
                        that.addMarkerToMap(markerModel,map,openpopup,popupid,mapconfig);
                    })
                }, that.config.map.markerDelay);
            });
        }
        , configureMap : function(map,mapconfig,openpopup,popupid) {
            var that        = this;
            var tilelayer   = new L.TileLayer(mapconfig.tileLayer.url, mapconfig.tileLayer.opts);
            var scale       = L.control.scale(mapconfig.scale);
            map.setView(new L.LatLng(mapconfig.view.lat, mapconfig.view.lng), mapconfig.view.zoom);
            map.addLayer(tilelayer);
            scale.addTo(map);
            // track the currently open popup
            map.on('popupopen', function(evt) {
                // event latency between leaflet and backbone
                // appears to cause popups to collapse erratically
                // in Firefox when clicking map pins
                if (navigator.userAgent.indexOf('Firefox') != -1) {
                    openpopup[popupid(evt.popup.getLatLng())] = true;
                } else {
                    openpopup[popupid(evt.popup.getLatLng())] = true;
                }
            });
            map.on('popupclose', function(evt){
                if (navigator.userAgent.indexOf('Firefox') != -1) {<commit_msg>automatically pan the map right/east if the marker is beneath the article when its popup opens<commit_after>/*global define*/
define('views/map', [
      'jquery'
    , 'underscore'
    , 'backbone'
    , 'leaflet'
    , 'text!partials/map.html'
    , 'models/map'
    , 'views/marker'
], function($,_,Backbone,L,mapPartial,MapModel,MarkerView) {
    'use strict';
    var MapView = Backbone.View.extend({
        id:      'map',
        tagName: 'div',
        initialize: function(args) {
            var that = this;
            that.config = args.config;
            that.model = new MapModel(args);
            that.router = args.router;
        }
        , render: function () {
            var that = this;
            if ($('#' + that.id).children().length > 0) return;
            // put div#map in place
            // note: map.json has the @id value: {"id" : "map"}
            $('body').append(mapPartial);
            // Leaflet config
            this.model.init().done(function() {
                var col       = that.model.get('collection');
                var mapconfig = that.model.get('mapconfig');
                var map       = new L.Map(mapconfig.id, mapconfig.map);
                var openpopup = {};
                var popupid = function(latlng) {
                    return latlng.lat.toString()
                         + latlng.lng.toString()
                };
                that.configureMap(map,mapconfig,openpopup,popupid);
                // let map render while markers are added
                map.invalidateSize();
                window.setTimeout(function() {
                    col.forEach(function(markerModel) {
                        that.addMarkerToMap(markerModel,map,openpopup,popupid,mapconfig);
                    })
                }, that.config.map.markerDelay);
            });
        }
        , configureMap : function(map,mapconfig,openpopup,popupid) {
            var that        = this;
            var tilelayer   = new L.TileLayer(mapconfig.tileLayer.url, mapconfig.tileLayer.opts);
            var scale       = L.control.scale(mapconfig.scale);
            map.setView(new L.LatLng(mapconfig.view.lat, mapconfig.view.lng), mapconfig.view.zoom);
            map.addLayer(tilelayer);
            scale.addTo(map);
            // track the currently open popup
            map.on('popupopen', function(evt) {
                var popup = evt.popup;
                var popupLatLng = popup.getLatLng();
                var edgeLatLng = map.containerPointToLatLng(L.DomUtil.getViewportOffset(document.getElementById('article')));
                var dx, offset, pad;
                // pan east if the popup is covered by the article (i.e., is to the
                // right of the article's left edge)
                if (popupLatLng.lng > edgeLatLng.lng) {
                    // offset is the amount of the popup that would hang over under the article
                    // due to the popup's width
                    offset = $(popup.getContent()).closest('.leaflet-popup-content-wrapper').first().width()/2
                           - (map.latLngToLayerPoint(edgeLatLng).x - map.latLngToLayerPoint(map.getCenter()).x);
                    // pad is a slight relief between the popup and the article
                    pad = L.point(popup.options.autoPanPaddingBottomRight || popup.options.autoPanPadding);
                    pad = pad ? pad.x : 0;
                    // dx is the distance between the center of the map and the
                    // map marker for this popup
                    dx = map.latLngToLayerPoint(popupLatLng).x
                       - map.latLngToLayerPoint(map.getCenter()).x;
                    map.panBy([dx + offset + pad,0]);
                }
                // event latency between leaflet and backbone
                // appears to cause popups to collapse erratically
                // in Firefox when clicking map pins
                if (navigator.userAgent.indexOf('Firefox') != -1) {
                    openpopup[popupid(popupLatLng)] = true;
                } else {
                    openpopup[popupid(popupLatLng)] = true;
                }
            });
            map.on('popupclose', function(evt) {
                if (navigator.userAgent.indexOf('Firefox') != -1) {
{'fraction_non_alphanumeric': 0.11671087533156499, 'fraction_numerical': 0.0012564567918469914, 'mean_word_length': 1.5404255319148936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3469946', 'n_tokens_mistral': 1976, 'n_tokens_neox': 1882, 'n_words': 409}