Start working on ajax blame load
Start working on ajax blame load

--- a/css/gitphp.css
+++ b/css/gitphp.css
@@ -139,11 +139,11 @@
 table.code tr.light:hover { background-color:#ffffff; }
 table.code tr.dark:hover { background-color:#f6f6f0; }
 
-td#blame {
+td#blameData {
 	white-space: nowrap;
 	text-align: left;
 }
-td#blame div.light:hover { background-color:#edece6; }
-td#blame div.dark { background-color:#f6f6f0; }
-td#blame div.dark:hover { background-color:#edece6; }
+td#blameData div.light:hover { background-color:#edece6; }
+td#blameData div.dark { background-color:#f6f6f0; }
+td#blameData div.dark:hover { background-color:#edece6; }
 

 Binary files /dev/null and b/images/blame-loader.gif differ
--- a/include/controller/Controller_Blame.class.php
+++ b/include/controller/Controller_Blame.class.php
@@ -45,6 +45,9 @@
 	 */
 	protected function GetTemplate()
 	{
+		if (isset($this->params['js']) && $this->params['js']) {
+			return 'blamedata.tpl';
+		}
 		return 'blame.tpl';
 	}
 
@@ -92,6 +95,10 @@
 		if (isset($_GET['h'])) {
 			$this->params['hash'] = $_GET['h'];
 		}
+		if (isset($_GET['o']) && ($_GET['o'] == 'js')) {
+			$this->params['js'] = true;
+			GitPHP_Log::GetInstance()->SetEnabled(false);
+		}
 	}
 
 	/**
@@ -118,6 +125,13 @@
 			$blob->SetName(basename($this->params['file']));
 		$blob->SetCommit($commit);
 		$this->tpl->assign('blob', $blob);
+
+		$blame = $blob->GetBlame();
+		$this->tpl->assign('blame', $blob->GetBlame());
+
+		if (isset($this->params['js']) && $this->params['js']) {
+			return;
+		}
 
 		$this->tpl->assign('tree', $commit->GetTree());
 
@@ -154,9 +168,6 @@
 				}
 			}
 		}
-
-		$blame = $blob->GetBlame();
-		$this->tpl->assign('blame', $blob->GetBlame());
 	}
 
 }

--- a/include/controller/Controller_Blob.class.php
+++ b/include/controller/Controller_Blob.class.php
@@ -180,6 +180,8 @@
 			$this->tpl->assign('data', base64_encode($blob->GetData()));
 			return;
 		}
+
+		$this->tpl->assign('extrascripts', array('js/blame.js'));
 
 		if (GitPHP_Config::GetInstance()->GetValue('geshi', true)) {
 			include_once(GitPHP_Config::GetInstance()->GetValue('geshiroot', 'lib/geshi/') . "geshi.php");
@@ -194,6 +196,7 @@
 						$geshi->set_language($lang);
 						$geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
 						$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
+						$geshi->set_overall_id('blobData');
 						$this->tpl->assign('geshiout', $geshi->parse_code());
 						$this->tpl->assign('extracss', $geshi->get_stylesheet());
 						$this->tpl->assign('geshi', true);

file:b/js/blame.js (new)
--- /dev/null
+++ b/js/blame.js
@@ -1,1 +1,53 @@
+/*
+ * GitPHP Javascript blame
+ * 
+ * Load blame data into blob page asynchronously
+ * 
+ * @author Christopher Han <xiphux@gmail.com>
+ * @copyright Copyright (c) 2010 Christopher Han
+ * @package GitPHP
+ */
 
+function initBlame() {
+
+	$('a#blameLink').toggle(function() {
+
+		var blameCol = $('table#blobData td#blameData');
+		if (blameCol && blameCol.size() > 0) {
+			blameCol.show('fast');
+		} else {
+			var colElement = document.createElement('td');
+			var col = jQuery(colElement);
+			col.attr('id', 'blameData');
+			col.css('display', 'none');
+
+			var imgElement = document.createElement('img');
+			var img = jQuery(imgElement);
+			img.attr('src', "images/blame-loader.gif");
+			img.attr('alt', "Loading...");
+			img.appendTo(col);
+
+			$('table#blobData tr:first').prepend(col);
+			col.show('fast');
+
+			$.get($('a#blameLink').attr('href'), { o: 'js' },
+			function(data) {
+				$('td#blameData').html(data);
+				$('td#blameData').addClass('de1');
+			});
+		}
+
+		return false;
+	},
+	function() {
+		var blameCol = $('table#blobData td#blameData');
+		blameCol.hide('fast');
+
+		return false;
+	});
+}
+
+$(document).ready(function() {
+	initBlame();
+});
+

--- a/templates/blame.tpl
+++ b/templates/blame.tpl
@@ -27,20 +27,9 @@
  <div class="page_body">
    {if $geshi}
      {$geshihead}
-       <td class="ln de1" id="blame">
-	{foreach from=$blob->GetData(true) item=blobline name=blob}
-	  {assign var=blamecommit value=$blame[$smarty.foreach.blob.iteration]}
-	  {if $blamecommit}
-	    {if $opened}</div>{/if}
-	    <div class="{cycle values="light,dark"}">
-	    {assign var=opened value=true}
-	    <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&a=commit&h={$blamecommit->GetHash()}" title="{$blamecommit->GetTitle()}" class="commitTip">{$blamecommit->GetAuthorEpoch()|date_format:"%F %X"}</a>
-	    {$blamecommit->GetAuthor()}
-	  {/if}
-	  &nbsp;<br />
-	{/foreach}
-	{if $opened}</div>{/if}
-	</td>
+       <td class="ln de1" id="blameData">
+        {include file='blamedata.tpl'}
+       </td>
      {$geshibody}
      {$geshifoot}
    {else}

--- /dev/null
+++ b/templates/blamedata.tpl
@@ -1,1 +1,21 @@
+{*
+ * blamedata.tpl
+ * gitphp: A PHP git repository browser
+ * Component: Blame data column template
+ *
+ * Copyright (C) 2010 Christopher Han <xiphux@gmail.com>
+ *}
 
+{foreach from=$blob->GetData(true) item=blobline name=blob}
+  {assign var=blamecommit value=$blame[$smarty.foreach.blob.iteration]}
+  {if $blamecommit}
+    {if $opened}</div>{/if}
+    <div class="{cycle values="light,dark"}">
+    {assign var=opened value=true}
+    <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&a=commit&h={$blamecommit->GetHash()}" title="{$blamecommit->GetTitle()}" class="commitTip">{$blamecommit->GetAuthorEpoch()|date_format:"%F %X"}</a>
+    {$blamecommit->GetAuthorName()|escape}
+  {/if}
+  <br />
+{/foreach}
+{if $opened}</div>{/if}
+

--- a/templates/blob.tpl
+++ b/templates/blob.tpl
@@ -16,7 +16,7 @@
    {else}
      HEAD
    {/if}
-   {if !$datatag} | <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&a=blame&h={$blob->GetHash()}&f={$blob->GetPath()}&hb={$commit->GetHash()}">blame</a>{/if}
+   {if !$datatag} | <a href="{$SCRIPT_NAME}?p={$project->GetProject()|urlencode}&a=blame&h={$blob->GetHash()}&f={$blob->GetPath()}&hb={$commit->GetHash()}" id="blameLink">blame</a>{/if}
    <br />
  </div>
 
@@ -35,7 +35,7 @@
      {$geshiout}
    {else}
      {* Just plain display *}
-     <table class="code">
+     <table class="code" id="blobData">
      {foreach from=$bloblines item=line name=bloblines}
        <tr>
          <td class="num"><a id="l{$smarty.foreach.bloblines.iteration}" href="#l{$smarty.foreach.bloblines.iteration}" class="linenr">{$smarty.foreach.bloblines.iteration}</a></td>

--- a/templates/header.tpl
+++ b/templates/header.tpl
@@ -28,6 +28,9 @@
     <script language="javascript" src="js/ext/jquery-1.4.2.min.js"></script>
     <script language="javascript" src="js/ext/jquery.qtip.min.js"></script>
     <script language="javascript" src="js/tooltips.js"></script>
+    {foreach from=$extrascripts item=script}
+    <script language="javascript" src="{$script}"></script>
+    {/foreach}
     {/if}
     </head>
     {$smarty.capture.header}

comments