
// jquery ujs hack for remote ajax button
$(document).on("mouseup", "button[data-remote]", function(e) {
  // middle button click
  if(e.which == 2) {
    $(e.currentTarget).trigger("click.rails")
  }
});

// jquery ujs hack for form restful button
$(document).on("click.rails", "button[data-method]", function(e) {
  button = $(e.currentTarget)

  var url = button.data("url"),
    method = button.data('method'),
    target = button.data('target'),
    csrf_token = $('meta[name=csrf-token]').attr('content'),
    csrf_param = $('meta[name=csrf-param]').attr('content'),
    form = $('<form method="post" action="' + url + '"></form>'),
    metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';

  if (csrf_param !== undefined && csrf_token !== undefined) {
    metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
  }

  if (target) { form.attr('target', target); }

  form.hide().append(metadata_input).appendTo('body');
  form.submit();

});

@@ -1,29 +1,44 @@
-%0A
+(function() %7B%0A  
 // jquery ujs hack for remot
@@ -43,32 +43,34 @@
 ote ajax button%0A
+  
 $(document).on(%22
@@ -112,24 +112,26 @@
 nction(e) %7B%0A
+  
   // middle 
@@ -143,16 +143,18 @@
 n click%0A
+  
   if(e.w
@@ -170,16 +170,18 @@
 ) %7B%0A    
+ 
+ 
 $(e.curr
@@ -220,15 +220,181 @@
 )%0A  
-%7D%0A%7D);%0A%0A
+  %7D%0A  %7D);%0A%0A  $(document).on(%22click.rails%22, %22button%5Bdata-method%5D%22, function(e) %7B%0A    if (!$.rails.allowAction($(e.currentTarget))) return $.rails.stopEverything(e);%0A  %7D);%0A%0A  
 // j
@@ -432,16 +432,18 @@
  button%0A
+  
 $(docume
@@ -501,16 +501,18 @@
 on(e) %7B%0A
+  
   button
@@ -534,16 +534,18 @@
 arget)%0A%0A
+  
   var ur
@@ -572,16 +572,18 @@
 %22),%0A    
+  
 method =
@@ -610,16 +610,18 @@
 '),%0A    
+ 
+ 
 target =
@@ -640,24 +640,26 @@
 ('target'),%0A
+  
     csrf_tok
@@ -707,24 +707,26 @@
 tent'),%0A    
+ 
+ 
 csrf_param =
@@ -766,24 +766,26 @@
 'content'),%0A
+  
     form = $
@@ -838,24 +838,26 @@
 orm%3E'),%0A    
+  
 metadata_inp
@@ -927,16 +927,18 @@
 %22 /%3E';%0A%0A
+  
   if (cs
@@ -991,24 +991,26 @@
 ined) %7B%0A    
+  
 metadata_inp
@@ -1097,19 +1097,23 @@
  /%3E';%0A  
+ 
+ 
 %7D%0A%0A
+  
   if (ta
@@ -1154,16 +1154,18 @@
 ); %7D%0A%0A  
+ 
+ 
 form.hid
@@ -1209,16 +1209,18 @@
 body');%0A
+  
   form.s
@@ -1229,12 +1229,19 @@
 mit();%0A%0A
+  
 %7D);%0A
+%7D)();

refactor and debug for confirm msg