Using the following snippet of code to get an image with a mouseover image:

<%= image_tag("button_off.png", :mouseover => "button_on.png", :alt => 
:button) %>

Generates inline JavaScript to do the image swapping like so:

<img alt="button" onmouseout="this.src='/assets/button_off.png'" 
onmouseover="this.src='/assets/button_on.png'" src="/assets/button_off.png" 
/>

It's possible (and very simple) to do the image swapping in an UJS manner:

<img alt="button" data-mouseover="/assets/button_on.png" 
src="/assets/button_off.png" />

With the supporting jQuery snippet:

$('img[data-mouseover]').hover(
  function() {
    $(this).data('_mouseover', $(this).attr('src'));      
    $(this).attr('src', $(this).data('mouseover'));
  }, 
  function() { 
    $(this).attr('src', $(this).data('_mouseover'));
  }
);

Is there any specific reason I'm not aware of that Rails still uses inline 
JavaScript for this? Would there be any reception if I were to submit a pull 
request for this? Never contributed to rails before so I'm not sure. Thanks!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-core/-/dCJvxtgOui4J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to