title: How can I override Rails 3 unobtrusive javascript functions without modifying the supplied rails.js?
body: <p>My Javascript isn't quite up to scratch and I'm struggling to override a function in the supplied <code>rails.js</code>.</p>
  
  <p>I want to modify the way that <code>a[data-confirm]</code> are handled, using a jQuery UI modal dialogue rather than the vanilla javascript <code>confirm()</code>.</p>
  
  <p>The relevant function in <code>rails.js</code> is <code>allowAction(element)</code>. If I define this in another file, I can call it from the firebug console successfully, but the <code>rails.js</code> version is still called from anchors with a <code>data-confirm</code> attribute.</p>
  
  <p>I think it's because the whole <code>rails.js</code> file is wrapped in:</p>
  
  <pre><code>(function($) {
  ...
  })( jQuery );
  </code></pre>
  
  <p>Is there a sensible way to override this function, <em>without</em> modifying the supplied <code>rails.js</code>?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>The call in <code>rails.js</code> to <code>allowAction</code> is wrapped in a <code>.live</code> call: </p>
  
  <pre><code>  $('a[data-confirm], a[data-method], a[data-remote]').live('click.rails', function(e) {
    var link = $(this);
    if (!allowAction(link)) return false;
  
    if (link.attr('data-remote')) {
      handleRemote(link);
      return false;
    } else if (link.attr('data-method')) {
      handleMethod(link);
      return false;
    }   
  });
  </code></pre>
  
  <p>I also tried including my javascript before and after the <code>rails.js</code>, to no avail.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>So, if I call <code>.die('click.rails')</code> I can then redefine the entire <code>click.rails</code> event, but the original <code>handleRemote()</code> and <code>handleMethod()</code> functions are not called.</p>