1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | /* * GitPHP javascript tree * * Load subtree data into tree page asynchronously * * @author Christopher Han <xiphux@gmail.com> * @copyright Copyright (c) 2010 Christopher Han * @package GitPHP * @subpackage Javascript */ function initTree() { var url = window.location.href.match(/^([^\?]+\/)/); if (!url) { return; } url = url[1]; var collapsed = '[+]'; var expanded = '[–]'; $('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() { var treeHash = $(this).attr('href').match(/h=([0-9a-fA-F]{40}|HEAD)/); if (!treeHash) { return; } treeHash = treeHash[1]; var cell = $(this).parent(); var row = cell.parent(); var treeRows = $('.' + treeHash); if (treeRows && treeRows.size() > 0) { if (treeRows.is(':visible')) { treeRows.hide(); treeRows.each(function() { if ($(this).data('parent') == treeHash) $(this).data('expanded', false); }); row.find('a.expander').text(collapsed); } else { treeRows.each(function() { if (($(this).data('parent') == treeHash) || ($(this).data('expanded') == true)) { $(this).show(); $(this).data('expanded', true); } }); row.find('a.expander').text(expanded); } } else { var indent = cell.html().match(/^(—+)/); if (indent) indent = indent[1]; else indent = ''; indent += '—'; var img = jQuery(document.createElement('img')); img.attr('src', url + "images/tree-loader.gif"); img.attr('alt', GITPHP_RES_LOADING); img.addClass('treeSpinner'); img.appendTo(cell); $.get($(this).attr('href'), { o: 'js' }, function(data) { var subRows = jQuery(data); subRows.addClass(treeHash); subRows.each(function() { $(this).data('parent', treeHash); $(this).data('expanded', true); }); var classList = row.attr('class').split(/\s+/); $.each(classList, function(index, item) { if (item.match(/[0-9a-fA-F]{40}/)) { subRows.addClass(item); } }); subRows.find('td.fileName').prepend(indent); 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.find('a.expander').text(expanded); cell.children('img.treeSpinner').remove(); }); } return false; }); } $(document).ready(function() { initTree(); }); |