Make expander indicator also a link to expand
Make expander indicator also a link to expand

file:a/js/tree.js -> file:b/js/tree.js
/* /*
* GitPHP javascript tree * GitPHP javascript tree
* *
* Load subtree data into tree page asynchronously * Load subtree data into tree page asynchronously
* *
* @author Christopher Han <xiphux@gmail.com> * @author Christopher Han <xiphux@gmail.com>
* @copyright Copyright (c) 2010 Christopher Han * @copyright Copyright (c) 2010 Christopher Han
* @package GitPHP * @package GitPHP
* @subpackage Javascript * @subpackage Javascript
*/ */
   
function initTree() { function initTree() {
var url = window.location.href.match(/^([^\?]+\/)/); var url = window.location.href.match(/^([^\?]+\/)/);
if (!url) { if (!url) {
return; return;
} }
url = url[1]; url = url[1];
   
var collapsed = '[+]'; var collapsed = '[+]';
var expanded = '[–]'; var expanded = '[–]';
   
$('table.treeTable td.expander').text(collapsed); $('a.jsTree').each(function() {
  var a = jQuery(document.createElement('a'));
  a.attr('href', $(this).attr('href'));
  a.text(collapsed);
  a.addClass('jsTree');
  a.addClass('expander');
  $(this).parent().parent().find('td.expander').append(a);
  });
   
$('a.jsTree').live('click', function() { $('a.jsTree').live('click', function() {
var treeHash = $(this).attr('href').match(/h=([0-9a-fA-F]{40}|HEAD)/); var treeHash = $(this).attr('href').match(/h=([0-9a-fA-F]{40}|HEAD)/);
if (!treeHash) { if (!treeHash) {
return; return;
} }
   
treeHash = treeHash[1]; treeHash = treeHash[1];
   
var cell = $(this).parent(); var cell = $(this).parent();
var row = cell.parent(); var row = cell.parent();
   
var treeRows = $('.' + treeHash); var treeRows = $('.' + treeHash);
if (treeRows && treeRows.size() > 0) { if (treeRows && treeRows.size() > 0) {
if (treeRows.is(':visible')) { if (treeRows.is(':visible')) {
treeRows.hide(); treeRows.hide();
treeRows.each(function() { treeRows.each(function() {
if ($(this).data('parent') == treeHash) if ($(this).data('parent') == treeHash)
$(this).data('expanded', false); $(this).data('expanded', false);
}); });
row.find('td.expander').text(collapsed); row.find('a.expander').text(collapsed);
} else { } else {
treeRows.each(function() { treeRows.each(function() {
if (($(this).data('parent') == treeHash) || ($(this).data('expanded') == true)) { if (($(this).data('parent') == treeHash) || ($(this).data('expanded') == true)) {
$(this).show(); $(this).show();
$(this).data('expanded', true); $(this).data('expanded', true);
} }
}); });
row.find('td.expander').text(expanded); row.find('a.expander').text(expanded);
} }
} else { } else {
var indent = cell.html().match(/^(—+)/); var indent = cell.html().match(/^(—+)/);
if (indent) if (indent)
indent = indent[1]; indent = indent[1];
else else
indent = ''; indent = '';
indent += '—'; indent += '—';
   
var img = jQuery(document.createElement('img')); var img = jQuery(document.createElement('img'));
img.attr('src', url + "images/tree-loader.gif"); img.attr('src', url + "images/tree-loader.gif");
img.attr('alt', GITPHP_RES_LOADING); img.attr('alt', GITPHP_RES_LOADING);
img.addClass('treeSpinner'); img.addClass('treeSpinner');
img.appendTo(cell); img.appendTo(cell);
   
$.get($(this).attr('href'), { o: 'js' }, $.get($(this).attr('href'), { o: 'js' },
function(data) { function(data) {
var subRows = jQuery(data); var subRows = jQuery(data);
   
subRows.addClass(treeHash); subRows.addClass(treeHash);
   
subRows.each(function() { subRows.each(function() {
$(this).data('parent', treeHash); $(this).data('parent', treeHash);
$(this).data('expanded', true); $(this).data('expanded', true);
}); });
   
var classList = row.attr('class').split(/\s+/); var classList = row.attr('class').split(/\s+/);
$.each(classList, function(index, item) { $.each(classList, function(index, item) {
if (item.match(/[0-9a-fA-F]{40}/)) { if (item.match(/[0-9a-fA-F]{40}/)) {
subRows.addClass(item); subRows.addClass(item);
} }
}); });
   
subRows.find('td.fileName').prepend(indent); subRows.find('td.fileName').prepend(indent);
subRows.find('td.expander').text(collapsed); subRows.each(function() {
  var treeLink = $(this).find('a.jsTree');
  if (treeLink && (treeLink.size() > 0)) {
  var a1 = jQuery(document.createElement('a'));
  a1.attr('href', treeLink.attr('href'));
  a1.text(collapsed);
  a1.addClass('jsTree');
  a1.addClass('expander');
  $(this).find('td.expander').append(a1);
  }
  });
   
row.after(subRows); row.after(subRows);
   
row.find('td.expander').text(expanded); row.find('a.expander').text(expanded);
cell.children('img.treeSpinner').remove(); cell.children('img.treeSpinner').remove();
}); });
} }
   
return false; return false;
}); });
} }
   
$(document).ready(function() { $(document).ready(function() {
initTree(); initTree();
}); });
   
comments