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!