<commit_before>"use strict";

var $ = require('jquery'),
    Marionette = require('../shim/backbone.marionette'),
    shutterbug = require('../shim/shutterbug'),
    views = require('./core/views'),
    models = require('./core/models'),
    settings = require('./core/settings'),
    itsi = require('./core/itsiEmbed'),
    analyzeModels = require('./analyze/models'),
    userModels = require('./user/models'),
    userViews = require('./user/views');

var App = new Marionette.Application({
    initialize: function() {
        this.restApi = new RestAPI();
        this.map = new models.MapModel();
        this.state = new models.AppStateModel();

        // If in embed mode we are by default in activity mode.
        var activityMode = settings.get('itsi_embed');
        settings.set('activityMode', activityMode);

        // Initialize embed interface if in activity mode
        if (activityMode) {
            this.itsi = new itsi.ItsiEmbed(this);
            this.itsi.getAuthInfo();
        }

        // This view is intentionally not attached to any region.
        this._mapView = new views.MapView({
            model: this.map,
            el: '#map'
        });

        this._mapView.on('change:needs_reset', function(needs) {
            App.currentProject.set('needs_reset', needs);
        });

        this.rootView = new views.RootView({app: this});
        this.user = new userModels.UserModel({});

        this.header = new views.HeaderView({
            el: 'header',
            model: this.user,
            appState: this.state
        });

        this.header.render();

        // Not set until modeling/controllers.js creates a
        // new project.
        this.currentProject = null;

        // Enable screenshot functionality
        initializeShutterbug();
    },

    load: function(data) {
        var mapState = data.map;
        if (mapState) {
            this.map.set({
                lat: mapState.lat,
                lng: mapState.lng,
                zoom: mapState.zoom
            });
        }
    },

    getAnalyzeCollection: function() {
        if (!this.analyzeCollection) {
            this.analyzeCollection = analyzeModels.createAnalyzeTaskCollection(this.map.get('areaOfInterest'));
        }

        return this.analyzeCollection;
    },

    clearAnalyzeCollection: function() {
        delete this.analyzeCollection;
    },

    getMapView: function() {
        return this._mapView;
    },

    getLeafletMap: function() {
        return this._mapView._leafletMap;
    },

    getUserOrShowLoginIfNotItsiEmbed: function() {
        if (!settings.get('itsi_embed')) {
            this.getUserOrShowLogin();
        }
    },

    getUserOrShowLogin: function() {
        this.user.fetch().always(function() {
            if (App.user.get('guest')) {
                App.showLoginModal();
            }
        });
    },

    showLoginModal: function() {
        new userViews.LoginModalView({
            model: new userModels.LoginFormModel({}),
            app: this
        }).render();
    }
});

function RestAPI() {
    return {
        getPolygon: function(args) {
            var url = '/api/modeling/boundary-layers/' + args.layerCode + '/' + args.shapeId;
            return $.ajax({
                'url': url,
                'type': 'GET'
            });
        }
    };
}

function initializeShutterbug() {
    var googleTileLayerSelector = '#map > .leaflet-google-layer > div > div > div:nth-child(1) > div:nth-child(1)';

    $(window)
        .on('shutterbug-saycheese', function() {
            // Set fixed width before screenshot to constrain width to viewport
            $('#model-output-wrapper, body > .map-container').css({
                'width': window.innerWidth
            });

            var mapView = App.getMapView(),
                activeBaseLayer = mapView.baseLayers[mapView.getActiveBaseLayerName()],
                googleLayerVisible = !!activeBaseLayer._google;

            if (googleLayerVisible) {
                // Convert Google Maps CSS Transforms to Left / Right
                var $googleTileLayer = $(googleTileLayerSelector),
                    transform = $googleTileLayer.css('transform').split(','),
                    left = parseFloat(transform[4]),
                    top = parseFloat(transform[5]);

                $googleTileLayer.css({
                    transform: 'none',
                    left: left,
                    top: top,
                });
            }
        })
        .on('shutterbug-asyouwere', function() {
            // Reset after screenshot has been taken
            $('#model-output-wrapper, body > .map-container').css({
                'width': ''
            });

            var mapView = App.getMapView(),
                activeBaseLayer = mapView.baseLayers[mapView.getActiveBaseLayerName()],
                googleLayerVisible = !!activeBaseLayer._google;

            if (googleLayerVisible) {
                var $googleTileLayer = $(googleTileLayerSelector),
                    left = parseFloat($googleTileLayer.css('left')),
                    top = parseFloat($googleTileLayer.css('top')),
                    transform = 'matrix(1, 0, 0, 1, ' + left + ', ' + top + ')';

                $googleTileLayer.css({
                    transform: transform,
                    left: '',
                    top: '',
                });
            }
        });

    shutterbug.enable('body');
}

module.exports = App;
<commit_msg>Fix ITSI Firefox screenshots<commit_after>"use strict";

var $ = require('jquery'),
    Marionette = require('../shim/backbone.marionette'),
    shutterbug = require('../shim/shutterbug'),
    views = require('./core/views'),
    models = require('./core/models'),
    settings = require('./core/settings'),
    itsi = require('./core/itsiEmbed'),
    analyzeModels = require('./analyze/models'),
    userModels = require('./user/models'),
    userViews = require('./user/views');

var App = new Marionette.Application({
    initialize: function() {
        this.restApi = new RestAPI();
        this.map = new models.MapModel();
        this.state = new models.AppStateModel();

        // If in embed mode we are by default in activity mode.
        var activityMode = settings.get('itsi_embed');
        settings.set('activityMode', activityMode);

        // Initialize embed interface if in activity mode
        if (activityMode) {
            this.itsi = new itsi.ItsiEmbed(this);
            this.itsi.getAuthInfo();
        }

        // This view is intentionally not attached to any region.
        this._mapView = new views.MapView({
            model: this.map,
            el: '#map'
        });

        this._mapView.on('change:needs_reset', function(needs) {
            App.currentProject.set('needs_reset', needs);
        });

        this.rootView = new views.RootView({app: this});
        this.user = new userModels.UserModel({});

        this.header = new views.HeaderView({
            el: 'header',
            model: this.user,
            appState: this.state
        });

        this.header.render();

        // Not set until modeling/controllers.js creates a
        // new project.
        this.currentProject = null;

        // Enable screenshot functionality
        initializeShutterbug();
    },

    load: function(data) {
        var mapState = data.map;
        if (mapState) {
            this.map.set({
                lat: mapState.lat,
                lng: mapState.lng,
                zoom: mapState.zoom
            });
        }
    },

    getAnalyzeCollection: function() {
        if (!this.analyzeCollection) {
            this.analyzeCollection = analyzeModels.createAnalyzeTaskCollection(this.map.get('areaOfInterest'));
        }

        return this.analyzeCollection;
    },

    clearAnalyzeCollection: function() {
        delete this.analyzeCollection;
    },

    getMapView: function() {
        return this._mapView;
    },

    getLeafletMap: function() {
        return this._mapView._leafletMap;
    },

    getUserOrShowLoginIfNotItsiEmbed: function() {
        if (!settings.get('itsi_embed')) {
            this.getUserOrShowLogin();
        }
    },

    getUserOrShowLogin: function() {
        this.user.fetch().always(function() {
            if (App.user.get('guest')) {
                App.showLoginModal();
            }
        });
    },

    showLoginModal: function() {
        new userViews.LoginModalView({
            model: new userModels.LoginFormModel({}),
            app: this
        }).render();
    }
});

function RestAPI() {
    return {
        getPolygon: function(args) {
            var url = '/api/modeling/boundary-layers/' + args.layerCode + '/' + args.shapeId;
            return $.ajax({
                'url': url,
                'type': 'GET'
            });
        }
    };
}

function initializeShutterbug() {
    var googleTileLayerSelector = '#map > .leaflet-google-layer > div > div > div:nth-child(1) > div:nth-child(1)';

    $(window)
        .on('shutterbug-saycheese', function() {
            // Set fixed width before screenshot to constrain width to viewport
            $('#model-output-wrapper, body > .map-container').css({
                'width': window.innerWidth
            });

            var mapView = App.getMapView(),
                activeBaseLayer = mapView.baseLayers[mapView.getActiveBaseLayerName()],
                googleLayerVisible = !!activeBaseLayer._google;

            if (googleLayerVisible) {
                // Convert Google Maps CSS Transforms to Left / Right
                var $googleTileLayer = $(googleTileLayerSelector),
                    transform = $googleTileLayer.css('transform').split(','),
                    left = parseFloat(transform[4]),
                    top = parseFloat(transform[5]);

                $googleTileLayer.css({
                    transform: 'none',
                    left: left,
                    top: top,
                });
            }

            // Fix Firefox screenshots by adding a '#' to the URL.
            // Setting to empty string does nothing, so we first set to
            // '/' then to empty string, which leaves a '#' in the URL.
            document.location.hash = '/';
            document.location.hash = '';
        })
        .on('shutterbug-asyouwere', function() {
            // Reset after screenshot has been taken
            $('#model-output-wrapper, body > .map-container').css({
                'width': ''
            });

            var mapView = App.getMapView(),
                activeBaseLayer = mapView.baseLayers[mapView.getActiveBaseLayerName()],
                googleLayerVisible = !!activeBaseLayer._google;

            if (googleLayerVisible) {
                var $googleTileLayer = $(googleTileLayerSelector),
                    left = parseFloat($googleTileLayer.css('left')),
                    top = parseFloat($googleTileLayer.css('top')),
                    transform = 'matrix(1, 0, 0, 1, ' + left + ', ' + top + ')';

                $googleTileLayer.css({
                    transform: transform,
                    left: '',
                    top: '',
                });
            }
        });

    shutterbug.enable('body');
}

module.exports = App;

{'fraction_non_alphanumeric': 0.1293453326274925, 'fraction_numerical': 0.0014116816657843657, 'mean_word_length': 1.7333011815770436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '1033376', 'n_tokens_mistral': 3094, 'n_tokens_neox': 2936, 'n_words': 619}