<span <% if level < max_level && r != ''%>
onmouseover="$('<%=row_id%>_plusminus').show();"
onmouseout="$('<%=row_id%>_plusminus').hide();"
<% end %>>
<img
onmouseover="removeClickEvent($('<%=row_id%>'))"
onmouseout="restoreClickEvent($('<%=row_id%>'))"
onclick="toggleGroup('<%=row_id %>')"
src="/images/minus.gif" id="<%=row_id%>_plusminus"
style="display:none;
<% if r[:children].blank?%>
visibility:hidden
<% end %>" />
<%=r[:group]%>
</span>
Refactorings
No refactoring yet !
Tj Holowaychuk
April 16, 2009, April 16, 2009 19:58, permalink
Learn ruby first, then rails :P IMO erb is really ugly, try out HAML maybe (also ugly, but less ugly)
Danny Peck
April 16, 2009, April 16, 2009 20:09, permalink
this is better. could probably still be refactored.
<%=
span_on_mouseover = ""
span_on_mouseout = ""
if level < max_level && r != ""
span_on_mouseover = "$('"+row_id+"_plusminus').show();"
span_on_mouseout = "$('"+row_id+"_plusminus').hide();"
end
img_on_mouseover = "removeClickEvent($('"+row_id+"'))"
img_on_mouseout = "restoreClickEvent($('"+row_id+"'))"
img_on_click = "toggleGroup('"+row_id+"')"
img_visibility_flag = "display:none"
img_visibility_flag = img_visibility_flag+";visibility:hidden" if r[:children].blank?
content_tag(:span, content_tag(:img, "",
:src => "/images/minus.gif",
:style => img_visibility_flag,
:onmouseover => img_on_mouseover,
:onmouseout => img_on_mouseout,
:onclick => img_on_click,
:id => row_id+"_plusminus")+r[:group],
:onmouseover => span_on_mouseover,
:onmouseout => span_on_mouseout)%>
Danny Peck
April 16, 2009, April 16, 2009 20:33, permalink
@Tj Holowaychuk I don't have a choice here.
Adam
April 16, 2009, April 16, 2009 23:12, permalink
<% content_tag_for(:span, group) do %> <%= image_tag 'minus.gif' %> <%=h group.name %> <% end %>
Event.observe(window, 'dom:loaded', function() {
$$('.group').each(function(element) {
var image = element.next('img');
element.onmouseover = function() { Element.show(image) };
element.onmouseout = function() { Element.hide(image) };
image.onmouseover = function() { removeClickEvent(element) };
image.onmouseout = function() { restoreClickEvent(element) };
image.onclick = function() { toggleGroup(element.id) };
image.hide();
});
});
Definitely new to Ruby and using content tags, especially when there's a lot going on like in this case.