git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: Petr Baudis <pasky@suse.cz>, Fredrik Kuivinen <frekui@gmail.com>,
	Giuseppe Bilotta <giuseppe.bilotta@gmail.com>,
	Luben Tuikov <ltuikov@yahoo.com>,
	Martin Koegler <mkoegler@auto.tuwien.ac.at>,
	Jakub Narebski <jnareb@gmail.com>
Subject: [PATCH/RFC 10/10] gitweb: Create links leading to 'blame_incremental' using JavaScript
Date: Sat, 25 Jul 2009 00:44:10 +0200	[thread overview]
Message-ID: <1248475450-5668-11-git-send-email-jnareb@gmail.com> (raw)
In-Reply-To: <1248475450-5668-1-git-send-email-jnareb@gmail.com>

The new 'blame_incremental' view requires JavaScript to run.  Not all
web browsers implement JavaScript (e.g. text browsers such as Lynx),
and not all users have JavaScript enabled.  Therefore instead of
unconditionally link to 'blame_incremental' view, we use JavaScript to
convert those links to lead to view utilizing JavaScript, by adding
'js=1' to link.

The only JavaScript-aware/using view is currently 'blame_incremental'.
As first, it might want to have links to non-JavaScript version, and
second, it should also use window.onload, we do not add nor run
fixLinks() for such views (currently hardcoded 'blame_incremental')

Possible enhancement would be to do JavaScript redirect by setting
window.location instead of modifying $format and $action in
git_blame_common() subroutine.


This idea was originally implemented by Petr Baudis in
  http://article.gmane.org/gmane.comp.version-control.git/47614
but it added <script> element with fixBlameLinks() function in page
header, to be added as onload event using 'onload' attribute of HTML
'body' element: <body onload="fixBlameLinks();">.  This version adds
script at then end of page (in the page footer), and uses JavaScript
'window.onload=fixLinks();'.  Also in Petr version only links marked
with 'blamelink' class were modified, and they were modified by
replacing "a=blame" by "a=blame_incremental"... which doesn't work for
path_info links, and might replace wrong part if there is "a=blame" in
project name, ref name or file name.

Slightly different solution was implemented by Martin Koegler in
  http://thread.gmane.org/gmane.comp.version-control.git/47902/focus=47905
Here GitAddLinks() function was in gitweb.js file, not as contents of
<script> element.  This might be a better solution (although I think
it would be better to split JavaScript file and load only parts that
are required).  It was also included in page header (in <head>
element) though, which means waiting for a script to load (and run).
It was smarter in that to "fix" (modify) link, it split URL, modified
value of 'a' parameter, and then recreated modified link.  It avoids
trouble with "a=blame" as substring in project name or file name, but
it doesn't work with path_info URL/link in the way it was written.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch is new, and didn't appear in any way in any of my earlier
series dealing with incremental blame view.

TODO list:
* Extract and remove unrelated changes, like updating copyright
* Perhaps put fixLinks() function in separate file gitweb.js.
  Should gitweb use single JavaScript file, or should it be split into
  more than one file?
* Better solution to "don't invoke for JavaScript-aware actions"
  problem.  Currently hardcoded 'blame_incremental'.

 gitweb/blame.js    |    8 +++++---
 gitweb/gitweb.perl |   21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gitweb/blame.js b/gitweb/blame.js
index 5a8a29f..d8ecee1 100644
--- a/gitweb/blame.js
+++ b/gitweb/blame.js
@@ -1,4 +1,6 @@
 // Copyright (C) 2007, Fredrik Kuivinen <frekui@gmail.com>
+//               2007, Petr Baudis <pasky@suse.cz>
+//          2008-2009, Jakub Narebski <jnareb@gmail.com>
 
 /* ============================================================ */
 /* generic utility functions */
@@ -36,7 +38,7 @@ function spacePad(n, width) {
 /**
  * @param {string} input: input value converted to string.
  * @param {number} size: desired length of output.
- * @param {string} ch: single character to prefix to s.
+ * @param {string} ch: single character to prefix to string.
  */
 function padLeft(input, size, ch) {
 	var s = input + "";
@@ -611,14 +613,14 @@ function startBlame(blamedataUrl, bUrl) {
 	projectUrl = bUrl;
 	if ((div_progress_bar = document.getElementById('progress_bar'))) {
 		div_progress_bar.setAttribute('style', 'width: 100%;');
-		//div_progress_bar.style.value = 'width: 100%;';
+		//div_progress_bar.style.value = 'width: 100%;'; // doesn't work
 	}
 	totalLines = countLines();
 	updateProgressInfo();
 
 	http.open('get', blamedataUrl);
 	http.setRequestHeader('Accept', 'text/plain'); // in case of future changes
-	// perhaps also 'multipart/x-mixed-replace'
+	// perhaps also, in the future, 'multipart/x-mixed-replace' (not standard)
 	http.onreadystatechange = handleResponse;
 	//http.onreadystatechange = function () { handleResponse(http); };
 	http.send(null);
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 036f8da..38492d0 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3243,6 +3243,23 @@ sub git_footer_html {
 		insert_file($site_footer);
 	}
 
+	if ($action ne 'blame_incremental') {
+		print <<'HTML';
+<script type="text/javascript">/* <![CDATA[ */
+function fixLinks() {
+	//var allLinks = document.getElementsByTagName("a");
+	var allLinks = document.links;
+	for (var i = 0; i < allLinks.length; i++) {
+		var link = allLinks[i];
+		link.href +=
+			(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1';
+	}
+}
+window.onload = fixLinks;
+/* ]]> */</script>
+HTML
+	}
+
 	print "</body>\n" .
 	      "</html>";
 }
@@ -4794,6 +4811,10 @@ sub git_tag {
 
 sub git_blame_common {
 	my $format = shift || 'porcelain';
+	if ($format eq 'porcelain' && $cgi->param('js')) {
+		$format = 'incremental';
+		$action = 'blame_incremental'; # for page title etc
+	}
 
 	# permissions
 	gitweb_check_feature('blame')
-- 
1.6.3.3

  parent reply	other threads:[~2009-07-24 22:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-24 22:44 [PATCHv2 00/10] gitweb: 'blame' view improvements Jakub Narebski
2009-07-24 22:44 ` [PATCH 01/10] gitweb: Make .error style generic Jakub Narebski
2009-07-24 22:44 ` [PATCH 02/10] gitweb: Mark boundary commits in 'blame' view Jakub Narebski
2009-07-25  0:13   ` Junio C Hamano
2009-07-25  0:32     ` Jakub Narebski
2009-07-25  0:39       ` Junio C Hamano
2009-07-24 22:44 ` [PATCHv2 03/10] gitweb: Use "previous" header of git-blame -p " Jakub Narebski
2009-07-24 22:44 ` [PATCH 04/10] gitweb: Mark commits with no "previous" " Jakub Narebski
2009-07-24 22:44 ` [PATCHv2 05/10] gitweb: Add author initials in 'blame' view, a la "git gui blame" Jakub Narebski
2009-07-24 22:44 ` [PATCH/RFC 06/10] gitweb: Use light/dark for class names also in 'blame' view Jakub Narebski
2009-07-24 22:44 ` [PATCH 07/10] gitweb: Add -partial_query option to href() subroutine Jakub Narebski
2009-07-24 22:44 ` [PATCH 08/10] gitweb: Add optional "time to generate page" info in footer Jakub Narebski
2009-07-24 22:44 ` [PATCHv2/RFC 09/10] gitweb: Incremental blame (proof of concept) Jakub Narebski
2009-07-25 19:28   ` Jakub Narebski
2009-07-24 22:44 ` Jakub Narebski [this message]
2009-07-25 10:46   ` [PATCH/RFC 10/10] gitweb: Create links leading to 'blame_incremental' using JavaScript Martin Koegler
2009-07-26 10:06     ` Jakub Narebski
2009-07-27 18:10       ` Martin Koegler
2009-07-27 19:06         ` Jakub Narebski
2009-07-24 23:47 ` [PATCHv2 00/10] gitweb: 'blame' view improvements Junio C Hamano
2009-07-25  0:10   ` Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1248475450-5668-11-git-send-email-jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=frekui@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=giuseppe.bilotta@gmail.com \
    --cc=ltuikov@yahoo.com \
    --cc=mkoegler@auto.tuwien.ac.at \
    --cc=pasky@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).