Sha256: eeeec8cd4ea8f5d636085b53b0b77738fec3cff6d1804acf2cf891ffa1e881b0

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

document.addEventListener("DOMContentLoaded", () => {
  const form = document.querySelector("form.awesome-edit-config");
  if (form) {
    form.querySelectorAll("input, textarea, select").forEach((el) => {
      el.addEventListener("change", () => {
        form.dataset.changed = true;
      });
    });

    const safePath = form.dataset.safePath.split("?")[0];
    document.querySelectorAll("a").forEach((el) => {
      el.addEventListener("click", () => {
        window.exitUrl = el.href;
      });
    });
    document.querySelectorAll("form").forEach((el) => {
      el.addEventListener("submit", () => {
        window.exitUrl = el.action;
      });
    });
    document.querySelectorAll('[type="submit"]').forEach((el) => {
      el.addEventListener("click", () => {
        window.exitUrl = el.form.action;
      });
    });

    window.addEventListener("beforeunload", (event) => {
      const exitUrl = window.exitUrl;
      const hasChanged = form.dataset.changed;
      window.exitUrl = null;

      if (!hasChanged || (exitUrl && exitUrl.includes(safePath))) {
        return null;
      }

      event.returnValue = true;
      return true;
    });
  }
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
decidim-decidim_awesome-0.11.2 app/packs/src/decidim/decidim_awesome/admin/form_exit_warn.js
decidim-decidim_awesome-0.11.1 app/packs/src/decidim/decidim_awesome/admin/form_exit_warn.js