From 358968cd28b23c79a9311b5f88dce14fed686e97 Mon Sep 17 00:00:00 2001
From: Jeremy Kemper <jeremy@bitsweat.net>
Date: Thu, 4 Feb 2010 17:46:29 -0800
Subject: Update prototype-ujs for data-confirm

---
 .../rails/app/templates/public/javascripts/rails.js     | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

(limited to 'railties/lib/generators/rails')

diff --git a/railties/lib/generators/rails/app/templates/public/javascripts/rails.js b/railties/lib/generators/rails/app/templates/public/javascripts/rails.js
index 2a0a05d25f..8e2e0d259d 100644
--- a/railties/lib/generators/rails/app/templates/public/javascripts/rails.js
+++ b/railties/lib/generators/rails/app/templates/public/javascripts/rails.js
@@ -34,6 +34,12 @@ document.observe("dom:loaded", function() {
   }
 
   $(document.body).observe("click", function(event) {
+    var message = event.element().readAttribute('data-confirm');
+    if (message && !confirm(message)) {
+      event.stop();
+      return false;
+    }
+
     var element = event.findElement("a[data-remote=true]");
     if (element) {
       handleRemote(element);
@@ -41,13 +47,14 @@ document.observe("dom:loaded", function() {
     }
   });
 
-  $(document.body).observe("ajax:before", function(event) {
-    var message = event.element().readAttribute('data-confirm');
-    if (message && !confirm(message)) event.stop();
-  });
-
   // TODO: I don't think submit bubbles in IE
   $(document.body).observe("submit", function(event) {
+    var message = event.element().readAttribute('data-confirm');
+    if (message && !confirm(message)) {
+      event.stop();
+      return false;
+    }
+
     var inputs = event.element().select("input[type=submit][data-disable-with]");
     inputs.each(function(input) {
       input.disabled = true;
-- 
cgit v1.2.3