From 0c118fe8c945d2a5735cd6050269aae39a97068d Mon Sep 17 00:00:00 2001 From: DualFroz Date: Wed, 2 Sep 2026 20:54:16 +0200 Subject: [PATCH] feat(javascripts): add application --- examples/blog/app/assets/javascripts/application.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 examples/blog/app/assets/javascripts/application.js diff --git a/examples/blog/app/assets/javascripts/application.js b/examples/blog/app/assets/javascripts/application.js new file mode 100644 index 0000000..457755a --- /dev/null +++ b/examples/blog/app/assets/javascripts/application.js @@ -0,0 +1,12 @@ +// Rails-UJS-lite: any element with a data-confirm attribute (button_to +// destroy links generate one, see app/views/posts/_post.erb) pops a native +// confirm() dialog before its click is allowed to reach the form submit; +// cancelling the dialog cancels the click. +document.addEventListener("click", function (event) { + var target = event.target.closest("[data-confirm]"); + if (!target) return; + if (!window.confirm(target.getAttribute("data-confirm"))) { + event.preventDefault(); + event.stopPropagation(); + } +});