<commit_before>const $$ = {
    on: function (root, eventName, selector, fn) {
        root.addEventListener(eventName, function (event) {
            const target = event.target.closest(selector);
            if (root.contains(target)) {
                fn.call(target, event);
            }
        });
    },
    show: function (element) {
        element.classList.remove("djdt-hidden");
    },
    hide: function (element) {
        element.classList.add("djdt-hidden");
    },
    toggle: function (element, value) {
        if (value) {
            $$.show(element);
        } else {
            $$.hide(element);
        }
    },
    visible: function (element) {
        element.classList.contains("djdt-hidden");
    },
    executeScripts: function (scripts) {
        scripts.forEach(function (script) {
            const el = document.createElement("script");
            el.type = "module";
            el.src = script;
            el.async = true;
            document.head.appendChild(el);
        });
    },
};

const onKeyDown = function (event) {
    if (event.keyCode === 27) {
        djdt.hide_one_level();
    }
};

const ajax = function (url, init) {
    init = Object.assign({ credentials: "same-origin" }, init);
    return fetch(url, init).then(function (response) {
        if (response.ok) {
            return response.json();
        } else {
            const win = document.querySelector("#djDebugWindow");
            win.innerHTML =
                '<div class="djDebugPanelTitle"><a class="djDebugClose" href="">»</a><h3>' +
                response.status +
                ": " +
                response.statusText +
                "</h3></div>";
            $$.show(win);
            return Promise.reject();
        }
    });
};

function ajaxForm(element) {
    const form = element.closest("form");
    const url = new URL(form.action);
    const formData = new FormData(form);
    for (const [name, value] of formData.entries()) {
        url.searchParams.append(name, value);
    }
    const ajaxData = {
        method: form.method.toUpperCase(),
    };
    return ajax(url, ajaxData);
}

const djdt = {
    handleDragged: false,
    init: function () {
        const djDebug = document.querySelector("#djDebug");
        $$.show(djDebug);
        $$.on(
            djDebug.querySelector("#djDebugPanelList"),
            "click",
            "li a",
            function (event) {
                event.preventDefault();
                if (!this.className) {
                    return;
                }
                const current = djDebug.querySelector("#" + this.className);
                if ($$.visible(current)) {
                    djdt.hide_panels();
                } else {
                    djdt.hide_panels();

                    $$.show(current);
                    this.parentElement.classList.add("djdt-active");

                    const inner = current.querySelector(
                            ".djDebugPanelContent .djdt-scroll"
                        ),
                        store_id = djDebug.dataset.storeId;
                    if (store_id && inner.children.length === 0) {
                        let url = djDebug.dataset.renderPanelUrl;
                        const url_params = new URLSearchParams();
                        url_params.append("store_id", store_id);
                        url_params.append("panel_id", this.className);
                        url += "?" + url_params.toString();
                        ajax(url).then(function (data) {<commit_msg>Simplify URL building using the URL class (#1355)<commit_after>const $$ = {
    on: function (root, eventName, selector, fn) {
        root.addEventListener(eventName, function (event) {
            const target = event.target.closest(selector);
            if (root.contains(target)) {
                fn.call(target, event);
            }
        });
    },
    show: function (element) {
        element.classList.remove("djdt-hidden");
    },
    hide: function (element) {
        element.classList.add("djdt-hidden");
    },
    toggle: function (element, value) {
        if (value) {
            $$.show(element);
        } else {
            $$.hide(element);
        }
    },
    visible: function (element) {
        element.classList.contains("djdt-hidden");
    },
    executeScripts: function (scripts) {
        scripts.forEach(function (script) {
            const el = document.createElement("script");
            el.type = "module";
            el.src = script;
            el.async = true;
            document.head.appendChild(el);
        });
    },
};

const onKeyDown = function (event) {
    if (event.keyCode === 27) {
        djdt.hide_one_level();
    }
};

const ajax = function (url, init) {
    init = Object.assign({ credentials: "same-origin" }, init);
    return fetch(url, init).then(function (response) {
        if (response.ok) {
            return response.json();
        } else {
            const win = document.querySelector("#djDebugWindow");
            win.innerHTML =
                '<div class="djDebugPanelTitle"><a class="djDebugClose" href="">»</a><h3>' +
                response.status +
                ": " +
                response.statusText +
                "</h3></div>";
            $$.show(win);
            return Promise.reject();
        }
    });
};

function ajaxForm(element) {
    const form = element.closest("form");
    const url = new URL(form.action);
    const formData = new FormData(form);
    for (const [name, value] of formData.entries()) {
        url.searchParams.append(name, value);
    }
    const ajaxData = {
        method: form.method.toUpperCase(),
    };
    return ajax(url, ajaxData);
}

const djdt = {
    handleDragged: false,
    init: function () {
        const djDebug = document.querySelector("#djDebug");
        $$.show(djDebug);
        $$.on(
            djDebug.querySelector("#djDebugPanelList"),
            "click",
            "li a",
            function (event) {
                event.preventDefault();
                if (!this.className) {
                    return;
                }
                const current = djDebug.querySelector("#" + this.className);
                if ($$.visible(current)) {
                    djdt.hide_panels();
                } else {
                    djdt.hide_panels();

                    $$.show(current);
                    this.parentElement.classList.add("djdt-active");

                    const inner = current.querySelector(
                            ".djDebugPanelContent .djdt-scroll"
                        ),
                        store_id = djDebug.dataset.storeId;
                    if (store_id && inner.children.length === 0) {
                        let url = new URL(djDebug.dataset.renderPanelUrl, window.location);
                        url.searchParams.append("store_id", store_id);
                        url.searchParams.append("panel_id", this.className);
                        ajax(url).then(function (data) {
{'fraction_non_alphanumeric': 0.1343051231248231, 'fraction_numerical': 0.0019813189923577695, 'mean_word_length': 1.5791970802919708, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 15, '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': '7384215', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1854, 'n_words': 367}