From 71a347e96308eabee696918cd276380ee30eea9d Mon Sep 17 00:00:00 2001
From: Paul Martin <paul@paulsputer.com>
Date: Wed, 09 Dec 2015 13:04:14 -0500
Subject: [PATCH] fix for #978 - HTML5 date input support
---
src/main/java/com/gitblit/wicket/pages/ImageDiffHandler.java | 48 ++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/src/main/java/com/gitblit/wicket/pages/ImageDiffHandler.java b/src/main/java/com/gitblit/wicket/pages/ImageDiffHandler.java
index 69d84f4..dc0c5ae 100644
--- a/src/main/java/com/gitblit/wicket/pages/ImageDiffHandler.java
+++ b/src/main/java/com/gitblit/wicket/pages/ImageDiffHandler.java
@@ -18,6 +18,7 @@
import java.nio.charset.StandardCharsets;
import java.util.List;
+import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WicketURLEncoder;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffEntry.Side;
@@ -37,12 +38,14 @@
private final String oldCommitId;
private final String newCommitId;
private final String repositoryName;
- private final String baseUrl;
+ private final BasePage page;
private final List<String> imageExtensions;
- public ImageDiffHandler(final String baseUrl, final String repositoryName, final String oldCommitId,
- final String newCommitId, final List<String> imageExtensions) {
- this.baseUrl = baseUrl;
+ private int imgDiffCount = 0;
+
+ public ImageDiffHandler(final BasePage page, final String repositoryName, final String oldCommitId, final String newCommitId,
+ final List<String> imageExtensions) {
+ this.page = page;
this.repositoryName = repositoryName;
this.oldCommitId = oldCommitId;
this.newCommitId = newCommitId;
@@ -62,9 +65,12 @@
String oldUrl = getImageUrl(diffEntry, Side.OLD);
String newUrl = getImageUrl(diffEntry, Side.NEW);
if (oldUrl != null && newUrl != null) {
+ imgDiffCount++;
+ String id = "imgdiff" + imgDiffCount;
HtmlBuilder builder = new HtmlBuilder("div");
- Element container = builder.root().appendElement("div").attr("class", "imgdiff");
- Element resizeable = container.appendElement("div").attr("class", "imgdiff-left");
+ Element wrapper = builder.root().attr("class", "imgdiff-container").attr("id", "imgdiff-" + id);
+ Element container = wrapper.appendElement("div").attr("class", "imgdiff-ovr-slider").appendElement("div").attr("class", "imgdiff");
+ Element old = container.appendElement("div").attr("class", "imgdiff-left");
// style='max-width:640px;' is necessary for ensuring that the browser limits large images
// to some reasonable width, and to override the "img { max-width: 100%; }" from bootstrap.css,
// which would scale the left image to the width of its resizeable container, which isn't what
@@ -73,8 +79,22 @@
// is too wide.
// XXX: Maybe add a max-height, too, to limit portrait-oriented images to some reasonable height?
// (Like a 300x10000px image...)
- resizeable.appendElement("img").attr("class", "imgdiff imgdiff-left").attr("style", "max-width:640px;").attr("src", oldUrl);
+ old.appendElement("img").attr("class", "imgdiff-old").attr("id", id).attr("style", "max-width:640px;").attr("src", oldUrl);
container.appendElement("img").attr("class", "imgdiff").attr("style", "max-width:640px;").attr("src", newUrl);
+ wrapper.appendElement("br");
+ Element controls = wrapper.appendElement("div");
+ // Opacity slider
+ controls.appendElement("div").attr("class", "imgdiff-opa-container").appendElement("a").attr("class", "imgdiff-opa-slider")
+ .attr("href", "#").attr("title", page.getString("gb.opacityAdjust"));
+ // Blink comparator: find Pluto!
+ controls.appendElement("a").attr("class", "imgdiff-link imgdiff-blink").attr("href", "#")
+ .attr("title", page.getString("gb.blinkComparator"))
+ .appendElement("img").attr("src", getStaticResourceUrl("blink32.png")).attr("width", "20");
+ // Pixel subtraction, initially not displayed, will be shown by imgdiff.js depending on feature test.
+ // (Uses CSS mix-blend-mode, which isn't supported on all browsers yet).
+ controls.appendElement("a").attr("class", "imgdiff-link imgdiff-subtract").attr("href", "#")
+ .attr("title", page.getString("gb.imgdiffSubtract")).attr("style", "display:none;")
+ .appendElement("img").attr("src", getStaticResourceUrl("sub32.png")).attr("width", "20");
return builder.toString();
}
break;
@@ -88,6 +108,11 @@
break;
}
return null;
+ }
+
+ /** Returns the number of image diffs generated so far by this {@link ImageDiffHandler}. */
+ public int getImgDiffCount() {
+ return imgDiffCount;
}
/**
@@ -106,7 +131,7 @@
if (ext.equalsIgnoreCase(extension)) {
String commitId = Side.NEW.equals(side) ? newCommitId : oldCommitId;
if (commitId != null) {
- return RawServlet.asLink(baseUrl, urlencode(repositoryName), commitId, urlencode(path));
+ return RawServlet.asLink(page.getContextUrl(), urlencode(repositoryName), commitId, urlencode(path));
} else {
return null;
}
@@ -117,6 +142,13 @@
}
/**
+ * Returns a URL that will fetch the designated static resource from within GitBlit.
+ */
+ protected String getStaticResourceUrl(String contextRelativePath) {
+ return WebApplication.get().getRequestCycleProcessor().getRequestCodingStrategy().rewriteStaticRelativeUrl(contextRelativePath);
+ }
+
+ /**
* Encode a URL component of a {@link RawServlet} URL in the special way that the servlet expects it. Note that
* the %-encoding used does not encode '&' or '<'. Slashes are not encoded in the result.
*
--
Gitblit v1.9.1