{"size": 3150, "ext": "js", "max_stars_repo_path": "Official Windows Platform Sample/Windows 8.1 Store app samples/[JavaScript]-Windows 8.1 Store app samples/HTML independent animations sample/JavaScript/js/scenario1.js", "max_stars_repo_name": "zzgchina888/msdn-code-gallery-microsoft", "max_stars_repo_stars_event_min_datetime": "2022-01-21T01:40:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-21T01:41:10.000Z", "max_issues_repo_path": "Official Windows Platform Sample/Windows 8.1 Store app samples/[JavaScript]-Windows 8.1 Store app samples/HTML independent animations sample/JavaScript/js/scenario1.js", "max_issues_repo_name": "zzgchina888/msdn-code-gallery-microsoft", "max_issues_repo_issues_event_min_datetime": "2022-03-15T04:21:41.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-15T04:21:41.000Z", "max_forks_repo_path": "Official Windows Platform Sample/Windows 8.1 Store app samples/[JavaScript]-Windows 8.1 Store app samples/HTML independent animations sample/JavaScript/js/scenario1.js", "max_forks_repo_name": "zzgchina888/msdn-code-gallery-microsoft", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 29.7169811321, "max_line_length": 100, "alphanum_fraction": 0.6333333333}
﻿//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved

(function () {
    "use strict";
    var page = WinJS.UI.Pages.define("/html/scenario1.html", {
        ready: function (element, options) {
            document.getElementById("scenario1Open").addEventListener("click", runscenario1, false);

            var range = document.getElementById('counterRange');
            range.value = uiThreadWorkHighRange;

            range.addEventListener("change", function () { uiThreadWorkHighRange = range.value; });
        }, unload: function () {
            stopUiThreadWork();
        }

        
    });

    var startButtonText = "Run Scenario 1", stopButtonText = "Stop";

    var uiThreadWorkHighRange = 0;

    var continueUiThreadWork = false;

    function runscenario1() {
        var button = document.getElementById("scenario1Open");

        if (button.innerText === startButtonText) {

            button.innerText = stopButtonText;

            startUiThreadWork();

            var IndependentAnimationelement = document.getElementById("IndependentAnimationBall");
            var DependentAnimation = document.getElementById("DependentAnimationBall");

            IndependentAnimationelement.className = 'ball';
            DependentAnimation.className = 'ball';
            IndependentAnimationelement.style.animationPlayState = 'running';
            DependentAnimation.style.animationPlayState = 'running';

        } else {

            button.innerText = startButtonText;
            resetScenario1();
        }
    }

    function startUiThreadWork() {

        continueUiThreadWork = true;

        window.requestAnimationFrame(doWork);
    }

    function stopUiThreadWork() {

        continueUiThreadWork = false;

    }

    function doWork() {

        var startTime = new Date().getTime();

        while (new Date().getTime() - startTime < uiThreadWorkHighRange) { }

        if (continueUiThreadWork) {
            var awakeTime = 250 - uiThreadWorkHighRange;
            setTimeout(doWork, awakeTime);
        }
    }

    function setDependencyLabel(targetLabel, elementClass) {

        var element = document.querySelector(elementClass);

        if (window.console.msIsIndependentlyComposed) {
            if (window.console.msIsIndependentlyComposed(element)) {
                targetLabel.textContent = "Independent";
            }
            else {
                targetLabel.textContent = "Dependent";
            }
        } else {
            targetLabel.textContent = "";
        }
    }


    function resetScenario1() {
        var IndependentAnimationelement = document.getElementById("IndependentAnimationBall");
        var DependentAnimation = document.getElementById("DependentAnimationBall");
        IndependentAnimationelement.className = 'ballstop';
        DependentAnimation.className = 'ballstop';
        stopUiThreadWork();
    }

})();
