"use strict";

$(() => {
    // This code will be executed when the user visits /login and
    // dev_login.html is rendered.
    if ($("[data-page-id='dev-login']").length > 0) {
        if (window.location.hash.substring(0, 1) === "#") {
            /* We append the location.hash to the formaction so that URL can be
            preserved after user is logged in. See this:
            https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects */
            $("input[name='direct_email']").each(function () {
                const new_formaction = $(this).attr("formaction") + "/" + window.location.hash;
                $(this).attr("formaction", new_formaction);
            });
        }
    }
});

"use strict";

$(() => {
    // This code will be executed when the user visits /login and
    // dev_login.html is rendered.
    if ($("[data-page-id='dev-login']").length > 0) {
        if (window.location.hash.substring(0, 1) === "#") {
            /* We append the location.hash to the input field with name next so that URL can be
            preserved after user is logged in. See this:
            https://stackoverflow.com/questions/5283395/url-hash-is-persisting-between-redirects */
            $("input[name='next']").each(function () {
                const new_value = $(this).attr("value") + window.location.hash;
                $(this).attr("value", new_value);
            });
        }
    }
});

Fix handling of fragments in the URL.
devlogin: Fix handling of fragments in the URL.

When a fragment (i.e. section starting with `#`) is present in the URL
when landing the development login page, dev-login.js used to append
it to the appends it to the `formaction` attribute of all the input
tag present in the `dev_login.html`.

This made sense before 139cb8026f7310e1cca53fbed5609f8d7e85dc37, which
adjusted the structure of how `next` was passed.

To fix this, we adjust the JavaScript login to set the `next` hidden
input instead.

fixes #16215
