8f5553306c2cf7f4b14153f6117f8e9b

Definitely new to Ruby and using content tags, especially when there's a lot going on like in this case.

<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 !

F1e3ab214a976a39cfd713bc93deb10f

Tj Holowaychuk

April 16, 2009, April 16, 2009 19:58, permalink

No rating. Login to rate!

Learn ruby first, then rails :P IMO erb is really ugly, try out HAML maybe (also ugly, but less ugly)

8f5553306c2cf7f4b14153f6117f8e9b

Danny Peck

April 16, 2009, April 16, 2009 20:09, permalink

No rating. Login to rate!

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)%>
8f5553306c2cf7f4b14153f6117f8e9b

Danny Peck

April 16, 2009, April 16, 2009 20:33, permalink

No rating. Login to rate!

@Tj Holowaychuk I don't have a choice here.

A8d3f35baafdaea851914b17dae9e1fc

Adam

April 16, 2009, April 16, 2009 23:12, permalink

2 ratings. Login to rate!
<% 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();
  });
});
8f5553306c2cf7f4b14153f6117f8e9b

Danny Peck

April 23, 2009, April 23, 2009 22:31, permalink

No rating. Login to rate!

thank you for the help.

Your refactoring





Format Copy from initial code

or Cancel