From 9a73d10bfd0357361526ce87a0e2ad43ab7efa24 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Mon, 17 Sep 2012 11:25:39 -0400
Subject: [PATCH] Restore zebra stripping, added line hovering, fix overflow (issue 130)

---
 src/com/gitblit/wicket/pages/BlobPage.java |   54 +++------------------------
 resources/gitblit.css                      |   60 +++++++++++++++++++++++++-----
 2 files changed, 56 insertions(+), 58 deletions(-)

diff --git a/resources/gitblit.css b/resources/gitblit.css
index bbd3c0c..fc948b6 100644
--- a/resources/gitblit.css
+++ b/resources/gitblit.css
@@ -163,8 +163,9 @@
 }
 
 div.sourceview {
-	overflow: auto;
+	overflow: hidden;
 }
+
 pre.prettyprint ol {
 	padding-left:25px;
 }
@@ -178,29 +179,68 @@
     vertical-align:top;
 }
 
+#nums pre {
+    white-space: pre;
+}
+
+#nums pre, #lines pre {
+	margin: 0;	
+}
+
+#lines pre {
+	padding: 0px !important;	
+	border: 0px !important;
+	white-space: nowrap;
+}
+
 /* CSS trick to workaround #link topOfWindow offset problem */
-#lines .line {
+#nums .num {
     border-top: 160px solid transparent;
     margin-top: -160px;
     -webkit-background-clip: padding-box;
     -moz-background-clip: padding;
     background-clip: padding-box;
+
+    color: #888;
 }
 
-#lines span:target {
+#nums span:target {
+	background-color: #ffffbf;
+	color: black;
+	font-weight: bold;
+	border-bottom: 1px solid red;
+}
+
+#lines table {
+	margin: 0;
+}
+
+#lines td {
+	padding: 0;
+}
+
+#lines a {
+	padding-left: 5px;
+}
+
+#lines a:hover {
+	background-color: #ffffbf;
+	text-decoration: none;
+}
+
+#lines tr:hover {
 	background-color: #ffffbf;
 }
-
-#nums pre {
-    white-space: pre;
+#lines .odd {
+	background-color: white;
 }
 
-#lines pre {
-	padding: 0px 5px !important;
-	border: 0px !important;
-	white-space: nowrap;
+#lines .even {
+	background-color: #fafafa;
 }
 
+
+
 h1 small, h2 small, h3 small, h4 small, h5 small, h6 small {
     color: #888;
 }
diff --git a/src/com/gitblit/wicket/pages/BlobPage.java b/src/com/gitblit/wicket/pages/BlobPage.java
index ebe539f..f4d6e5b 100644
--- a/src/com/gitblit/wicket/pages/BlobPage.java
+++ b/src/com/gitblit/wicket/pages/BlobPage.java
@@ -131,7 +131,7 @@
 			} else {
 				// plain text
 				String source = JGitUtils.getStringContent(r, commit.getTree(), blobPath, encodings);
-				String table = generateSourceTable(source, false);
+				String table = generateSourceView(source, false);
 				add(new Label("blobText", table).setEscapeModelStrings(false));
 				add(new Image("blobImage").setVisible(false));
 			}
@@ -149,7 +149,7 @@
 		sb.append("<!-- start nums column -->");
 		sb.append("<td id=\"nums\">");
 		sb.append("<pre>");
-		String numPattern = "<a href=\"#L{0}\">{0}</a>\n";
+		String numPattern = "<span id=\"L{0}\" class=\"num\">{0}</span>\n";
 		for (int i = 0; i < lines.length; i++) {
 			sb.append(MessageFormat.format(numPattern, "" + (i + 1)));
 		}
@@ -166,59 +166,17 @@
 			sb.append("<pre class=\"plainprint\">");
 		}
 		lines = StringUtils.escapeForHtml(source, true).split("\n");
-		for (int i = 0; i < lines.length; i++) {
-			sb.append(MessageFormat.format("<span id=\"L{0}\" class=\"line\">", "" + (i + 1)));
-			sb.append(lines[i]);
-			sb.append("</span>");
-		}
-		sb.append("</pre>");
-		sb.append("</div>");
-		sb.append("</td>");
-		sb.append("<!-- end lines column -->");
 		
-		sb.append("</tr></tbody></table>");
-		sb.append("<!-- end blob table -->");
-		
-		return sb.toString();
-	}
-	
-	protected String generateSourceTable(String source, boolean prettyPrint) {
-		String [] lines = source.split("\n");
-		
-		// be careful adding line breaks to this method
-		// GoogleCode Prettify is sensitive
-		StringBuilder sb = new StringBuilder();
-		sb.append("<!-- start blob table -->");
-		sb.append("<table width=\"100%\"><tbody><tr>");
-		
-		// nums column
-		sb.append("<!-- start nums column -->");
-		sb.append("<td id=\"nums\">");
-		sb.append("<pre><table width=\"100%\"><tbody>");
-		String numPattern = "<tr><td id=\"L{0}\"><a href=\"#L{0}\">{0}</a></td></tr>";
-		for (int i = 0; i < lines.length; i++) {
-			sb.append(MessageFormat.format(numPattern, "" + (i + 1)));
-		}
-		sb.append("<!-- end nums column -->");
-		sb.append("</tbody></table></pre>");
-		sb.append("</td>");
-		
-		sb.append("<!-- start lines column -->");
-		sb.append("<td id=\"lines\">");
-		if (prettyPrint) {
-			sb.append("<pre style=\"border: 0px;\" class=\"prettyprint\">");
-		} else {
-			sb.append("<pre class=\"plainprint\">");
-		}
 		sb.append("<table width=\"100%\"><tbody>");
 		
-		String linePattern = "<tr class=\"{0}\"><td>{1}</tr>";
+		String linePattern = "<tr class=\"{0}\"><td><a href=\"#L{2}\">{1}</a></tr>";
 		for (int i = 0; i < lines.length; i++) {
-			String l = StringUtils.escapeForHtml(lines[i], true);
 			String cssClass = (i % 2 == 0) ? "even" : "odd";
-			sb.append(MessageFormat.format(linePattern, cssClass, l));
+			sb.append(MessageFormat.format(linePattern, cssClass, lines[i], "" + (i + 1)));
 		}
 		sb.append("</tbody></table></pre>");
+		sb.append("</pre>");
+		sb.append("</div>");
 		sb.append("</td>");
 		sb.append("<!-- end lines column -->");
 		

--
Gitblit v1.9.1