{"version":3,"file":"ujs-DvFORZzB.js","sources":["../../../app/javascript/old_packs/common/ujs.js"],"sourcesContent":["document.addEventListener('DOMContentLoaded', () => {\n const csrfToken = document.querySelector('meta[name=\"csrf-token\"]')?.content;\n\n // ✅ `data-method=\"delete\"` の対応(リクエストを送らず、フォームを作成して送信)\n document.querySelectorAll('a[data-method]').forEach((link) => {\n link.addEventListener('click', (event) => {\n event.preventDefault();\n\n const method = link.dataset.method.toUpperCase();\n const url = link.getAttribute('href');\n const confirmMessage = link.dataset.confirm;\n\n // ✅ `data-confirm` の処理をここで実行(2重にならないように)\n if (confirmMessage && !window.confirm(confirmMessage)) {\n return;\n }\n\n // ✅ 動的にフォームを作成して `POST` 送信\n const form = document.createElement('form');\n form.action = url;\n form.method = 'POST';\n form.style.display = 'hidden';\n\n // ✅ `method` を `input[type=\"hidden\"]` で設定\n const methodInput = document.createElement('input');\n methodInput.type = 'hidden';\n methodInput.name = '_method';\n methodInput.value = method;\n form.appendChild(methodInput);\n\n // ✅ CSRFトークンを追加\n if (csrfToken) {\n const csrfInput = document.createElement('input');\n csrfInput.type = 'hidden';\n csrfInput.name = 'authenticity_token';\n csrfInput.value = csrfToken;\n form.appendChild(csrfInput);\n }\n\n document.body.appendChild(form);\n form.submit(); // ✅ `fetch()` ではなく、通常のフォーム送信を実行\n });\n });\n\n // ✅ `data-method` を持たない要素のみ `data-confirm` を適用(2回表示されないように)\n document.querySelectorAll('[data-confirm]:not([data-method])').forEach((element) => {\n element.addEventListener('click', (event) => {\n const message = element.dataset.confirm;\n if (!window.confirm(message)) {\n event.preventDefault();\n }\n });\n });\n\n // ✅ フォームの CSRF トークンを自動追加\n if (csrfToken) {\n document.querySelectorAll('form').forEach((form) => {\n if (!form.querySelector(\"input[name='authenticity_token']\")) {\n const input = document.createElement('input');\n input.type = 'hidden';\n input.name = 'authenticity_token';\n input.value = csrfToken;\n form.appendChild(input);\n }\n });\n }\n});\n"],"names":["_a","csrfToken","link","event","method","url","confirmMessage","form","method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