<commit_before>define('login', ['notification', 'storage'], function(notification, storage) {
    var requestedLogin = false;
    var readyForReload = false;

    z.doc.bind('login', function(skipDialog) {
        if (readyForReload) {
            window.location.reload();
            return;
        }
        if (skipDialog) {
            startLogin();
        } else {
            $('.overlay.login').addClass('show');
        }
    }).on('click', '.browserid', loginHandler)
      .on('click', '.persona', loginHandler);

    function loginHandler(e) {
        if (readyForReload) {
            window.location.reload();
            return;
        }

        var $this = $(this);
        $this.addClass('loading-submit');
        z.doc.on('logincancel', function() {
            $this.removeClass('loading-submit').blur();
        });
        if (z.body.data('persona-url')) {
            startLogin();
        } else {
            startFxALogin({
                action: $this.hasClass('register') ?  'signup' : 'signin',
            });
        }
        e.preventDefault();
    }

    function getCenteredCoordinates (width, height) {
        var x = window.screenX + Math.max(0, Math.floor((window.innerWidth - width) / 2));
        var y = window.screenY + Math.max(0, Math.floor((window.innerHeight - height) / 2));
        return [x, y];
    }

    function startFxALogin(options) {
        options = options || {};
        var w = 320;
        var h = 500;
        var i = getCenteredCoordinates(w, h);
        requestedLogin = true;

        var fxa_auth_url = z.body.data('fxa-login-url');
        var fxa_migrate_url = z.body.data('fxa-migrate-url');
        if (fxa_migrate_url) {
            // Save the auth URL for later.
            storage.setItem('fxa_auth_url', fxa_auth_url);
            fxa_auth_url = fxa_migrate_url;
        } else if (options.action) {
            fxa_auth_url += '&action=' + options.action;
        }
        window.open(fxa_auth_url,
                    'fxa',
                    'width=' + w + ',height=' + h + ',left=' + i[0] + ',top=' + i[1]);

        window.addEventListener("message", function (msg) {
            if (!msg.data || !msg.data.auth_code) {
                return;
            }
            var data = {
                'auth_response': msg.data.auth_code,
                'state': z.body.data('fxa-state')
            };
            $.ajax({
                type: 'POST',
                url: z.body.data('fxa-auth-url'),
                contentType: 'application/json',
                data: JSON.stringify(data),
                dataType: 'json'}).done(finishLogin);
        });
    }

    function startLogin() {
        requestedLogin = true;
        var forcedIssuer = document.body.dataset.personaUnverifiedIssuer;
        var mediaUrl = document.body.dataset.mediaUrl;
        if (mediaUrl.indexOf('https:') === -1) {
            mediaUrl = 'https://marketplace.cdn.mozilla.net/media';
        }
        var params = {
            siteLogo: mediaUrl + '/img/mkt/logos/128.png?siteLogo',
            termsOfService: '/terms-of-use',
            privacyPolicy: '/privacy-policy',<commit_msg>Fix popup closure on developer pages (bug 1124781)<commit_after>define('login', ['notification', 'storage'], function(notification, storage) {
    var requestedLogin = false;
    var readyForReload = false;

    z.doc.bind('login', function(skipDialog) {
        if (readyForReload) {
            window.location.reload();
            return;
        }
        if (skipDialog) {
            startLogin();
        } else {
            $('.overlay.login').addClass('show');
        }
    }).on('click', '.browserid', loginHandler)
      .on('click', '.persona', loginHandler);

    function loginHandler(e) {
        if (readyForReload) {
            window.location.reload();
            return;
        }

        var $this = $(this);
        $this.addClass('loading-submit');
        z.doc.on('logincancel', function() {
            $this.removeClass('loading-submit').blur();
        });
        if (z.body.data('persona-url')) {
            startLogin();
        } else {
            startFxALogin({
                action: $this.hasClass('register') ?  'signup' : 'signin',
            });
        }
        e.preventDefault();
    }

    function getCenteredCoordinates (width, height) {
        var x = window.screenX + Math.max(0, Math.floor((window.innerWidth - width) / 2));
        var y = window.screenY + Math.max(0, Math.floor((window.innerHeight - height) / 2));
        return [x, y];
    }

    function startFxALogin(options) {
        options = options || {};
        var w = 320;
        var h = 500;
        var i = getCenteredCoordinates(w, h);
        requestedLogin = true;

        var fxa_auth_url = z.body.data('fxa-login-url');
        var fxa_migrate_url = z.body.data('fxa-migrate-url');
        if (fxa_migrate_url) {
            // Save the auth URL for later.
            storage.setItem('fxa_auth_url', fxa_auth_url);
            fxa_auth_url = fxa_migrate_url;
        } else if (options.action) {
            fxa_auth_url += '&action=' + options.action;
        }
        var popup = window.open(fxa_auth_url, 'fxa',
            'width=' + w + ',height=' + h + ',left=' + i[0] + ',top=' + i[1]);

        window.addEventListener("message", function (msg) {
            if (!msg.data || !msg.data.auth_code) {
                return;
            }
            var data = {
                'auth_response': msg.data.auth_code,
                'state': z.body.data('fxa-state')
            };
            $.ajax({
                type: 'POST',
                url: z.body.data('fxa-auth-url'),
                contentType: 'application/json',
                data: JSON.stringify(data),
                dataType: 'json'}).done(finishLogin);

            // Close popup on receipt of message.
            popup.close();
        });
    }

    function startLogin() {
        requestedLogin = true;
        var forcedIssuer = document.body.dataset.personaUnverifiedIssuer;
        var mediaUrl = document.body.dataset.mediaUrl;
        if (mediaUrl.indexOf('https:') === -1) {
            mediaUrl = 'https://marketplace.cdn.mozilla.net/media';
        }
        var params = {
            siteLogo: mediaUrl + '/img/mkt/logos/128.png?siteLogo',
            termsOfService: '/terms-of-use',
            privacyPolicy: '/privacy-policy',
{'fraction_non_alphanumeric': 0.14736514845328774, 'fraction_numerical': 0.006062490284470698, 'mean_word_length': 1.7590051457975986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7214882', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1901, 'n_words': 355}