<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

;(function($, Modernizr, dataLayer, site) {
    'use strict';

    var $window = $(window);
    var $document = $(document);

    var uiTourSendEvent = function(action, data) {
        var event = new CustomEvent('mozUITour', {
            bubbles: true,
            detail: {
                action: action,
                data: data || {}
            }
        });

        document.dispatchEvent(event);
    };

    var uiTourGetConfiguration = function(configName, callback) {
        uiTourSendEvent('getConfiguration', {
            configuration: configName,
            callbackID: function() {
                var id = Math.random().toString(36).replace(/[^a-z]+/g, '');

                function listener(event) {
                    if (typeof event.detail === 'object' && event.detail.callbackID === id) {
                        document.removeEventListener('mozUITourResponse', listener);
                        callback(event.detail.data);
                    }
                }

                document.addEventListener('mozUITourResponse', listener);

                return id;
            }.call()
        });
    };

    var isIELT9 = (site.platform === 'windows' && /MSIE\s[1-8]\./.test(navigator.userAgent));
    var path_parts = window.location.pathname.split('/');
    var query_str = window.location.search ? window.location.search + '&' : '?';
    var params = new _SearchParams();
    var referrer = path_parts[path_parts.length - 2];
    var locale = path_parts[1];
    var virtual_url = ('/' + locale + '/products/download.html' +
                       query_str + 'referrer=' + referrer);

    var $html = $(document.documentElement);

    if (isFirefox()) {
        // data-latest-firefox includes point release information
        var latestFirefoxVersionFull = $html.attr('data-latest-firefox');

        // get latest full version (no point release info) for initial check
        var latestFirefoxVersion = parseInt(latestFirefoxVersionFull.split('.')[0], 10);

        if (isFirefoxUpToDate(latestFirefoxVersion + '')) {
            if (window.location.hash !== '#download-fx' && params.get('scene') !== 2) {
                // the firefox-latest class prevents the download from triggering
                // and scene 2 from showing, which we want if the user lands on
                // /firefox/new/ but if the user visits /firefox/new/?scene=2#download-fx
                // (from a download button) then we want them to see the same scene 2
                // as non-firefox users and initiate a download
                $html.addClass('firefox-latest');

                // if user is on release channel and has latest version, offer refresh button
                uiTourGetConfiguration('appinfo', function(config) {
                    if (config.defaultUpdateChannel === 'release' && config.version === latestFirefoxVersionFull) {
                        $html.addClass('show-refresh');

                        // DOM may not be ready yet, so bind filtered click handler to document
                        $document.on('click', '#refresh-firefox', function() {
                            uiTourSendEvent('resetFirefox');
                        });
                    }
                });
            }
        } else {
            $html.addClass('firefox-old');
        }
    }

    // scene2 install images are unique for IE < 9
    if (isIELT9) {
        $html.addClass('winIE8');
    }

    // Add GA custom tracking and external link tracking
    var state = 'Desktop, not Firefox';
    if (site.platform === 'android') {
        if ($html.hasClass('firefox-latest')) {
            state = 'Android, Firefox up-to-date';
        } else if ($html.hasClass('firefox-old')) {
            state = 'Android, Firefox not up-to-date';
        } else {
            state = 'Android, not Firefox';
        }
    } else if (site.platform === 'ios') {
        state = 'iOS, Firefox not supported';
    } else if (site.platform === 'fxos') {
        state = 'FxOS';
    } else {
        if ($html.hasClass('firefox-latest')) {
            state = 'Desktop, Firefox up-to-date';
        } else if ($html.hasClass('firefox-old')) {
            state = 'Desktop, Firefox not up-to-date';
        }
    }
    //GA Custom Dimension in Pageview
    window.dataLayer.push({
        event: 'set-state',
        state: state
    });

    // conditions in which scene2 should not be shown, even when the
    // #download-fx hash is set
    var no_scene2 = (
           site.platform === 'other'    // no download available
        || site.platform === 'ios'      // unsupported platform
        || site.platform === 'fxos'     // no download available
        || site.platform === 'android'  // download goes to Play Store
    );

    $document.ready(function() {
        var $scene1 = $('#scene1');
        var $stage = $('#stage-firefox');
        var $thankYou = $('.thankyou');
        var hash_change = ('onhashchange' in window);

        // if desktop with download available, re-locate dl button links
        if (!no_scene2 && $('.download-button-wrapper:visible').length > 0) {
            var $downloadButtonLinks = $('.download-button-wrapper .download-other-desktop').detach();
            $downloadButtonLinks.css('display', 'block').insertBefore('#firefox-screenshot');
        }

        if (site.platform === 'android') {
            $('#download-button-android .download-subtitle').html(
                $('.android.download-button-wrapper').data('upgradeSubtitle'));

            // On Android, skip all the scene transitions. We're just linking
            // to the Play Store.
            return;
        }

        function show_scene(scene, animate) {
            if (animate) {
                $stage.removeClass('stage-no-anim');
            } else {
                $stage.addClass('stage-no-anim');
            }

            var CSSbottom = (scene === 2) ? '-420px' : 0;
            $stage.data('scene', scene);
            $('.scene').css('visibility', 'visible');
            if (!Modernizr.csstransitions && animate) {
                $stage.animate({
                    bottom: CSSbottom
                }, 400);
            } else {
                $stage.toggleClass('scene2');
            }
            if (scene === 2) {
                // after animation, hide scene1 so it's not focusable and
                // reset focus
                setTimeout(function() {
                    $scene1.css('visibility', 'hidden');
                    $thankYou.focus();
                }, 500);
            }
        }

        function show_scene_anim(scene) {
            show_scene(scene, true);
        }

        // Pull download link from the download button and add to the
        // 'click here' link.
        // TODO: Remove and generate link in bedrock.
        $('#direct-download-link').attr(
            'href', $('.download-list li:visible .download-link').attr('href')
        );

        $stage.on('click', '#direct-download-link, .download-link', function(e) {
            e.preventDefault();
            var url = $(e.currentTarget).attr('href');
<commit_msg>[fix bug 1164295] Add pixel to /new for downloads<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

;(function($, Modernizr, dataLayer, site) {
    'use strict';

    var $window = $(window);
    var $document = $(document);

    var uiTourSendEvent = function(action, data) {
        var event = new CustomEvent('mozUITour', {
            bubbles: true,
            detail: {
                action: action,
                data: data || {}
            }
        });

        document.dispatchEvent(event);
    };

    var uiTourGetConfiguration = function(configName, callback) {
        uiTourSendEvent('getConfiguration', {
            configuration: configName,
            callbackID: function() {
                var id = Math.random().toString(36).replace(/[^a-z]+/g, '');

                function listener(event) {
                    if (typeof event.detail === 'object' && event.detail.callbackID === id) {
                        document.removeEventListener('mozUITourResponse', listener);
                        callback(event.detail.data);
                    }
                }

                document.addEventListener('mozUITourResponse', listener);

                return id;
            }.call()
        });
    };

    var isIELT9 = (site.platform === 'windows' && /MSIE\s[1-8]\./.test(navigator.userAgent));
    var path_parts = window.location.pathname.split('/');
    var query_str = window.location.search ? window.location.search + '&' : '?';
    var params = new _SearchParams();
    var referrer = path_parts[path_parts.length - 2];
    var locale = path_parts[1];
    var virtual_url = ('/' + locale + '/products/download.html' +
                       query_str + 'referrer=' + referrer);

    var pixelAdded = false;

    var $html = $(document.documentElement);

    if (isFirefox()) {
        // data-latest-firefox includes point release information
        var latestFirefoxVersionFull = $html.attr('data-latest-firefox');

        // get latest full version (no point release info) for initial check
        var latestFirefoxVersion = parseInt(latestFirefoxVersionFull.split('.')[0], 10);

        if (isFirefoxUpToDate(latestFirefoxVersion + '')) {
            if (window.location.hash !== '#download-fx' && params.get('scene') !== 2) {
                // the firefox-latest class prevents the download from triggering
                // and scene 2 from showing, which we want if the user lands on
                // /firefox/new/ but if the user visits /firefox/new/?scene=2#download-fx
                // (from a download button) then we want them to see the same scene 2
                // as non-firefox users and initiate a download
                $html.addClass('firefox-latest');

                // if user is on release channel and has latest version, offer refresh button
                uiTourGetConfiguration('appinfo', function(config) {
                    if (config.defaultUpdateChannel === 'release' && config.version === latestFirefoxVersionFull) {
                        $html.addClass('show-refresh');

                        // DOM may not be ready yet, so bind filtered click handler to document
                        $document.on('click', '#refresh-firefox', function() {
                            uiTourSendEvent('resetFirefox');
                        });
                    }
                });
            }
        } else {
            $html.addClass('firefox-old');
        }
    }

    // scene2 install images are unique for IE < 9
    if (isIELT9) {
        $html.addClass('winIE8');
    }

    // Add GA custom tracking and external link tracking
    var state = 'Desktop, not Firefox';
    if (site.platform === 'android') {
        if ($html.hasClass('firefox-latest')) {
            state = 'Android, Firefox up-to-date';
        } else if ($html.hasClass('firefox-old')) {
            state = 'Android, Firefox not up-to-date';
        } else {
            state = 'Android, not Firefox';
        }
    } else if (site.platform === 'ios') {
        state = 'iOS, Firefox not supported';
    } else if (site.platform === 'fxos') {
        state = 'FxOS';
    } else {
        if ($html.hasClass('firefox-latest')) {
            state = 'Desktop, Firefox up-to-date';
        } else if ($html.hasClass('firefox-old')) {
            state = 'Desktop, Firefox not up-to-date';
        }
    }
    //GA Custom Dimension in Pageview
    window.dataLayer.push({
        event: 'set-state',
        state: state
    });

    // conditions in which scene2 should not be shown, even when the
    // #download-fx hash is set
    var no_scene2 = (
           site.platform === 'other'    // no download available
        || site.platform === 'ios'      // unsupported platform
        || site.platform === 'fxos'     // no download available
        || site.platform === 'android'  // download goes to Play Store
    );

    $document.ready(function() {
        var $scene1 = $('#scene1');
        var $stage = $('#stage-firefox');
        var $thankYou = $('.thankyou');
        var hash_change = ('onhashchange' in window);

        // if desktop with download available, re-locate dl button links
        if (!no_scene2 && $('.download-button-wrapper:visible').length > 0) {
            var $downloadButtonLinks = $('.download-button-wrapper .download-other-desktop').detach();
            $downloadButtonLinks.css('display', 'block').insertBefore('#firefox-screenshot');
        }

        if (site.platform === 'android') {
            $('#download-button-android .download-subtitle').html(
                $('.android.download-button-wrapper').data('upgradeSubtitle'));

            // On Android, skip all the scene transitions. We're just linking
            // to the Play Store.
            return;
        }

        function show_scene(scene, animate) {
            if (animate) {
                $stage.removeClass('stage-no-anim');
            } else {
                $stage.addClass('stage-no-anim');
            }

            var CSSbottom = (scene === 2) ? '-420px' : 0;
            $stage.data('scene', scene);
            $('.scene').css('visibility', 'visible');
            if (!Modernizr.csstransitions && animate) {
                $stage.animate({
                    bottom: CSSbottom
                }, 400);
            } else {
                $stage.toggleClass('scene2');
            }
            if (scene === 2) {
                // after animation, hide scene1 so it's not focusable and
                // reset focus
                setTimeout(function() {
                    $scene1.css('visibility', 'hidden');
                    $thankYou.focus();
                }, 500);
                // Added measurements fire only when the download is fired
                if (!pixelAdded) {
                    pixelAdded = true;
                    spring_campaign_measurement();
                }
            }
        }

        function show_scene_anim(scene) {
            show_scene(scene, true);
        }

        // Pixel to be removed on July 31st, 2015 (Bug 1168440)
        function spring_campaign_measurement () {
            var _dntStatus = navigator.doNotTrack || navigator.msDoNotTrack;
            var fxMatch = navigator.userAgent.match(/Firefox\/(\d+)/);
            var ie10Match = navigator.userAgent.match(/MSIE 10/i);
            var w8Match = navigator.appVersion.match(/Windows NT 6.2/);

            if (fxMatch && Number(fxMatch[1]) < 32) {
                // Can't say for sure if it is 1 or 0, due to Fx bug 887703
                _dntStatus = 'Unspecified';
            } else if (ie10Match && w8Match) {
                // IE10 on Windows 8 does not Enable based on user intention
                _dntStatus = 'Unspecified';
            } else {
                _dntStatus = { '0': 'Disabled', '1': 'Enabled' }[_dntStatus] || 'Unspecified';
            }

            if (_dntStatus !== 'Enabled'){
                var $body = $('body');
                var $pixel = $('<img />', {
                    width: '1',
                    height: '1',
                    src: 'https://servedby.flashtalking.com/spot/8/6247;40428;4669/?spotName=Mozilla_Download_Conversion'
                });
                $body.append($pixel);
            }
        }

        // Pull download link from the download button and add to the
        // 'click here' link.
        // TODO: Remove and generate link in bedrock.
        $('#direct-download-link').attr(
            'href', $('.download-list li:visible .download-link').attr('href')
        );

        $stage.on('click', '#direct-download-link, .download-link', function(e) {
            e.preventDefault();
            var url = $(e.currentTarget).attr('href');

{'fraction_non_alphanumeric': 0.1319990176817289, 'fraction_numerical': 0.009086444007858546, 'mean_word_length': 1.7441037735849056, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 57, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1515534', 'n_tokens_mistral': 4517, 'n_tokens_neox': 4189, 'n_words': 1133}