<commit_before><?php
    define('JAVASCRIPT', true);
    require_once dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR."includes".DIRECTORY_SEPARATOR."common.php";
?>
$(function() {
    toggle_all();
    validate_slug();
    validate_email();
    validate_url();
    validate_passwords();
    confirm_submit();
    auto_submit();
    Help.init();
    Write.init();
    Settings.init();
    Extend.init();
});
// Adds a master toggle to forms that have multiple checkboxes.
function toggle_all() {
    $("form[data-toggler]").each(function() {
        var all_on = true;
        var target = $(this);
        var parent = $("#" + $(this).attr("data-toggler"));
        var slaves = target.find(":checkbox");
        var master = Date.now().toString(16);

        slaves.each(function() {
            return all_on = $(this).prop("checked");
        });

        slaves.click(function(e) {
            slaves.each(function() {
                return all_on = $(this).prop("checked");
            });

            $("#" + master).prop("checked", all_on);
        });

        parent.append(
            [$("<label>", {
                "for": master
            }).text('<?php echo __("Toggle All", "admin"); ?>'),
            $("<input>", {
                "type": "checkbox",
                "name": "toggle",
                "id": master,
                "class": "checkbox"
            }).prop("checked", all_on).click(function(e) {
                slaves.prop("checked", $(this).prop("checked"));
            })]
        );
    });
}
// Validates slug fields.
function validate_slug() {
    $("input[name='slug']").keyup(function(e) {
        if (/^([a-z0-9\-]*)$/.test($(this).val()))
            $(this).removeClass("error");
        else
            $(this).addClass("error");
    });
}
// Validates email fields.
function validate_email() {
    $("input[type='email']").keyup(function(e) {
        if ($(this).val() != "" && !isEmail($(this).val()))
            $(this).addClass("error");
        else
            $(this).removeClass("error");
    });
}
// Validates URL fields.
function validate_url() {
    $("input[type='url']").keyup(function(e) {
        if ($(this).val() != "" && !isURL($(this).val()))
            $(this).addClass("error");
        else
            $(this).removeClass("error");
    });
}
// Tests the strength of #password1 and compares #password1 to #password2.
function validate_passwords() {
    passwords = $("input[type='password']").filter(function(index) {
        var id = $(this).attr("id");
        return (!!id) ? id.match(/password[1-2]$/) : false ;
    });

    passwords.first().keyup(function(e) {
        if (passwordStrength($(this).val()) > 99)
            $(this).addClass("strong");
        else
            $(this).removeClass("strong");
    });

    passwords.keyup(function(e) {
        if (passwords.first().val() != "" && passwords.first().val() != passwords.last().val())
            passwords.last().addClass("error");
        else
            passwords.last().removeClass("error");
    });

    passwords.parents("form").on("submit", function(e) {
        if (passwords.first().val() != passwords.last().val()) {
            e.preventDefault();
            alert('<?php echo __("Passwords do not match."); ?>');
        }
    });
}
// Asks the user to confirm form submission.
function confirm_submit() {
    $("form[data-confirm]").submit(function(e) {
        var text = $(this).attr("data-confirm") || '<?php echo __("Are you sure you want to proceed?", "admin"); ?>' ;

        if (!confirm(text.replace(/<[^>]+>/g, "")))
            e.preventDefault();
    });
}
// Submit a form when an element changes.
function auto_submit() {
    $("select[data-submit], input[data-submit][type='checkbox']").on("change", function(e) {
        $(this).parents("form").submit();
    });
}
var Route = {
    action: '<?php if (isset($_GET['action'])) echo addslashes($_GET['action']); ?>'
}
var Visitor = {
    token: '<?php if (same_origin()) echo authenticate(); ?>'
}
var Site = {
    url: '<?php echo addslashes($config->url); ?>',
    chyrp_url: '<?php echo addslashes($config->chyrp_url); ?>',
    ajax: <?php echo($config->enable_ajax ? "true" : "false"); ?> 
}
var Help = {
    init: function() {
        $(".help").on("click", function(e) {
            e.preventDefault();
            Help.show($(this).attr("href"));
        });
    },
    show: function(href) {
        $("<div>", {
            "role": "region",
        }).addClass("iframe_background").append(
            [$("<iframe>", {
                "src": href
            }).addClass("iframe_foreground").loader().on("load", function() {
                $(this).loader(true);
            }),
            $("<a>", {
                "href": "#",
                "role": "button",
                "accesskey": "x",
                "aria-label": '<?php echo __("Close", "admin"); ?>'
            }).addClass("iframe_close_gadget").click(function(e) {
                e.preventDefault();
                $(this).parent().remove();
            }).append(
                $("<img>", {
                    "src": Site.chyrp_url + '/admin/images/icons/close.svg',
                    "alt": '<?php echo __("close", "admin"); ?>'
                })
            )]
        ).click(function(e) {
            if (e.target === e.currentTarget)
                $(this).remove();
        }).insertAfter("#content");
    }
}
var Write = {
    init: function() {
        // Insert buttons for ajax previews.
        if (<?php echo($theme->file_exists("content".DIR."preview") ? "true" : "false"); ?>)
            $("#write_form *[data-preview], #edit_form *[data-preview]").each(function() {
                var target = $(this);

                $("label[for='" + target.attr("id") + "']").append(
                    $("<a>", {
                        "href": "#",
                        "role": "button",
                        "aria-label": '<?php echo __("Preview", "admin"); ?>'
                    }).addClass("emblem preview").click(function(e) {
                        var content  = target.val();
                        var field    = target.attr("name");
                        var safename = $("input#feather").val() || "page";
                        var action   = (safename == "page") ? "preview_page" : "preview_post" ;

                        e.preventDefault();

                        if (content != "")
                            Write.show(action, safename, field, content);
                        else
                            target.focus();
                    }).append(
                        $("<img>", {
                            "src": Site.chyrp_url + '/admin/images/icons/magnifier.svg',
                            "alt": '(<?php echo __("preview", "admin"); ?>)'
                        })
                    )
                );
            });
    },
    show: function(action, safename, field, content) {
        var uid = Date.now().toString(16);

        // Build a form targeting a named iframe.
        $("<form>", {
            "id": uid,
            "action": Site.chyrp_url + "/ajax/",
            "method": "post",<commit_msg>Admin: fixed preview alt text<commit_after><?php
    define('JAVASCRIPT', true);
    require_once dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR."includes".DIRECTORY_SEPARATOR."common.php";
?>
$(function() {
    toggle_all();
    validate_slug();
    validate_email();
    validate_url();
    validate_passwords();
    confirm_submit();
    auto_submit();
    Help.init();
    Write.init();
    Settings.init();
    Extend.init();
});
// Adds a master toggle to forms that have multiple checkboxes.
function toggle_all() {
    $("form[data-toggler]").each(function() {
        var all_on = true;
        var target = $(this);
        var parent = $("#" + $(this).attr("data-toggler"));
        var slaves = target.find(":checkbox");
        var master = Date.now().toString(16);

        slaves.each(function() {
            return all_on = $(this).prop("checked");
        });

        slaves.click(function(e) {
            slaves.each(function() {
                return all_on = $(this).prop("checked");
            });

            $("#" + master).prop("checked", all_on);
        });

        parent.append(
            [$("<label>", {
                "for": master
            }).text('<?php echo __("Toggle All", "admin"); ?>'),
            $("<input>", {
                "type": "checkbox",
                "name": "toggle",
                "id": master,
                "class": "checkbox"
            }).prop("checked", all_on).click(function(e) {
                slaves.prop("checked", $(this).prop("checked"));
            })]
        );
    });
}
// Validates slug fields.
function validate_slug() {
    $("input[name='slug']").keyup(function(e) {
        if (/^([a-z0-9\-]*)$/.test($(this).val()))
            $(this).removeClass("error");
        else
            $(this).addClass("error");
    });
}
// Validates email fields.
function validate_email() {
    $("input[type='email']").keyup(function(e) {
        if ($(this).val() != "" && !isEmail($(this).val()))
            $(this).addClass("error");
        else
            $(this).removeClass("error");
    });
}
// Validates URL fields.
function validate_url() {
    $("input[type='url']").keyup(function(e) {
        if ($(this).val() != "" && !isURL($(this).val()))
            $(this).addClass("error");
        else
            $(this).removeClass("error");
    });
}
// Tests the strength of #password1 and compares #password1 to #password2.
function validate_passwords() {
    passwords = $("input[type='password']").filter(function(index) {
        var id = $(this).attr("id");
        return (!!id) ? id.match(/password[1-2]$/) : false ;
    });

    passwords.first().keyup(function(e) {
        if (passwordStrength($(this).val()) > 99)
            $(this).addClass("strong");
        else
            $(this).removeClass("strong");
    });

    passwords.keyup(function(e) {
        if (passwords.first().val() != "" && passwords.first().val() != passwords.last().val())
            passwords.last().addClass("error");
        else
            passwords.last().removeClass("error");
    });

    passwords.parents("form").on("submit", function(e) {
        if (passwords.first().val() != passwords.last().val()) {
            e.preventDefault();
            alert('<?php echo __("Passwords do not match."); ?>');
        }
    });
}
// Asks the user to confirm form submission.
function confirm_submit() {
    $("form[data-confirm]").submit(function(e) {
        var text = $(this).attr("data-confirm") || '<?php echo __("Are you sure you want to proceed?", "admin"); ?>' ;

        if (!confirm(text.replace(/<[^>]+>/g, "")))
            e.preventDefault();
    });
}
// Submit a form when an element changes.
function auto_submit() {
    $("select[data-submit], input[data-submit][type='checkbox']").on("change", function(e) {
        $(this).parents("form").submit();
    });
}
var Route = {
    action: '<?php if (isset($_GET['action'])) echo addslashes($_GET['action']); ?>'
}
var Visitor = {
    token: '<?php if (same_origin()) echo authenticate(); ?>'
}
var Site = {
    url: '<?php echo addslashes($config->url); ?>',
    chyrp_url: '<?php echo addslashes($config->chyrp_url); ?>',
    ajax: <?php echo($config->enable_ajax ? "true" : "false"); ?> 
}
var Help = {
    init: function() {
        $(".help").on("click", function(e) {
            e.preventDefault();
            Help.show($(this).attr("href"));
        });
    },
    show: function(href) {
        $("<div>", {
            "role": "region",
        }).addClass("iframe_background").append(
            [$("<iframe>", {
                "src": href
            }).addClass("iframe_foreground").loader().on("load", function() {
                $(this).loader(true);
            }),
            $("<a>", {
                "href": "#",
                "role": "button",
                "accesskey": "x",
                "aria-label": '<?php echo __("Close", "admin"); ?>'
            }).addClass("iframe_close_gadget").click(function(e) {
                e.preventDefault();
                $(this).parent().remove();
            }).append(
                $("<img>", {
                    "src": Site.chyrp_url + '/admin/images/icons/close.svg',
                    "alt": '<?php echo __("close", "admin"); ?>'
                })
            )]
        ).click(function(e) {
            if (e.target === e.currentTarget)
                $(this).remove();
        }).insertAfter("#content");
    }
}
var Write = {
    init: function() {
        // Insert buttons for ajax previews.
        if (<?php echo($theme->file_exists("content".DIR."preview") ? "true" : "false"); ?>)
            $("#write_form *[data-preview], #edit_form *[data-preview]").each(function() {
                var target = $(this);

                $("label[for='" + target.attr("id") + "']").append(
                    $("<a>", {
                        "href": "#",
                        "role": "button",
                        "aria-label": '<?php echo __("Preview", "admin"); ?>'
                    }).addClass("emblem preview").click(function(e) {
                        var content  = target.val();
                        var field    = target.attr("name");
                        var safename = $("input#feather").val() || "page";
                        var action   = (safename == "page") ? "preview_page" : "preview_post" ;

                        e.preventDefault();

                        if (content != "")
                            Write.show(action, safename, field, content);
                        else
                            target.focus();
                    }).append(
                        $("<img>", {
                            "src": Site.chyrp_url + '/admin/images/icons/magnifier.svg',
                            "alt": '<?php echo __("preview", "admin"); ?>'
                        })
                    )
                );
            });
    },
    show: function(action, safename, field, content) {
        var uid = Date.now().toString(16);

        // Build a form targeting a named iframe.
        $("<form>", {
            "id": uid,
            "action": Site.chyrp_url + "/ajax/",
            "method": "post",
{'fraction_non_alphanumeric': 0.20240244410498542, 'fraction_numerical': 0.00180530481877517, 'mean_word_length': 1.8246715042165131, 'pattern_counts': {'":': 44, '<': 51, '<?xml version=': 0, '>': 63, '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': '495167', 'n_tokens_mistral': 4163, 'n_tokens_neox': 4034, 'n_words': 751}