<% @entries.each do |entry| %>
<% tr_id = Digest::MD5.hexdigest(entry.path)
depth = params[:depth].to_i %>
-<tr id="<%= tr_id %>">
+<tr id="<%= tr_id %>" class="<%= params[:parent_id] %>">
<td>
<%= if entry.is_dir?
link_to_remote h(entry.name),
- {:url => {:action => 'browse', :id => @project, :path => entry.path, :rev => @rev, :depth => (depth + 1)},
+ {:url => {:action => 'browse', :id => @project, :path => entry.path, :rev => @rev, :depth => (depth + 1), :parent_id => tr_id},
:update => tr_id,
:position => :after,
- :success => "Element.addClassName('#{tr_id}', 'open');",
- :condition => "!Element.hasClassName('#{tr_id}', 'open')"
+ :success => "scmEntryLoaded('#{tr_id}')",
+ :condition => "scmEntryClick('#{tr_id}')"
},
{:href => url_for({:action => 'browse', :id => @project, :path => entry.path, :rev => @rev}),
:class => ('icon icon-folder'),
return false;
}
+function collapseScmEntry(id) {
+ var els = document.getElementsByClassName(id, 'browser');
+ for (var i = 0; i < els.length; i++) {
+ collapseScmEntry(els[i].id);
+ Element.hide(els[i]);
+ }
+ $(id).removeClassName('open');
+}
+
+function expandScmEntry(id) {
+ var els = document.getElementsByClassName(id, 'browser');
+ for (var i = 0; i < els.length; i++) {
+ Element.show(els[i]);
+ }
+ $(id).addClassName('open');
+}
+
+function scmEntryClick(id) {
+ el = $(id);
+ if (el.hasClassName('open')) {
+ collapseScmEntry(id);
+ return false;
+ } else if (el.hasClassName('loaded')) {
+ expandScmEntry(id);
+ return false;
+ }
+ return true;
+}
+
+function scmEntryLoaded(id) {
+ Element.addClassName(id, 'open');
+ Element.addClassName(id, 'loaded');
+}
+
/* shows and hides ajax indicator */
Ajax.Responders.register({
onCreate: function(){