<commit_before>$(document).ready(function () {
    //Update the language on the page using the browser's locale
    update_lang(get_locale());

    //If the app is running from PhoneGap than handle unique events
    if (window.cordova) {
        $(document).one("deviceready", function() {
            var win = $(window);
            //If portrait mode (checked since plugin has a bug in landscape)
            if (win.height() > win.width()) {
                try {
                    //Change the status bar to match the headers
                    StatusBar.overlaysWebView(false);
                    StatusBar.styleLightContent();
                    StatusBar.backgroundColorByHexString("#1C1C1C");
                } catch (err) {}
            }

            try {
                // Request the device's IP address
                networkinterface.getIPAddress(function(ip){
                    var chk = ip.split(".");
                    for(var i=0; i<chk.length; i++) {chk[i] = +chk[i];}

                    // Check if the IP is on a private network, if not don't enable automatic scanning
                    if (!(chk[0] == 10 || (chk[0] == 172 && chk[1] > 17 && chk[1] < 32) || (chk[0] == 192 && chk[1] == 168))) return;

                    //Change main menu items to reflect ability to automatically scan
                    var auto = $("#auto-scan"),
                        next = auto.next();

                    next.removeClass("ui-first-child").find("a.ui-btn").text(_("Manually Add Device"));
                    auto.show();

                    window.deviceip = ip;
                    window.devicesfound = [];
                    window.scanprogress = 1;
                });
            } catch (err) {}

            $(document).on("resume",function(){
                if (window.curr_ip === undefined) return;

                var page = $(".ui-page-active").attr("id"),
                    func = function(){};

                if (page == "status") {
                    func = get_status;
                } else if (page == "sprinklers") {
                    func = check_status;
                }

                update_controller(func,function(){
                    $("#footer-running").slideUp();
                    comm_error();
                });
            });

            $(document).on("pause",function(){
                //Remove any status timers that may be running
                if (window.interval_id !== undefined) clearInterval(window.interval_id);
                if (window.timeout_id !== undefined) clearTimeout(window.timeout_id);
            });
        });
    } else {
        //Show donate text in the about page
        $("#donate").show();

        //Insert the startup images for iOS since we are in a web app
        (function(){
            var p, l, r = window.devicePixelRatio, h = window.screen.height;
            if (navigator.platform === "iPad") {
                p = r === 2 ? "img/startup-tablet-portrait-retina.png" : "img/startup-tablet-portrait.png";
                l = r === 2 ? "img/startup-tablet-landscape-retina.png" : "img/startup-tablet-landscape.png";
                $('<link rel="apple-touch-startup-image" href="'+l+'" media="screen and (orientation: landscape)"><link rel="apple-touch-startup-image" href="'+p+'" media="screen and (orientation: portrait)">').appendTo("body");
            } else {
                p = r === 2 ? (h === 568 ? "img/startup-iphone5-retina.png" : "img/startup-retina.png") : "img/startup.png";
                $('<link rel="apple-touch-startup-image" href="'+p+'">').appendTo("body");
            }
        })();
    }
});

//Set AJAX timeout
$.ajaxSetup({
    timeout: 6000
});

//Handle timeout
$(document).ajaxError(function(x,t,m) {
    if(t.status==401) {
        showerror(_("Check device password and try again."));
    } else if (t.status===0) {
        if (/https?:\/\/[\d|.]+\/j\w/.exec(m.url)) {
            // Ajax fails typically because the password is wrong
            showerror(_("Check that the device is connected to the network and try again."));
        } else {
            // Ajax fails typically because the password is wrong
            showerror(_("Check device password and try again."));
        }
    }
    if(t.statusText==="timeout") {
        if (m.url.search("yahooapis.com") || m.url.search("api.wunderground.com")) {
            $("#weather-list").animate({
                "margin-left": "-1000px"
            },1000,function(){
                $(this).hide();
            });
        } else {
            showerror(_("Connection timed-out. Please try again."));
        }
    }
});

//After jQuery mobile is loaded set intial configuration
$(document).one("mobileinit", function(){
    $.mobile.defaultPageTransition = 'fade';
    $.mobile.hashListeningEnabled = false;
    $("#addnew, #site-select").enhanceWithin().popup();
    $("body").show();
});

$(document).one("pagebeforechange", function(event) {
    // Let the framework know we're going to handle the load.
    event.preventDefault();

    //On initial load check if a valid site exists for auto connect
    check_configured();

    //If a site is found then load it
    if (window.curr_ip !== undefined) newload();
    else changePage("#start");

});

$(document).on("pageshow",function(e){
    var newpage = "#"+e.target.id;

    // Render graph after the page is shown otherwise graphing function will fail
    if (newpage == "#preview") {
        //Use the user's local time for preview
        var now = new Date();
        $("#preview_date").val(now.toISOString().slice(0,10));
        get_preview();
    }

    // Bind all data-onclick events on current page to their associated function (removes 300ms delay)
    bind_links(newpage);
});

$(document).on("pagebeforeshow",function(e,data){
    var newpage = e.target.id,
        fromStart = ($(".ui-page-active").attr("id") == "start") ? 1 : 0;

    //Remove lingering tooltip from preview page
    $("#tooltip").remove();

    //Remove any status timers that may be running
    if (window.interval_id !== undefined) clearInterval(window.interval_id);
    if (window.timeout_id !== undefined) clearTimeout(window.timeout_id);

    if (!fromStart && newpage == "sprinklers") {
        //Reset status bar to loading while an update is done
        $("#footer-running").html("<p class='ui-icon ui-icon-loading mini-load'></p>");
        setTimeout(function(){
            update_controller(check_status,function(){
                $("#footer-running").slideUp();
                comm_error();
            });
        },800);
    }
});

//Update the preview page on date change
$("#preview_date").change(function(){
    var id = $(".ui-page-active").attr("id");<commit_msg>Base: Remove unused code<commit_after>$(document).ready(function () {
    //Update the language on the page using the browser's locale
    update_lang(get_locale());

    //If the app is running from PhoneGap than handle unique events
    if (window.cordova) {
        $(document).one("deviceready", function() {
            var win = $(window);
            //If portrait mode (checked since plugin has a bug in landscape)
            if (win.height() > win.width()) {
                try {
                    //Change the status bar to match the headers
                    StatusBar.overlaysWebView(false);
                    StatusBar.styleLightContent();
                    StatusBar.backgroundColorByHexString("#1C1C1C");
                } catch (err) {}
            }

            try {
                // Request the device's IP address
                networkinterface.getIPAddress(function(ip){
                    var chk = ip.split(".");
                    for(var i=0; i<chk.length; i++) {chk[i] = +chk[i];}

                    // Check if the IP is on a private network, if not don't enable automatic scanning
                    if (!(chk[0] == 10 || (chk[0] == 172 && chk[1] > 17 && chk[1] < 32) || (chk[0] == 192 && chk[1] == 168))) return;

                    //Change main menu items to reflect ability to automatically scan
                    var auto = $("#auto-scan"),
                        next = auto.next();

                    next.removeClass("ui-first-child").find("a.ui-btn").text(_("Manually Add Device"));
                    auto.show();

                    window.deviceip = ip;
                    window.devicesfound = [];
                    window.scanprogress = 1;
                });
            } catch (err) {}

            $(document).on("resume",function(){
                if (window.curr_ip === undefined) return;

                var page = $(".ui-page-active").attr("id"),
                    func = function(){};

                if (page == "status") {
                    func = get_status;
                } else if (page == "sprinklers") {
                    func = check_status;
                }

                update_controller(func,function(){
                    $("#footer-running").slideUp();
                    comm_error();
                });
            });

            $(document).on("pause",function(){
                //Remove any status timers that may be running
                if (window.interval_id !== undefined) clearInterval(window.interval_id);
                if (window.timeout_id !== undefined) clearTimeout(window.timeout_id);
            });
        });
    } else {
        //Show donate text in the about page
        $("#donate").show();

        //Insert the startup images for iOS since we are in a web app
        (function(){
            var p, l, r = window.devicePixelRatio, h = window.screen.height;
            if (navigator.platform === "iPad") {
                p = r === 2 ? "img/startup-tablet-portrait-retina.png" : "img/startup-tablet-portrait.png";
                l = r === 2 ? "img/startup-tablet-landscape-retina.png" : "img/startup-tablet-landscape.png";
                $('<link rel="apple-touch-startup-image" href="'+l+'" media="screen and (orientation: landscape)"><link rel="apple-touch-startup-image" href="'+p+'" media="screen and (orientation: portrait)">').appendTo("body");
            } else {
                p = r === 2 ? (h === 568 ? "img/startup-iphone5-retina.png" : "img/startup-retina.png") : "img/startup.png";
                $('<link rel="apple-touch-startup-image" href="'+p+'">').appendTo("body");
            }
        })();
    }
});

//Set AJAX timeout
$.ajaxSetup({
    timeout: 6000
});

//Handle timeout
$(document).ajaxError(function(x,t,m) {
    if(t.status==401) {
        showerror(_("Check device password and try again."));
    } else if (t.status===0) {
        if (/https?:\/\/[\d|.]+\/j\w/.exec(m.url)) {
            // Ajax fails typically because the password is wrong
            showerror(_("Check that the device is connected to the network and try again."));
        } else {
            // Ajax fails typically because the password is wrong
            showerror(_("Check device password and try again."));
        }
    }
    if(t.statusText==="timeout") {
        if (m.url.search("yahooapis.com") || m.url.search("api.wunderground.com")) {
            $("#weather-list").animate({
                "margin-left": "-1000px"
            },1000,function(){
                $(this).hide();
            });
        } else {
            showerror(_("Connection timed-out. Please try again."));
        }
    }
});

//After jQuery mobile is loaded set intial configuration
$(document).one("mobileinit", function(){
    $.mobile.defaultPageTransition = 'fade';
    $.mobile.hashListeningEnabled = false;
    $("#addnew, #site-select").enhanceWithin().popup();
    $("body").show();
});

$(document).one("pagebeforechange", function(event) {
    // Let the framework know we're going to handle the load.
    event.preventDefault();

    //On initial load check if a valid site exists for auto connect
    check_configured();

    //If a site is found then load it
    if (window.curr_ip !== undefined) newload();
    else changePage("#start");

});

$(document).on("pageshow",function(e){
    var newpage = "#"+e.target.id;

    // Render graph after the page is shown otherwise graphing function will fail
    if (newpage == "#preview") {
        //Use the user's local time for preview
        var now = new Date();
        $("#preview_date").val(now.toISOString().slice(0,10));
        get_preview();
    }

    // Bind all data-onclick events on current page to their associated function (removes 300ms delay)
    bind_links(newpage);
});

$(document).on("pagebeforeshow",function(e,data){
    var newpage = e.target.id,
        fromStart = ($(".ui-page-active").attr("id") == "start") ? 1 : 0;

    //Remove any status timers that may be running
    if (window.interval_id !== undefined) clearInterval(window.interval_id);
    if (window.timeout_id !== undefined) clearTimeout(window.timeout_id);

    if (!fromStart && newpage == "sprinklers") {
        //Reset status bar to loading while an update is done
        $("#footer-running").html("<p class='ui-icon ui-icon-loading mini-load'></p>");
        setTimeout(function(){
            update_controller(check_status,function(){
                $("#footer-running").slideUp();
                comm_error();
            });
        },800);
    }
});

//Update the preview page on date change
$("#preview_date").change(function(){
    var id = $(".ui-page-active").attr("id");
{'fraction_non_alphanumeric': 0.15539686081975748, 'fraction_numerical': 0.00892657888864093, 'mean_word_length': 1.957975797579758, 'pattern_counts': {'":': 2, '<': 17, '<?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': '5275408', 'n_tokens_mistral': 3844, 'n_tokens_neox': 3628, 'n_words': 953}