<commit_before>iD.ui.Background = function(context) {
    var key = 'b',
        opacities = [1, 0.5, 0],
        directions = [
            ['left', [1, 0]],
            ['top', [0, -1]],
            ['right', [-1, 0]],
            ['bottom', [0, 1]]],
        opacityDefault = (context.storage('background-opacity') !== undefined) ?
            (+context.storage('background-opacity')) : 0.5;

    function background(selection) {

        function setOpacity(d) {
            context.container().selectAll('.background-layer')
                .transition()
                .style('opacity', d)
                .attr('data-opacity', d);

            opacityList.selectAll('li')
                .classed('active', function(_) { return _ === d; });

            context.storage('background-opacity', d);
        }

        function selectLayer() {
            function active(d) {
                return context.background().showsLayer(d);
            }

            content.selectAll('label.layer')
                .classed('active', active)
                .selectAll('input')
                .property('checked', active);
        }

        function clickSetSource(d) {
            d3.event.preventDefault();
            if (d.data.name === 'Custom') {
                var configured = d();
                if (!configured) {
                    selectLayer();
                    return;
                }
                d = configured;
            }
            context.background().baseLayerSource(d);
            selectLayer();
        }

        function clickSetOverlay(d) {
            d3.event.preventDefault();
            context.background().toggleOverlayLayer(d);
            selectLayer();
        }

        function clickGpx() {
            context.background().toggleGpxLayer();
            update();
        }

        function drawList(layerList, type, change, filter) {
            var sources = context.background()
                .sources(context.map().extent())
                .filter(filter);

            var layerLinks = layerList.selectAll('label.layer')
                .data(sources, function(d) { return d.data.name; });

            var layerInner = layerLinks.enter()
                .append('label')
                .attr('class', 'layer');

            // only set tooltips for layers with tooltips
            layerInner
                .filter(function(d) { return d.data.description; })
                .call(bootstrap.tooltip()
                    .title(function(d) { return d.data.description; })
                    .placement('right')
                );

            layerInner.append('input')
                .attr('type', type)
                .attr('name', 'layers')
                .attr('value', function(d) { return d.data.name; })
                .on('change', change);

            layerInner.insert('span').text(function(d) {
                return d.data.name;
            });

            layerLinks.exit()
                .remove();

            layerList.style('display', layerList.selectAll('label.layer').data().length > 0 ? 'block' : 'none');
        }

        function update() {
            backgroundList.call(drawList, 'radio', clickSetSource, function(d) {
                return !d.data.overlay;
            });

            overlayList.call(drawList, 'checkbox', clickSetOverlay, function(d) {
                return d.data.overlay;
            });

            var hasGpx = context.background().hasGpxLayer(),
                showsGpx = context.background().showsGpxLayer();

            gpxLayerItem
                .classed('active', showsGpx)
                .selectAll('input')
                .property('disabled', !hasGpx)
                .property('checked', showsGpx);

            selectLayer();
        }

        function clickNudge(d) {

            var timeout = window.setTimeout(function() {
                    interval = window.setInterval(nudge, 100);
                }, 500),
                interval;

            d3.select(this).on('mouseup', function() {
                window.clearInterval(interval);
                window.clearTimeout(timeout);
                nudge();
            });

            function nudge() {
                var offset = context.background()
                    .nudge(d[1], context.map().zoom())
                    .offset();
                resetButton.classed('disabled', offset[0] === 0 && offset[1] === 0);
            }
        }

        var content = selection.append('div')
                .attr('class', 'fillL map-overlay content hide'),
            tooltip = bootstrap.tooltip()
                .placement('right')
                .html(true)
                .title(iD.ui.tooltipHtml(t('background.description'), key));

        function hide() { setVisible(false); }

        function toggle() {
            if (d3.event) d3.event.preventDefault();
            tooltip.hide(button);
            setVisible(!button.classed('active'));
            content.selectAll('.toggle-list label:first-child').node().focus();
        }

        function setVisible(show) {
            if (show !== shown) {
                button.classed('active', show);
                shown = show;

                if (show) {
                    selection.on('mousedown.background-inside', function() {
                        return d3.event.stopPropagation();
                    });
                    content.style('display', 'block')
                        .style('left', '0px')
                        .transition()
                        .duration(200)
                        .style('left', '-260px');
                } else {
                    content.style('display', 'block')
                        .style('left', '-260px')
                        .transition()
                        .duration(200)
                        .style('left', '0px')
                        .each('end', function() {
                            d3.select(this).style('display', 'none');<commit_msg>Don't focus when hiding<commit_after>iD.ui.Background = function(context) {
    var key = 'b',
        opacities = [1, 0.5, 0],
        directions = [
            ['left', [1, 0]],
            ['top', [0, -1]],
            ['right', [-1, 0]],
            ['bottom', [0, 1]]],
        opacityDefault = (context.storage('background-opacity') !== undefined) ?
            (+context.storage('background-opacity')) : 0.5;

    function background(selection) {

        function setOpacity(d) {
            context.container().selectAll('.background-layer')
                .transition()
                .style('opacity', d)
                .attr('data-opacity', d);

            opacityList.selectAll('li')
                .classed('active', function(_) { return _ === d; });

            context.storage('background-opacity', d);
        }

        function selectLayer() {
            function active(d) {
                return context.background().showsLayer(d);
            }

            content.selectAll('label.layer')
                .classed('active', active)
                .selectAll('input')
                .property('checked', active);
        }

        function clickSetSource(d) {
            d3.event.preventDefault();
            if (d.data.name === 'Custom') {
                var configured = d();
                if (!configured) {
                    selectLayer();
                    return;
                }
                d = configured;
            }
            context.background().baseLayerSource(d);
            selectLayer();
        }

        function clickSetOverlay(d) {
            d3.event.preventDefault();
            context.background().toggleOverlayLayer(d);
            selectLayer();
        }

        function clickGpx() {
            context.background().toggleGpxLayer();
            update();
        }

        function drawList(layerList, type, change, filter) {
            var sources = context.background()
                .sources(context.map().extent())
                .filter(filter);

            var layerLinks = layerList.selectAll('label.layer')
                .data(sources, function(d) { return d.data.name; });

            var layerInner = layerLinks.enter()
                .append('label')
                .attr('class', 'layer');

            // only set tooltips for layers with tooltips
            layerInner
                .filter(function(d) { return d.data.description; })
                .call(bootstrap.tooltip()
                    .title(function(d) { return d.data.description; })
                    .placement('right')
                );

            layerInner.append('input')
                .attr('type', type)
                .attr('name', 'layers')
                .attr('value', function(d) { return d.data.name; })
                .on('change', change);

            layerInner.insert('span').text(function(d) {
                return d.data.name;
            });

            layerLinks.exit()
                .remove();

            layerList.style('display', layerList.selectAll('label.layer').data().length > 0 ? 'block' : 'none');
        }

        function update() {
            backgroundList.call(drawList, 'radio', clickSetSource, function(d) {
                return !d.data.overlay;
            });

            overlayList.call(drawList, 'checkbox', clickSetOverlay, function(d) {
                return d.data.overlay;
            });

            var hasGpx = context.background().hasGpxLayer(),
                showsGpx = context.background().showsGpxLayer();

            gpxLayerItem
                .classed('active', showsGpx)
                .selectAll('input')
                .property('disabled', !hasGpx)
                .property('checked', showsGpx);

            selectLayer();
        }

        function clickNudge(d) {

            var timeout = window.setTimeout(function() {
                    interval = window.setInterval(nudge, 100);
                }, 500),
                interval;

            d3.select(this).on('mouseup', function() {
                window.clearInterval(interval);
                window.clearTimeout(timeout);
                nudge();
            });

            function nudge() {
                var offset = context.background()
                    .nudge(d[1], context.map().zoom())
                    .offset();
                resetButton.classed('disabled', offset[0] === 0 && offset[1] === 0);
            }
        }

        var content = selection.append('div')
                .attr('class', 'fillL map-overlay content hide'),
            tooltip = bootstrap.tooltip()
                .placement('right')
                .html(true)
                .title(iD.ui.tooltipHtml(t('background.description'), key));

        function hide() { setVisible(false); }

        function toggle() {
            if (d3.event) d3.event.preventDefault();
            tooltip.hide(button);
            var visible = !button.classed('active');
            setVisible(visible);
            if (visible) content.selectAll('.toggle-list label:first-child').node().focus();
        }

        function setVisible(show) {
            if (show !== shown) {
                button.classed('active', show);
                shown = show;

                if (show) {
                    selection.on('mousedown.background-inside', function() {
                        return d3.event.stopPropagation();
                    });
                    content.style('display', 'block')
                        .style('left', '0px')
                        .transition()
                        .duration(200)
                        .style('left', '-260px');
                } else {
                    content.style('display', 'block')
                        .style('left', '-260px')
                        .transition()
                        .duration(200)
                        .style('left', '0px')
                        .each('end', function() {
                            d3.select(this).style('display', 'none');
{'fraction_non_alphanumeric': 0.1378767803908579, 'fraction_numerical': 0.007784034448492879, 'mean_word_length': 1.3332689335394128, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3477108', 'n_tokens_mistral': 3126, 'n_tokens_neox': 2884, 'n_words': 527}