The Unified and Autonomous Development Platform
Add blame split support in file diff view
robin shine710cb30ead1a
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/dragdrop/DropBehavior.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/dragdrop/DropBehavior.javaindex e79239e0fe..89557a4488 100644--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/dragdrop/DropBehavior.java+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/behavior/dragdrop/DropBehavior.java@@ -1,26 +1,19 @@package com.pmease.commons.wicket.behavior.dragdrop;+import static org.apache.wicket.ajax.attributes.CallbackParameter.explicit;+import org.apache.wicket.Component;-import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;import org.apache.wicket.ajax.AjaxRequestTarget;-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;import org.apache.wicket.markup.head.IHeaderResponse;import org.apache.wicket.markup.head.JavaScriptReferenceHeaderItem;import org.apache.wicket.markup.head.OnDomReadyHeaderItem;import org.apache.wicket.request.IRequestParameters;import org.apache.wicket.request.cycle.RequestCycle;-import static org.apache.wicket.ajax.attributes.CallbackParameter.explicit;+import com.pmease.commons.wicket.behavior.AbstractPostAjaxBehavior;@SuppressWarnings("serial")-public abstract class DropBehavior extends AbstractDefaultAjaxBehavior {-- @Override- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {- super.updateAjaxAttributes(attributes);- attributes.setMethod(Method.POST);- }+public abstract class DropBehavior extends AbstractPostAjaxBehavior {@Overridepublic void renderHead(Component component, IHeaderResponse response) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.jsindex a1f84fa498..c206ea10f0 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js@@ -1,546 +1,546 @@-gitplex.sourceview = {- init: function(fileContent, filePath, openComment, mark, symbolTooltipId,- revision, blameInfos, comments, markCallback, viewState, loggedIn, anchor, tabSize, lineWrapMode) {- var cm;-- var $sourceView = $(".source-view");- if (openComment)- $sourceView.data("openComment", openComment);- if (mark)- $sourceView.data("mark", mark);-- $sourceView.data("markCallback", markCallback);-- var $code = $sourceView.children(".code");- $sourceView.closest(".scrollable").css("overflow", "visible");-- function repositionCommentPopovers() {- $(".comment-popover:visible").each(function() {- var $popover = $(this);- var lineInfo = cm.lineInfo($popover.data("line"));- if (lineInfo.gutterMarkers) {- var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];- if (gutter) {- var $indicator = $(gutter).children("a");- if ($indicator.offset().top+$indicator.height() < $sourceView.offset().top- || $indicator.offset().top > $sourceView.offset().top+$sourceView.height()) {- $popover.css("left", "-10000px");- } else {- $popover.css({- "left": $indicator.offset().left + $indicator.outerWidth() - $sourceView.offset().left,- "top": $indicator.offset().top + ($indicator.outerHeight() - $popover.outerHeight())/2 - $sourceView.offset().top- });- }- }- }- });- }-- $sourceView.on("storeViewState", function(event) {- event.stopPropagation();- if (cm) {- pmease.commons.history.setViewState(pmease.commons.codemirror.getViewState(cm));- }- });-- $sourceView.on("autofit", function(event, width, height) {- event.stopPropagation();- $sourceView.outerWidth(width);- $sourceView.outerHeight(height);- $code.outerHeight($sourceView.height());-- var $comment = $sourceView.children(".comment");- var paddingLeft;- if ($comment.is(":visible")) {- paddingLeft = $comment.outerWidth();- $comment.children(".ui-resizable-handle").outerHeight($sourceView.height());-- var $commentHead = $comment.find(">.content>.head");- var $commentBody = $comment.find(">.content>.body");- $commentBody.outerHeight($sourceView.height() - $commentHead.outerHeight());- } else {- paddingLeft = 0;- }- $sourceView.css("padding-left", paddingLeft);-- var $outline = $sourceView.children(".outline");- if ($outline.is(":visible")) {- $sourceView.css("padding-right", $outline.outerWidth());- $outline.css("left", $code.outerWidth() + paddingLeft);- $outline.children(".ui-resizable-handle").outerHeight($sourceView.height());-- var $outlineHead = $outline.find(">.content>.head");- var $outlineBody = $outline.find(">.content>.body");- $outlineBody.outerHeight($sourceView.height() - $outlineHead.outerHeight());- } else {- $sourceView.css("padding-right", "0");- }-- /*- * initialize codemirror here when we know the container width and height- * as otherwise the annotatescrollbar addon is inaccurate when window- * initially loads- */- var initState = !cm;- if (!cm) {- var options = {- value: fileContent,- readOnly: pmease.commons.isDevice()?"nocursor":true,- theme: "eclipse",- lineNumbers: true,- lineWrapping: lineWrapMode == "Soft wrap",- tabSize: tabSize,- styleActiveLine: true,- styleSelectedText: true,- foldGutter: true,- matchBrackets: true,- scrollbarStyle: "simple",- highlightIdentifiers: {delay: 500},- gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],- extraKeys: {- "F11": function(cm) {- cm.setOption("fullScreen", !cm.getOption("fullScreen"));- },- "Esc": function(cm) {- if (cm.getOption("fullScreen"))- cm.setOption("fullScreen", false);- }- }- };-- cm = CodeMirror($code[0], options);- pmease.commons.codemirror.setMode(cm, filePath);-- // add gutters with a timer to avoid the issue that occasionally- // gutter becomes much wider than expected- setTimeout(function() {- var gutters = cm.getOption("gutters").slice();- gutters.splice(0, 0, "CodeMirror-comments");- cm.setOption("gutters", gutters);- for (var line in comments) {- if (comments.hasOwnProperty(line)) {- gitplex.sourceview.addCommentGutter(line, comments[line][1]);- }- }-- if (blameInfos) {- gitplex.sourceview.blame(blameInfos);- }- gitplex.sourceview.highlightCommentTrigger();- }, 10);-- $code.selectionPopover("init", function() {- if (cm.hasFocus()) {- var from = cm.getCursor("from");- var to = cm.getCursor("to");- if (from.line != to.line || from.ch != to.ch) {- markCallback("openSelectionPopover", from.line, from.ch, to.line, to.ch);- return;- }- }- return "close";- });-- $code.mouseover(function(e) {- var node = e.target || e.srcElement, $node = $(node);- if ($node.hasClass("cm-property") || $node.hasClass("cm-variable") || $node.hasClass("cm-variable-2")- || $node.hasClass("cm-variable-3") || $node.hasClass("cm-def") || $node.hasClass("cm-meta")) {- document.getElementById(symbolTooltipId).onMouseOverSymbol(revision, node);- }- });- cm.setSize($code.width(), $code.height());- if (mark)- pmease.commons.codemirror.mark(cm, mark, true);- if (initState) // restore cursor and scroll- pmease.commons.codemirror.initState(cm, viewState);- cm.on("scroll", function() {- gitplex.symboltooltip.removeTooltip(document.getElementById(symbolTooltipId));- gitplex.mouseState.moved = false;- repositionCommentPopovers(cm);- });- } else {- cm.setSize($code.width(), $code.height());- if (cm.getOption("fullScreen"))- cm.setOption("fullScreen", false);- repositionCommentPopovers(cm);- }- });- if (anchor) {- var $anchor = $("#"+anchor);- if ($anchor.length != 0) {- setTimeout(function() {- $anchor.closest(".code-comment").parent().scrollIntoView($anchor);- }, 10);- }- }- },- initComment: function() {- var $sourceView = $(".source-view");- var $code = $sourceView.children(".code");- var commentWidthCookieKey = "sourceView.comment.width";- var $comment = $sourceView.children(".comment");- var commentWidth = Cookies.get(commentWidthCookieKey);- if (!commentWidth)- commentWidth = 400;- $comment.outerWidth(commentWidth);- var $commentResizeHandle = $comment.children(".ui-resizable-handle");- $comment.resizable({- autoHide: false,- handles: {"e": $commentResizeHandle},- minWidth: 200,- resize: function(e, ui) {- var codeWidth = $code.outerWidth();- if(codeWidth < 300)- $(this).resizable({maxWidth: ui.size.width});- },- stop: function(e, ui) {- $(this).resizable({maxWidth: undefined});- Cookies.set(commentWidthCookieKey, ui.size.width, {expires: Infinity});- }- });- },- initOutline: function() {- var $sourceView = $(".source-view");- var $code = $sourceView.children(".code");- var outlineWidthCookieKey = "sourceView.outline.width";- var $outline = $sourceView.children(".outline");- var outlineWidth = Cookies.get(outlineWidthCookieKey);- if (!outlineWidth)- outlineWidth = 350;- $outline.outerWidth(outlineWidth);- var $outlineResizeHandle = $outline.children(".ui-resizable-handle");- $outline.resizable({- autoHide: false,- handles: {"w": $outlineResizeHandle},- minWidth: 100,- resize: function(e, ui) {- var codeWidth = $code.outerWidth();- if(codeWidth < 300)- $(this).resizable({maxWidth: ui.size.width});- },- stop: function(e, ui) {- $(this).resizable({maxWidth: undefined});- Cookies.set(outlineWidthCookieKey, ui.size.width, {expires: Infinity});- }- });- },- showBlameMessage: function(tooltipId, message) {- var $blameTooltip = $("#" + tooltipId);- $blameTooltip.empty().text(message);- $blameTooltip.align({placement: $blameTooltip.data("alignment"), target: {element: $blameTooltip.data("trigger")}});- },- restoreMark: function() {- var $sourceView = $(".source-view");- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- var mark = $sourceView.data("mark");- if (mark) {- pmease.commons.codemirror.mark(cm, mark, false);- } else {- pmease.commons.codemirror.clearMark(cm);- }- },- addCommentGutter: function(line, comments) {- $(".comment-popover[data-line='" + line + "']").remove();-- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- var markCallback = $(".source-view").data("markCallback");-- var $gutter = $(document.createElement("div"));- $gutter.addClass("CodeMirror-comment");- $gutter.data("comments", comments);- if (comments.length != 1) {- /*- * when there are multiple comments starts with the same line, we should- * display a comment indicator which will display a comment popover with- * list of comment triggers upon click, user can then click one of the- * trigger link to display the actual comment content- */- $gutter.append("<a><i class='fa fa-comments'></i></a>");- var $indicator = $gutter.children("a");- var content = "";- for (var i in comments) {- var comment = comments[i];- var index = parseInt(i) + 1;- content += "<a class='comment-trigger' title='Click to show details of this comment'>#" + comment.id + "</a>";- }- $indicator.popover({- html: true,- container: ".source-view",- placement: "right auto",- template: "<div data-line='" + line + "' class='popover comment-popover'><div class='arrow'></div><div class='popover-content'></div></div>",- content: content- });- $indicator.on('shown.bs.popover', function () {- $(".comment-popover[data-line='" + line + "'] a").each(function() {- $(this).mouseover(function() {- var comment = comments[$(this).index()];- pmease.commons.codemirror.mark(cm, comment.mark, false);- });- $(this).mouseout(function() {- gitplex.sourceview.restoreMark();- });- $(this).click(function() {- if ($(".source-view form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;- }- var comment = comments[$(this).index()];- markCallback("openComment", comment.id);- });- });- gitplex.sourceview.highlightCommentTrigger();- });- } else {- var comment = comments[0];- $gutter.append("<a class='comment-trigger' title='Click to show comment of marked text'><i class='fa fa-commenting'></i></a>");- var $indicator = $gutter.children("a");- $indicator.mouseover(function() {- pmease.commons.codemirror.mark(cm, comment.mark, false);- });- $indicator.mouseout(function() {- gitplex.sourceview.restoreMark();- });- $indicator.click(function() {- if ($(".source-view form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;- }- markCallback("openComment", comment.id);- });- }- cm.setGutterMarker(parseInt(line), "CodeMirror-comments", $gutter[0]);- },- openSelectionPopover: function(mark, markUrl, loggedIn) {- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- var ch = (mark.beginChar + mark.endChar)/2;- var position = cm.charCoords({line:mark.beginLine, ch:ch});-- var $content = $("<div><a class='permanent'><i class='fa fa-link'></i> Permanent link of this selection</a>");- $content.children("a.permanent").attr("href", markUrl);- if (loggedIn) {- $content.append("<a class='comment'><i class='fa fa-comment'></i> Add comment on this selection</a>");- $content.children("a.comment").click(function() {- if ($(".source-view").find("form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;- }- var markCallback = $(".source-view").data("markCallback");- markCallback("addComment", mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);- });- } else {- $content.append("<span class='comment'><i class='fa fa-warning'></i> Log in to comment on selection</span>");- }-- $(".source-view>.code").selectionPopover("open", {- position: position,- content: $content- });- },- onCommentAdded: function(comment) {- var $sourceView = $(".source-view");- $sourceView.data("openComment", comment);- $sourceView.data("mark", comment.mark);-- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- var line = parseInt(comment.mark.beginLine);- var lineInfo = cm.lineInfo(line);- var gutter;- if (lineInfo.gutterMarkers)- gutter = lineInfo.gutterMarkers["CodeMirror-comments"];- var comments;- if (gutter) {- comments = $(gutter).data("comments");- } else {- comments = [];- }- comments.push(comment);- gitplex.sourceview.addCommentGutter(line, comments);- gitplex.sourceview.highlightCommentTrigger();- gitplex.sourceview.onLayoutChange();- },- onCommentDeleted: function(comment) {- var $sourceView = $(".source-view");- $sourceView.removeData("openComment");-- var line = parseInt(comment.mark.beginLine);- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- var lineInfo = cm.lineInfo(line);- var $gutter = $(lineInfo.gutterMarkers["CodeMirror-comments"]);- var comments = $gutter.data("comments");- if (comments.length == 1) {- cm.setGutterMarker(line, "CodeMirror-comments", null);- } else {- for (var i in comments) {- if (comments[i].id == comment.id) {- comments.splice(i, 1);- break;- }- }- gitplex.sourceview.addCommentGutter(line, comments);- }- gitplex.sourceview.highlightCommentTrigger();- gitplex.sourceview.onLayoutChange();-- gitplex.sourceview.mark(undefined, false);- },- onLayoutChange: function() {- $sourceView = $('.source-view');- $sourceView.trigger('autofit', [$sourceView.outerWidth(), $sourceView.outerHeight()]);- },- onAddComment: function(mark) {- var $sourceView = $(".source-view");- $sourceView.removeData("openComment");- $sourceView.data("mark", mark);- $(".source-view>.code").selectionPopover("close");-- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- pmease.commons.codemirror.clearSelection(cm);- gitplex.sourceview.onLayoutChange();-- // mark and scroll after changing layout to make sure scroll- // works correctly- pmease.commons.codemirror.mark(cm, mark, true);-- gitplex.sourceview.highlightCommentTrigger();- },- onOpenComment: function(comment) {- var $sourceView = $(".source-view");- $sourceView.data("openComment", comment);- $sourceView.data("mark", comment.mark);- gitplex.sourceview.highlightCommentTrigger();- gitplex.sourceview.onLayoutChange();-- // mark and scroll after changing layout to make sure scroll- // works correctly- gitplex.sourceview.mark(comment.mark, true);- },- onCloseComment: function() {- var $sourceView = $(".source-view");- $sourceView.removeData("openComment");- gitplex.sourceview.highlightCommentTrigger();- gitplex.sourceview.onLayoutChange();- gitplex.sourceview.mark(undefined, false);- },- onToggleOutline: function() {- gitplex.sourceview.onLayoutChange();- $(".outline-toggle").toggleClass("active");- },- highlightCommentTrigger: function() {- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- $(".comment-popover a").removeClass("active");-- /*- * we can not simply select all comment triggers via jQuery- * as comment gutter may be create/destroy dynamically by- * CodeMirror- */- for (var i=0; i<cm.lineCount(); i++) {- var gutterMarkers = cm.lineInfo(i).gutterMarkers;- if (gutterMarkers) {- var gutter = gutterMarkers["CodeMirror-comments"];- if (gutter) {- $(gutter).children("a").removeClass("active");- }- }- }-- var openComment = $(".source-view").data("openComment");- if (openComment) {- var line = parseInt(openComment.mark.beginLine);- var lineInfo = cm.lineInfo(line);- if (lineInfo && lineInfo.gutterMarkers) {- var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];- if (gutter) {- var comments = $(gutter).data("comments");- if (comments.length == 1) {- $(gutter).children("a").addClass("active");- } else {- $(".comment-popover[data-line='" + line + "'] a").each(function() {- var comment = comments[$(this).index()];- if (comment.id == openComment.id) {- $(this).addClass("active");- }- });- }- }- }- }- },- mark: function(mark, scroll) {- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- if (mark) {- $(".source-view").data("mark", mark);- pmease.commons.codemirror.mark(cm, mark, scroll);- } else {- $(".source-view").removeData("mark");- pmease.commons.codemirror.clearMark(cm);- }- },- blame: function(blameInfos) {- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- var alignment = {targetX: 100, targetY: 100, x: 0, y: 0};-- if (blameInfos) {- var markCallback = $(".source-view").data("markCallback");- var gutters = cm.getOption("gutters").slice();- gutters.splice(1, 0, "CodeMirror-annotations");- cm.setOption("gutters", gutters);- for (var i in blameInfos) {- var blameInfo = blameInfos[i];- for (var j in blameInfo.ranges) {- var range = blameInfo.ranges[j];- var $gutter = $(document.createElement("div"));- $gutter.addClass("CodeMirror-annotation");- $("<a class='hash'>" + blameInfo.abbreviatedHash + "</a>").appendTo($gutter).attr("href", blameInfo.url);- var $hashLink = $gutter.children("a.hash");- $hashLink.data("hash", blameInfo.hash);- $hashLink.data("line", range.from);-- $hashLink.hover(function() {- var tooltipId = "blame-message-line-" + $(this).data("line");- markCallback("showBlameMessage", tooltipId, $(this).data("hash"));- var $tooltip = $("<div class='blame-message'><div class='loading'>Loading...</div></div>");- $tooltip.attr("id", tooltipId);- $tooltip.data("trigger", this);- $tooltip.data("alignment", alignment);- $(".source-view").append($tooltip);- return $tooltip;- }, alignment);-- $gutter.append("<span class='date'>" + blameInfo.commitDate + "</span>");- $gutter.append("<span class='author'>" + blameInfo.authorName + "</span>");- cm.setGutterMarker(range.from, "CodeMirror-annotations", $gutter[0]);-- for (var line = range.from+1; line<range.to; line++) {- var $gutter = $(document.createElement("div"));- $gutter.addClass("CodeMirror-annotation");- $gutter.append("<span class='same-as-above'>...</span>");- cm.setGutterMarker(line, "CodeMirror-annotations", $gutter[0]);- }- }- }- } else {- cm.clearGutter("CodeMirror-annotations");- var gutters = cm.getOption("gutters").slice();- gutters.splice(1, 1);- cm.setOption("gutters", gutters);- }- },- onBlame: function(blameInfos) {- gitplex.sourceview.blame(blameInfos);- gitplex.sourceview.onLayoutChange();- $(".blame-toggle").toggleClass("active");- },- scrollToCommentBottom: function() {- var $body = $(".source-view>.comment>.content>.body");- $body.scrollTop($body[0].scrollHeight);- },- onLineWrapModeChange: function(lineWrapMode) {- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- cm.setOption("lineWrapping", lineWrapMode == "Soft wrap");- },- onTabSizeChange: function(tabSize) {- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;- cm.setOption("tabSize", tabSize);- }-};+gitplex.sourceview = {+ init: function(fileContent, filePath, openComment, mark, symbolTooltipId,+ revision, blameInfos, comments, markCallback, viewState, loggedIn, anchor, tabSize, lineWrapMode) {+ var cm;++ var $sourceView = $(".source-view");+ if (openComment)+ $sourceView.data("openComment", openComment);+ if (mark)+ $sourceView.data("mark", mark);++ $sourceView.data("markCallback", markCallback);++ var $code = $sourceView.children(".code");+ $sourceView.closest(".scrollable").css("overflow", "visible");++ function repositionCommentPopovers() {+ $(".comment-popover:visible").each(function() {+ var $popover = $(this);+ var lineInfo = cm.lineInfo($popover.data("line"));+ if (lineInfo.gutterMarkers) {+ var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];+ if (gutter) {+ var $indicator = $(gutter).children("a");+ if ($indicator.offset().top+$indicator.height() < $sourceView.offset().top+ || $indicator.offset().top > $sourceView.offset().top+$sourceView.height()) {+ $popover.css("left", "-10000px");+ } else {+ $popover.css({+ "left": $indicator.offset().left + $indicator.outerWidth() - $sourceView.offset().left,+ "top": $indicator.offset().top + ($indicator.outerHeight() - $popover.outerHeight())/2 - $sourceView.offset().top+ });+ }+ }+ }+ });+ }++ $sourceView.on("storeViewState", function(event) {+ event.stopPropagation();+ if (cm) {+ pmease.commons.history.setViewState(pmease.commons.codemirror.getViewState(cm));+ }+ });++ $sourceView.on("autofit", function(event, width, height) {+ event.stopPropagation();+ $sourceView.outerWidth(width);+ $sourceView.outerHeight(height);+ $code.outerHeight($sourceView.height());++ var $comment = $sourceView.children(".comment");+ var paddingLeft;+ if ($comment.is(":visible")) {+ paddingLeft = $comment.outerWidth();+ $comment.children(".ui-resizable-handle").outerHeight($sourceView.height());++ var $commentHead = $comment.find(">.content>.head");+ var $commentBody = $comment.find(">.content>.body");+ $commentBody.outerHeight($sourceView.height() - $commentHead.outerHeight());+ } else {+ paddingLeft = 0;+ }+ $sourceView.css("padding-left", paddingLeft);++ var $outline = $sourceView.children(".outline");+ if ($outline.is(":visible")) {+ $sourceView.css("padding-right", $outline.outerWidth());+ $outline.css("left", $code.outerWidth() + paddingLeft);+ $outline.children(".ui-resizable-handle").outerHeight($sourceView.height());++ var $outlineHead = $outline.find(">.content>.head");+ var $outlineBody = $outline.find(">.content>.body");+ $outlineBody.outerHeight($sourceView.height() - $outlineHead.outerHeight());+ } else {+ $sourceView.css("padding-right", "0");+ }++ /*+ * initialize codemirror here when we know the container width and height+ * as otherwise the annotatescrollbar addon is inaccurate when window+ * initially loads+ */+ var initState = !cm;+ if (!cm) {+ var options = {+ value: fileContent,+ readOnly: pmease.commons.isDevice()?"nocursor":true,+ theme: "eclipse",+ lineNumbers: true,+ lineWrapping: lineWrapMode == "Soft wrap",+ tabSize: tabSize,+ styleActiveLine: true,+ styleSelectedText: true,+ foldGutter: true,+ matchBrackets: true,+ scrollbarStyle: "simple",+ highlightIdentifiers: {delay: 500},+ gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],+ extraKeys: {+ "F11": function(cm) {+ cm.setOption("fullScreen", !cm.getOption("fullScreen"));+ },+ "Esc": function(cm) {+ if (cm.getOption("fullScreen"))+ cm.setOption("fullScreen", false);+ }+ }+ };++ cm = CodeMirror($code[0], options);+ pmease.commons.codemirror.setMode(cm, filePath);++ // add gutters with a timer to avoid the issue that occasionally+ // gutter becomes much wider than expected+ setTimeout(function() {+ var gutters = cm.getOption("gutters").slice();+ gutters.splice(0, 0, "CodeMirror-comments");+ cm.setOption("gutters", gutters);+ for (var line in comments) {+ if (comments.hasOwnProperty(line)) {+ gitplex.sourceview.addCommentGutter(line, comments[line][1]);+ }+ }++ if (blameInfos) {+ gitplex.sourceview.blame(blameInfos);+ }+ gitplex.sourceview.highlightCommentTrigger();+ }, 10);++ $code.selectionPopover("init", function() {+ if (cm.hasFocus()) {+ var from = cm.getCursor("from");+ var to = cm.getCursor("to");+ if (from.line != to.line || from.ch != to.ch) {+ markCallback("openSelectionPopover", from.line, from.ch, to.line, to.ch);+ return;+ }+ }+ return "close";+ });++ $code.mouseover(function(e) {+ var node = e.target || e.srcElement, $node = $(node);+ if ($node.hasClass("cm-property") || $node.hasClass("cm-variable") || $node.hasClass("cm-variable-2")+ || $node.hasClass("cm-variable-3") || $node.hasClass("cm-def") || $node.hasClass("cm-meta")) {+ document.getElementById(symbolTooltipId).onMouseOverSymbol(revision, node);+ }+ });+ cm.setSize($code.width(), $code.height());+ if (mark)+ pmease.commons.codemirror.mark(cm, mark, true);+ if (initState) // restore cursor and scroll+ pmease.commons.codemirror.initState(cm, viewState);+ cm.on("scroll", function() {+ gitplex.symboltooltip.removeTooltip(document.getElementById(symbolTooltipId));+ gitplex.mouseState.moved = false;+ repositionCommentPopovers(cm);+ });+ } else {+ cm.setSize($code.width(), $code.height());+ if (cm.getOption("fullScreen"))+ cm.setOption("fullScreen", false);+ repositionCommentPopovers(cm);+ }+ });+ if (anchor) {+ var $anchor = $("#"+anchor);+ if ($anchor.length != 0) {+ setTimeout(function() {+ $anchor.closest(".code-comment").parent().scrollIntoView($anchor);+ }, 10);+ }+ }+ },+ initComment: function() {+ var $sourceView = $(".source-view");+ var $code = $sourceView.children(".code");+ var commentWidthCookieKey = "sourceView.comment.width";+ var $comment = $sourceView.children(".comment");+ var commentWidth = Cookies.get(commentWidthCookieKey);+ if (!commentWidth)+ commentWidth = 400;+ $comment.outerWidth(commentWidth);+ var $commentResizeHandle = $comment.children(".ui-resizable-handle");+ $comment.resizable({+ autoHide: false,+ handles: {"e": $commentResizeHandle},+ minWidth: 200,+ resize: function(e, ui) {+ var codeWidth = $code.outerWidth();+ if(codeWidth < 300)+ $(this).resizable({maxWidth: ui.size.width});+ },+ stop: function(e, ui) {+ $(this).resizable({maxWidth: undefined});+ Cookies.set(commentWidthCookieKey, ui.size.width, {expires: Infinity});+ }+ });+ },+ initOutline: function() {+ var $sourceView = $(".source-view");+ var $code = $sourceView.children(".code");+ var outlineWidthCookieKey = "sourceView.outline.width";+ var $outline = $sourceView.children(".outline");+ var outlineWidth = Cookies.get(outlineWidthCookieKey);+ if (!outlineWidth)+ outlineWidth = 350;+ $outline.outerWidth(outlineWidth);+ var $outlineResizeHandle = $outline.children(".ui-resizable-handle");+ $outline.resizable({+ autoHide: false,+ handles: {"w": $outlineResizeHandle},+ minWidth: 100,+ resize: function(e, ui) {+ var codeWidth = $code.outerWidth();+ if(codeWidth < 300)+ $(this).resizable({maxWidth: ui.size.width});+ },+ stop: function(e, ui) {+ $(this).resizable({maxWidth: undefined});+ Cookies.set(outlineWidthCookieKey, ui.size.width, {expires: Infinity});+ }+ });+ },+ showBlameMessage: function(tooltipId, message) {+ var $blameTooltip = $("#" + tooltipId);+ $blameTooltip.empty().text(message);+ $blameTooltip.align({placement: $blameTooltip.data("alignment"), target: {element: $blameTooltip.data("trigger")}});+ },+ restoreMark: function() {+ var $sourceView = $(".source-view");+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ var mark = $sourceView.data("mark");+ if (mark) {+ pmease.commons.codemirror.mark(cm, mark, false);+ } else {+ pmease.commons.codemirror.clearMark(cm);+ }+ },+ addCommentGutter: function(line, comments) {+ $(".comment-popover[data-line='" + line + "']").remove();++ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ var markCallback = $(".source-view").data("markCallback");++ var $gutter = $(document.createElement("div"));+ $gutter.addClass("CodeMirror-comment");+ $gutter.data("comments", comments);+ if (comments.length != 1) {+ /*+ * when there are multiple comments starts with the same line, we should+ * display a comment indicator which will display a comment popover with+ * list of comment triggers upon click, user can then click one of the+ * trigger link to display the actual comment content+ */+ $gutter.append("<a><i class='fa fa-comments'></i></a>");+ var $indicator = $gutter.children("a");+ var content = "";+ for (var i in comments) {+ var comment = comments[i];+ var index = parseInt(i) + 1;+ content += "<a class='comment-trigger' title='Click to show details of this comment'>#" + comment.id + "</a>";+ }+ $indicator.popover({+ html: true,+ container: ".source-view",+ placement: "right auto",+ template: "<div data-line='" + line + "' class='popover comment-popover'><div class='arrow'></div><div class='popover-content'></div></div>",+ content: content+ });+ $indicator.on('shown.bs.popover', function () {+ $(".comment-popover[data-line='" + line + "'] a").each(function() {+ $(this).mouseover(function() {+ var comment = comments[$(this).index()];+ pmease.commons.codemirror.mark(cm, comment.mark, false);+ });+ $(this).mouseout(function() {+ gitplex.sourceview.restoreMark();+ });+ $(this).click(function() {+ if ($(".source-view form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ var comment = comments[$(this).index()];+ markCallback("openComment", comment.id);+ });+ });+ gitplex.sourceview.highlightCommentTrigger();+ });+ } else {+ var comment = comments[0];+ $gutter.append("<a class='comment-trigger' title='Click to show comment of marked text'><i class='fa fa-commenting'></i></a>");+ var $indicator = $gutter.children("a");+ $indicator.mouseover(function() {+ pmease.commons.codemirror.mark(cm, comment.mark, false);+ });+ $indicator.mouseout(function() {+ gitplex.sourceview.restoreMark();+ });+ $indicator.click(function() {+ if ($(".source-view form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ markCallback("openComment", comment.id);+ });+ }+ cm.setGutterMarker(parseInt(line), "CodeMirror-comments", $gutter[0]);+ },+ openSelectionPopover: function(mark, markUrl, loggedIn) {+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ var ch = (mark.beginChar + mark.endChar)/2;+ var position = cm.charCoords({line:mark.beginLine, ch:ch});++ var $content = $("<div><a class='permanent'><i class='fa fa-link'></i> Permanent link of this selection</a>");+ $content.children("a.permanent").attr("href", markUrl);+ if (loggedIn) {+ $content.append("<a class='comment'><i class='fa fa-comment'></i> Add comment on this selection</a>");+ $content.children("a.comment").click(function() {+ if ($(".source-view").find("form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ var markCallback = $(".source-view").data("markCallback");+ markCallback("addComment", mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);+ });+ } else {+ $content.append("<span class='comment'><i class='fa fa-warning'></i> Log in to comment on selection</span>");+ }++ $(".source-view>.code").selectionPopover("open", {+ position: position,+ content: $content+ });+ },+ onCommentAdded: function(comment) {+ var $sourceView = $(".source-view");+ $sourceView.data("openComment", comment);+ $sourceView.data("mark", comment.mark);++ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ var line = parseInt(comment.mark.beginLine);+ var lineInfo = cm.lineInfo(line);+ var gutter;+ if (lineInfo.gutterMarkers)+ gutter = lineInfo.gutterMarkers["CodeMirror-comments"];+ var comments;+ if (gutter) {+ comments = $(gutter).data("comments");+ } else {+ comments = [];+ }+ comments.push(comment);+ gitplex.sourceview.addCommentGutter(line, comments);+ gitplex.sourceview.highlightCommentTrigger();+ gitplex.sourceview.onLayoutChange();+ },+ onCommentDeleted: function(comment) {+ var $sourceView = $(".source-view");+ $sourceView.removeData("openComment");++ var line = parseInt(comment.mark.beginLine);+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ var lineInfo = cm.lineInfo(line);+ var $gutter = $(lineInfo.gutterMarkers["CodeMirror-comments"]);+ var comments = $gutter.data("comments");+ if (comments.length == 1) {+ cm.setGutterMarker(line, "CodeMirror-comments", null);+ } else {+ for (var i in comments) {+ if (comments[i].id == comment.id) {+ comments.splice(i, 1);+ break;+ }+ }+ gitplex.sourceview.addCommentGutter(line, comments);+ }+ gitplex.sourceview.highlightCommentTrigger();+ gitplex.sourceview.onLayoutChange();++ gitplex.sourceview.mark(undefined, false);+ },+ onLayoutChange: function() {+ $sourceView = $('.source-view');+ $sourceView.trigger('autofit', [$sourceView.outerWidth(), $sourceView.outerHeight()]);+ },+ onAddComment: function(mark) {+ var $sourceView = $(".source-view");+ $sourceView.removeData("openComment");+ $sourceView.data("mark", mark);+ $(".source-view>.code").selectionPopover("close");++ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ pmease.commons.codemirror.clearSelection(cm);+ gitplex.sourceview.onLayoutChange();++ // mark and scroll after changing layout to make sure scroll+ // works correctly+ pmease.commons.codemirror.mark(cm, mark, true);++ gitplex.sourceview.highlightCommentTrigger();+ },+ onOpenComment: function(comment) {+ var $sourceView = $(".source-view");+ $sourceView.data("openComment", comment);+ $sourceView.data("mark", comment.mark);+ gitplex.sourceview.highlightCommentTrigger();+ gitplex.sourceview.onLayoutChange();++ // mark and scroll after changing layout to make sure scroll+ // works correctly+ gitplex.sourceview.mark(comment.mark, true);+ },+ onCloseComment: function() {+ var $sourceView = $(".source-view");+ $sourceView.removeData("openComment");+ gitplex.sourceview.highlightCommentTrigger();+ gitplex.sourceview.onLayoutChange();+ gitplex.sourceview.mark(undefined, false);+ },+ onToggleOutline: function() {+ gitplex.sourceview.onLayoutChange();+ $(".outline-toggle").toggleClass("active");+ },+ highlightCommentTrigger: function() {+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ $(".comment-popover a").removeClass("active");++ /*+ * we can not simply select all comment triggers via jQuery+ * as comment gutter may be create/destroy dynamically by+ * CodeMirror+ */+ for (var i=0; i<cm.lineCount(); i++) {+ var gutterMarkers = cm.lineInfo(i).gutterMarkers;+ if (gutterMarkers) {+ var gutter = gutterMarkers["CodeMirror-comments"];+ if (gutter) {+ $(gutter).children("a").removeClass("active");+ }+ }+ }++ var openComment = $(".source-view").data("openComment");+ if (openComment) {+ var line = parseInt(openComment.mark.beginLine);+ var lineInfo = cm.lineInfo(line);+ if (lineInfo && lineInfo.gutterMarkers) {+ var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];+ if (gutter) {+ var comments = $(gutter).data("comments");+ if (comments.length == 1) {+ $(gutter).children("a").addClass("active");+ } else {+ $(".comment-popover[data-line='" + line + "'] a").each(function() {+ var comment = comments[$(this).index()];+ if (comment.id == openComment.id) {+ $(this).addClass("active");+ }+ });+ }+ }+ }+ }+ },+ mark: function(mark, scroll) {+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ if (mark) {+ $(".source-view").data("mark", mark);+ pmease.commons.codemirror.mark(cm, mark, scroll);+ } else {+ $(".source-view").removeData("mark");+ pmease.commons.codemirror.clearMark(cm);+ }+ },+ blame: function(blameInfos) {+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ var alignment = {targetX: 100, targetY: 100, x: 0, y: 0};++ if (blameInfos) {+ var markCallback = $(".source-view").data("markCallback");+ var gutters = cm.getOption("gutters").slice();+ gutters.splice(1, 0, "CodeMirror-annotations");+ cm.setOption("gutters", gutters);+ for (var i in blameInfos) {+ var blameInfo = blameInfos[i];+ for (var j in blameInfo.ranges) {+ var range = blameInfo.ranges[j];+ var $gutter = $(document.createElement("div"));+ $gutter.addClass("CodeMirror-annotation");+ $("<a class='hash'>" + blameInfo.abbreviatedHash + "</a>").appendTo($gutter).attr("href", blameInfo.url);+ var $hashLink = $gutter.children("a.hash");+ $hashLink.data("hash", blameInfo.hash);+ $hashLink.data("line", range.from);++ $hashLink.hover(function() {+ var tooltipId = "blame-message-line-" + $(this).data("line");+ markCallback("showBlameMessage", tooltipId, $(this).data("hash"));+ var $tooltip = $("<div class='blame-message'><div class='loading'>Loading...</div></div>");+ $tooltip.attr("id", tooltipId);+ $tooltip.data("trigger", this);+ $tooltip.data("alignment", alignment);+ $(".source-view").append($tooltip);+ return $tooltip;+ }, alignment);++ $gutter.append("<span class='date'>" + blameInfo.commitDate + "</span>");+ $gutter.append("<span class='author'>" + blameInfo.authorName + "</span>");+ cm.setGutterMarker(range.from, "CodeMirror-annotations", $gutter[0]);++ for (var line = range.from+1; line<range.to; line++) {+ var $gutter = $(document.createElement("div"));+ $gutter.addClass("CodeMirror-annotation");+ $gutter.append("<span class='same-as-above'>...</span>");+ cm.setGutterMarker(line, "CodeMirror-annotations", $gutter[0]);+ }+ }+ }+ } else {+ cm.clearGutter("CodeMirror-annotations");+ var gutters = cm.getOption("gutters").slice();+ gutters.splice(1, 1);+ cm.setOption("gutters", gutters);+ }+ },+ onBlame: function(blameInfos) {+ gitplex.sourceview.blame(blameInfos);+ gitplex.sourceview.onLayoutChange();+ $(".blame-toggle").toggleClass("active");+ },+ scrollToCommentBottom: function() {+ var $body = $(".source-view>.comment>.content>.body");+ $body.scrollTop($body[0].scrollHeight);+ },+ onLineWrapModeChange: function(lineWrapMode) {+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ cm.setOption("lineWrapping", lineWrapMode == "Soft wrap");+ },+ onTabSizeChange: function(tabSize) {+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;+ cm.setOption("tabSize", tabSize);+ }+};diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.javaindex ff68f86fbe..3b135f4b02 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java@@ -284,8 +284,11 @@ public class TextDiffPanel extends Panel implements SourceAware {target.appendJavaScript(script);break;case "expand":- if (blameInfo != null)+ if (blameInfo != null) {blameInfo.lastCommitHash = null;+ blameInfo.lastOldCommitHash = null;+ blameInfo.lastNewCommitHash = null;+ }int index = params.getParameterValue("param1").toInt();Integer lastContextSize = contextSizes.get(index);if (lastContextSize == null)@@ -511,32 +514,53 @@ public class TextDiffPanel extends Panel implements SourceAware {StringBuilder builder = new StringBuilder();if (blameInfo != null) {blameInfo.lastCommitHash = null;- builder.append(""- + "<colgroup>"- + "<col width='240'></col>"- + "<col width='60'></col>"- + "<col width='60'></col>"- + "<col width='15'></col>"- + "<col></col>"- + "</colgroup>");- } else if (diffMode == DiffViewMode.UNIFIED) {- builder.append(""- + "<colgroup>"- + "<col width='60'></col>"- + "<col width='60'></col>"- + "<col width='15'></col>"- + "<col></col>"- + "</colgroup>");+ blameInfo.lastOldCommitHash = null;+ blameInfo.lastNewCommitHash = null;+ }++ if (diffMode == DiffViewMode.UNIFIED) {+ if (blameInfo != null) {+ builder.append(""+ + "<colgroup>"+ + "<col width='240'></col>"+ + "<col width='60'></col>"+ + "<col width='60'></col>"+ + "<col width='15'></col>"+ + "<col></col>"+ + "</colgroup>");+ } else {+ builder.append(""+ + "<colgroup>"+ + "<col width='60'></col>"+ + "<col width='60'></col>"+ + "<col width='15'></col>"+ + "<col></col>"+ + "</colgroup>");+ }} else {- builder.append(""- + "<colgroup>"- + "<col width='60'></col>"- + "<col width='15'></col>"- + "<col></col>"- + "<col width='60'></col>"- + "<col width='15'></col>"- + "<col></col>"- + "</colgroup>");+ if (blameInfo != null) {+ builder.append(""+ + "<colgroup>"+ + "<col width='240'></col>"+ + "<col width='60'></col>"+ + "<col width='15'></col>"+ + "<col></col>"+ + "<col width='240'></col>"+ + "<col width='60'></col>"+ + "<col width='15'></col>"+ + "<col></col>"+ + "</colgroup>");+ } else {+ builder.append(""+ + "<colgroup>"+ + "<col width='60'></col>"+ + "<col width='15'></col>"+ + "<col></col>"+ + "<col width='60'></col>"+ + "<col width='15'></col>"+ + "<col></col>"+ + "</colgroup>");+ }}for (int i=0; i<getDiffBlocks().size(); i++) {MarkAwareDiffBlock block = getDiffBlocks().get(i);@@ -553,7 +577,7 @@ public class TextDiffPanel extends Panel implements SourceAware {if (nextBlock.getType() == Type.INSERT) {LinkedHashMap<Integer, LineDiff> lineChanges =DiffUtils.align(block.getLines(), nextBlock.getLines());- if (blameInfo != null) {+ if (blameInfo != null && diffMode == DiffViewMode.UNIFIED) {for (int j=0; j<block.getLines().size(); j++) {LineDiff lineDiff = lineChanges.get(j);if (lineDiff != null) {@@ -638,11 +662,13 @@ public class TextDiffPanel extends Panel implements SourceAware {private void appendBlame(StringBuilder builder, int oldLineNo, int newLineNo) {BriefCommit commit;- if (oldLineNo != -1)- commit = Preconditions.checkNotNull(blameInfo.oldBlame.get(oldLineNo));- else+ if (newLineNo != -1)commit = Preconditions.checkNotNull(blameInfo.newBlame.get(newLineNo));- if (!commit.getHash().equals(blameInfo.lastCommitHash)) {+ else+ commit = Preconditions.checkNotNull(blameInfo.oldBlame.get(oldLineNo));+ if (diffMode == DiffViewMode.UNIFIED && !commit.getHash().equals(blameInfo.lastCommitHash)+ || diffMode == DiffViewMode.SPLIT && newLineNo != -1 && !commit.getHash().equals(blameInfo.lastNewCommitHash)+ || diffMode == DiffViewMode.SPLIT && oldLineNo != -1 && !commit.getHash().equals(blameInfo.lastOldCommitHash)) {CommitDetailPage.State state = new CommitDetailPage.State();state.revision = commit.getHash();state.whitespaceOption = change.getWhitespaceOption();@@ -656,6 +682,10 @@ public class TextDiffPanel extends Panel implements SourceAware {builder.append("<td class='blame noselect'><div class='same-as-above'>...</div></td>");}blameInfo.lastCommitHash = commit.getHash();+ if (newLineNo != -1)+ blameInfo.lastNewCommitHash = commit.getHash();+ if (oldLineNo != -1)+ blameInfo.lastOldCommitHash = commit.getHash();}private void appendEqual(StringBuilder builder, MarkAwareDiffBlock block, int lineIndex, int lastContextSize) {@@ -667,7 +697,7 @@ public class TextDiffPanel extends Panel implements SourceAware {int oldLineNo = block.getOldStart() + lineIndex;int newLineNo = block.getNewStart() + lineIndex;- if (diffMode == DiffViewMode.UNIFIED || blameInfo != null) {+ if (diffMode == DiffViewMode.UNIFIED) {if (blameInfo != null) {appendBlame(builder, oldLineNo, newLineNo);}@@ -685,6 +715,9 @@ public class TextDiffPanel extends Panel implements SourceAware {}builder.append("</td>");} else {+ if (blameInfo != null) {+ appendBlame(builder, oldLineNo, -1);+ }builder.append("<td class='number noselect'>").append(oldLineNo+1).append("</td>");builder.append("<td class='operation noselect'> </td>");builder.append("<td class='content left' data-old='").append(oldLineNo).append("' data-new='").append(newLineNo).append("'>");@@ -697,6 +730,9 @@ public class TextDiffPanel extends Panel implements SourceAware {}}builder.append("</td>");+ if (blameInfo != null) {+ appendBlame(builder, -1, newLineNo);+ }builder.append("<td class='number noselect'>").append(newLineNo+1).append("</td>");builder.append("<td class='operation noselect'> </td>");builder.append("<td class='content right' data-old='").append(oldLineNo).append("' data-new='").append(newLineNo).append("'>");@@ -717,7 +753,7 @@ public class TextDiffPanel extends Panel implements SourceAware {builder.append("<tr class='code original'>");int newLineNo = block.getNewStart() + lineIndex;- if (diffMode == DiffViewMode.UNIFIED || blameInfo != null) {+ if (diffMode == DiffViewMode.UNIFIED) {if (blameInfo != null) {appendBlame(builder, -1, newLineNo);}@@ -747,9 +783,15 @@ public class TextDiffPanel extends Panel implements SourceAware {}builder.append("</td>");} else {+ if (blameInfo != null) {+ builder.append("<td class='blame noselect'> </td>");+ }builder.append("<td class='number noselect'> </td>");builder.append("<td class='operation noselect'> </td>");builder.append("<td class='content left'> </td>");+ if (blameInfo != null) {+ appendBlame(builder, -1, newLineNo);+ }builder.append("<td class='number noselect new'>").append(newLineNo+1).append("</td>");builder.append("<td class='operation noselect new'>+</td>");builder.append("<td class='content right new' data-new='").append(newLineNo).append("'>");@@ -769,7 +811,7 @@ public class TextDiffPanel extends Panel implements SourceAware {builder.append("<tr class='code original'>");int oldLineNo = block.getOldStart() + lineIndex;- if (diffMode == DiffViewMode.UNIFIED || blameInfo != null) {+ if (diffMode == DiffViewMode.UNIFIED ) {if (blameInfo != null) {appendBlame(builder, oldLineNo, -1);}@@ -799,6 +841,9 @@ public class TextDiffPanel extends Panel implements SourceAware {}builder.append("</td>");} else {+ if (blameInfo != null) {+ appendBlame(builder, oldLineNo, -1);+ }builder.append("<td class='number noselect old'>").append(oldLineNo+1).append("</td>");builder.append("<td class='operation noselect old'>-</td>");builder.append("<td class='content left old' data-old='").append(oldLineNo).append("'>");@@ -810,6 +855,9 @@ public class TextDiffPanel extends Panel implements SourceAware {builder.append(tokens.get(i).toHtml(Operation.EQUAL));}builder.append("</td>");+ if (blameInfo != null) {+ builder.append("<td class='blame noselect'> </td>");+ }builder.append("<td class='number noselect'> </td>");builder.append("<td class='operation noselect'> </td>");builder.append("<td class='content right'> </td>");@@ -822,6 +870,9 @@ public class TextDiffPanel extends Panel implements SourceAware {builder.append("<tr class='code original'>");int oldLineNo = deleteBlock.getOldStart()+deleteLineIndex;+ if (blameInfo != null) {+ appendBlame(builder, oldLineNo, -1);+ }builder.append("<td class='number noselect old'>").append(oldLineNo+1).append("</td>");builder.append("<td class='operation noselect old'>-</td>");builder.append("<td class='content left old' data-old='").append(oldLineNo).append("'>");@@ -835,6 +886,9 @@ public class TextDiffPanel extends Panel implements SourceAware {builder.append("</td>");int newLineNo = insertBlock.getNewStart()+insertLineIndex;+ if (blameInfo != null) {+ appendBlame(builder, -1, newLineNo);+ }builder.append("<td class='number noselect new'>").append(newLineNo+1).append("</td>");builder.append("<td class='operation noselect new'>+</td>");builder.append("<td class='content right new' data-new='").append(newLineNo).append("'>");@@ -858,6 +912,9 @@ public class TextDiffPanel extends Panel implements SourceAware {int oldLineNo = deleteBlock.getOldStart() + deleteLineIndex;int newLineNo = insertBlock.getNewStart() + insertLineIndex;if (diffMode == DiffViewMode.UNIFIED) {+ if (blameInfo != null) {+ appendBlame(builder, oldLineNo, newLineNo);+ }builder.append("<td class='number noselect old new'>").append(oldLineNo+1).append("</td>");builder.append("<td class='number noselect old new'>").append(newLineNo+1).append("</td>");builder.append("<td class='operation noselect old new'>*</td>");@@ -872,6 +929,9 @@ public class TextDiffPanel extends Panel implements SourceAware {}builder.append("</td>");} else {+ if (blameInfo != null) {+ appendBlame(builder, oldLineNo, -1);+ }builder.append("<td class='number noselect old'>").append(oldLineNo+1).append("</td>");builder.append("<td class='operation noselect old'>-</td>");builder.append("<td class='content left old' data-old='").append(oldLineNo).append("'>");@@ -887,6 +947,9 @@ public class TextDiffPanel extends Panel implements SourceAware {}builder.append("</td>");+ if (blameInfo != null) {+ appendBlame(builder, -1, newLineNo);+ }builder.append("<td class='number noselect new'>").append(newLineNo+1).append("</td>");builder.append("<td class='operation noselect new'>+</td>");builder.append("<td class='content right new' data-new='").append(newLineNo).append("'>");@@ -910,11 +973,13 @@ public class TextDiffPanel extends Panel implements SourceAware {builder.append("<tr class='expander expander").append(blockIndex).append("'>");String script = String.format("javascript:$('#%s').data('callback')('expand', %d);", getMarkupId(), blockIndex);- if (diffMode == DiffViewMode.UNIFIED || blameInfo != null) {+ if (diffMode == DiffViewMode.UNIFIED) {if (blameInfo != null) {builder.append("<td colspan='3' class='expander noselect'><a title='Show more lines' href=\"").append(script).append("\"><i class='fa fa-sort'></i></a></td>");blameInfo.lastCommitHash = null;+ blameInfo.lastOldCommitHash = null;+ blameInfo.lastNewCommitHash = null;} else {builder.append("<td colspan='2' class='expander noselect'><a title='Show more lines' href=\"").append(script).append("\"><i class='fa fa-sort'></i></a></td>");@@ -922,10 +987,20 @@ public class TextDiffPanel extends Panel implements SourceAware {builder.append("<td colspan='2' class='skipped noselect'><i class='fa fa-ellipsis-h'></i> skipped ").append(skippedLines).append(" lines <i class='fa fa-ellipsis-h'></i></td>");} else {- builder.append("<td class='expander noselect'><a title='Show more lines' href=\"").append(script)- .append("\"><i class='fa fa-sort'></i></a></td>");- builder.append("<td class='skipped noselect' colspan='5'><i class='fa fa-ellipsis-h'></i> skipped ")- .append(skippedLines).append(" lines <i class='fa fa-ellipsis-h'></i></td>");+ if (blameInfo != null) {+ builder.append("<td colspan='2' class='expander noselect'><a title='Show more lines' href=\"").append(script)+ .append("\"><i class='fa fa-sort'></i></a></td>");+ builder.append("<td class='skipped noselect' colspan='6'><i class='fa fa-ellipsis-h'></i> skipped ")+ .append(skippedLines).append(" lines <i class='fa fa-ellipsis-h'></i></td>");+ blameInfo.lastCommitHash = null;+ blameInfo.lastOldCommitHash = null;+ blameInfo.lastNewCommitHash = null;+ } else {+ builder.append("<td class='expander noselect'><a title='Show more lines' href=\"").append(script)+ .append("\"><i class='fa fa-sort'></i></a></td>");+ builder.append("<td class='skipped noselect' colspan='5'><i class='fa fa-ellipsis-h'></i> skipped ")+ .append(skippedLines).append(" lines <i class='fa fa-ellipsis-h'></i></td>");+ }}builder.append("</tr>");}@@ -1122,6 +1197,10 @@ public class TextDiffPanel extends Panel implements SourceAware {String lastCommitHash;+ String lastOldCommitHash;++ String lastNewCommitHash;+}}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.cssindex b15f666346..6bc1914596 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.css@@ -1,207 +1,208 @@-.text-diff {- border: 1px solid #D8D8D8;- position: relative;-}-.text-diff>.head {- padding: 8px;- border-bottom: 1px solid #D8D8D8;-}-.text-diff>.head .actions>a {- margin-right: 0;-}-.text-diff>.head>div {- margin-right: 8px;-}-.text-diff>.head>div:last-child {- margin-right: 0;-}-.text-diff>.body {- font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;- font-size: 12px;- table-layout: fixed;- border-collapse: separate;-}--/*- * have to use relative here as otherwise the last table row will have problem- * focusing on expander link. This relates to negative margin top- * specified for change class in revision diff panel- */-.text-diff>.body>tbody>tr>td {- position: relative;-}-.text-diff>.body>tbody>tr>td.number {- padding: 0 4px;- border-left: 1px solid #EEE;- text-align: right;- font-size: 12px;- color: #BBB;-}-.text-diff>.body>tbody>tr>td.operation {- border-left: 1px solid #EEE;-}-.text-diff>.body>tbody>tr>td:FIRST-CHILD {- border-left: none !important;-}-.text-diff>.body>tbody>tr:FIRST-CHILD>td {- border-top: none !important;-}-.text-diff>.body>tbody>tr:LAST-CHILD>td {- border-bottom: none !important;-}-.text-diff>.body>tbody>tr.expander>td.skipped {- padding: 6px 16px;- border-left: 1px solid #D8E2F2;- background: #f4f7fb;- color: #999;-}-.text-diff>.body>tbody>tr.expander>td.expander {- border-left: 1px solid #D8E2F2;- text-align: center;-}-.text-diff>.body>tbody>tr.expander>td.expander a {- display: block;- background: #edf2f9;- padding: 6px 0;- color: #888;-}-.text-diff>.body>tbody>tr.expander>td.expander>a:hover {- background: #4078c0;- color: white;-}-.text-diff>.body>tbody>tr>td.old.number {- background: #ffdddd;- border-left: 1px solid #f1c0c0;-}-.text-diff>.body>tbody>tr>td.old.content {- background: #ffecec;-}-.text-diff>.body>tbody>tr>td.old.operation {- border-left: 1px solid #f1c0c0;- background: #ffecec;-}-.text-diff>.body>tbody>tr>td.old .delete {- background-color: #F8C8C8;-}-.text-diff>.body>tbody>tr>td.new.number {- background: #dbffdb;- border-left: 1px solid #c1e9c1;-}-.text-diff>.body>tbody>tr>td.new.content {- background: #eaffea;-}-.text-diff>.body>tbody>tr>td.new.operation {- border-left: 1px solid #c1e9c1;- background: #eaffea;-}-.text-diff>.body>tbody>tr>td.new .insert {- background-color: #94F094;-}-.text-diff>.body>tbody>tr>td.old.new.number {- background: #FAF3D0;- border-left: 1px solid #EBD049;-}-.text-diff>.body>tbody>tr>td.old.new.content {- background: #FCF8E4;-}-.text-diff>.body>tbody>tr>td.old.new.operation {- border-left: 1px solid #EBD049;- background: #FCF8E4;-}-.text-diff>.body>tbody>tr>td.content {- white-space: pre-wrap;- word-wrap: break-word;-}-.text-diff>.body>tbody>tr>td.operation {- font-weight: bold;- padding: 0 4px 0 4px;-}-.text-diff>.body>tbody>tr.original+.expanded>td {- border-top: 1px solid #E8E8E8;-}-.text-diff>.body>tbody>tr.expanded+.original>td {- border-top: 1px solid #E8E8E8;-}-.text-diff>.body>tbody>tr.expanded>td {- background: #F9F9F9;-}-.text-diff>.body>tbody>tr>td.content>span.content-mark {- background: #CCCCFF;-}-.text-diff>.body>tbody>tr>td.content>span.content-mark.insert {- background: #88FFFF;-}-.text-diff>.body>tbody>tr>td.content>span.content-mark.delete {- background: #FF88FF;-}--.text-diff>.body>tbody>tr>td.number>.comment-indicator {- margin: 0 4px;- color: #999;-}-.text-diff>.body>tbody>tr>td.number>.comment-indicator:hover {- color: #333;-}-.comment-popover a {- display: block;- color: #999;- text-decoration: none;- white-space: nowrap;-}-.comment-popover a:hover {- color: #333;-}-.text-diff>.body>tbody>tr>td.number>.comment-trigger.active,-.comment-popover .comment-trigger.active {- font-size: 16px;- color: #333;-}-.text-diff>.body>tbody>tr>td.number>.comment-trigger.active {- line-height: 14px;-}-.text-diff>.body>tbody>tr>td.blame {- font-family: monospace;- text-overflow: ellipsis;- overflow: hidden;- white-space: nowrap;- padding: 0 4px;-}-.text-diff>.body>tbody>tr>td.blame .hash, .text-diff>.body>tbody>tr>td.blame .date {- margin-right: 8px;-}-.text-diff>.body>tbody>tr>td.blame .same-as-above {- margin-left: 100px;- margin-top: -8px;- color: #666;- font-size: 16px;-}-.text-diff>.body>tbody>tr:hover>td {- background: #E8F2FE !important;-}--.blame-message {- white-space: pre-wrap;- word-wrap: break-word;- position: absolute;- z-index: 10000;- font-size: 13px;- background-color: #FBFCC5;- border: 1px solid black;- border-radius: 4px;- color: black;- padding: 8px;-}--.diff-tokentooltip {- background-color: #FBFCC5;- border: 1px solid black;- border-radius: 4px;- color: black;- font-family: monospace;- font-size: 10pt;- overflow: auto;- padding: 4px 8px;- z-index: 100;- max-width: 900px;- max-height: 600px;-}+.text-diff {+ border: 1px solid #D8D8D8;+ position: relative;+}+.text-diff>.head {+ padding: 8px;+ border-bottom: 1px solid #D8D8D8;+}+.text-diff>.head .actions>a {+ margin-right: 0;+}+.text-diff>.head>div {+ margin-right: 8px;+}+.text-diff>.head>div:last-child {+ margin-right: 0;+}+.text-diff>.body {+ font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;+ font-size: 12px;+ table-layout: fixed;+ border-collapse: separate;+}++/*+ * have to use relative here as otherwise the last table row will have problem+ * focusing on expander link. This relates to negative margin top+ * specified for change class in revision diff panel+ */+.text-diff>.body>tbody>tr>td {+ position: relative;+}+.text-diff>.body>tbody>tr>td.number {+ padding: 0 4px;+ border-left: 1px solid #EEE;+ text-align: right;+ font-size: 12px;+ color: #BBB;+}+.text-diff>.body>tbody>tr>td.operation {+ border-left: 1px solid #EEE;+}+.text-diff>.body>tbody>tr>td:FIRST-CHILD {+ border-left: none !important;+}+.text-diff>.body>tbody>tr:FIRST-CHILD>td {+ border-top: none !important;+}+.text-diff>.body>tbody>tr:LAST-CHILD>td {+ border-bottom: none !important;+}+.text-diff>.body>tbody>tr.expander>td.skipped {+ padding: 6px 16px;+ border-left: 1px solid #D8E2F2;+ background: #f4f7fb;+ color: #999;+}+.text-diff>.body>tbody>tr.expander>td.expander {+ border-left: 1px solid #D8E2F2;+ text-align: center;+}+.text-diff>.body>tbody>tr.expander>td.expander a {+ display: block;+ background: #edf2f9;+ padding: 6px 0;+ color: #888;+}+.text-diff>.body>tbody>tr.expander>td.expander>a:hover {+ background: #4078c0;+ color: white;+}+.text-diff>.body>tbody>tr>td.old.number {+ background: #ffdddd;+ border-left: 1px solid #f1c0c0;+}+.text-diff>.body>tbody>tr>td.old.content {+ background: #ffecec;+}+.text-diff>.body>tbody>tr>td.old.operation {+ border-left: 1px solid #f1c0c0;+ background: #ffecec;+}+.text-diff>.body>tbody>tr>td.old .delete {+ background-color: #F8C8C8;+}+.text-diff>.body>tbody>tr>td.new.number {+ background: #dbffdb;+ border-left: 1px solid #c1e9c1;+}+.text-diff>.body>tbody>tr>td.new.content {+ background: #eaffea;+}+.text-diff>.body>tbody>tr>td.new.operation {+ border-left: 1px solid #c1e9c1;+ background: #eaffea;+}+.text-diff>.body>tbody>tr>td.new .insert {+ background-color: #94F094;+}+.text-diff>.body>tbody>tr>td.old.new.number {+ background: #FAF3D0;+ border-left: 1px solid #EBD049;+}+.text-diff>.body>tbody>tr>td.old.new.content {+ background: #FCF8E4;+}+.text-diff>.body>tbody>tr>td.old.new.operation {+ border-left: 1px solid #EBD049;+ background: #FCF8E4;+}+.text-diff>.body>tbody>tr>td.content {+ white-space: pre-wrap;+ word-wrap: break-word;+}+.text-diff>.body>tbody>tr>td.operation {+ font-weight: bold;+ padding: 0 4px 0 4px;+}+.text-diff>.body>tbody>tr.original+.expanded>td {+ border-top: 1px solid #E8E8E8;+}+.text-diff>.body>tbody>tr.expanded+.original>td {+ border-top: 1px solid #E8E8E8;+}+.text-diff>.body>tbody>tr.expanded>td {+ background: #F9F9F9;+}+.text-diff>.body>tbody>tr>td.content>span.content-mark {+ background: #CCCCFF;+}+.text-diff>.body>tbody>tr>td.content>span.content-mark.insert {+ background: #88FFFF;+}+.text-diff>.body>tbody>tr>td.content>span.content-mark.delete {+ background: #FF88FF;+}++.text-diff>.body>tbody>tr>td.number>.comment-indicator {+ margin: 0 4px;+ color: #999;+}+.text-diff>.body>tbody>tr>td.number>.comment-indicator:hover {+ color: #333;+}+.comment-popover a {+ display: block;+ color: #999;+ text-decoration: none;+ white-space: nowrap;+}+.comment-popover a:hover {+ color: #333;+}+.text-diff>.body>tbody>tr>td.number>.comment-trigger.active,+.comment-popover .comment-trigger.active {+ font-size: 16px;+ color: #333;+}+.text-diff>.body>tbody>tr>td.number>.comment-trigger.active {+ line-height: 14px;+}+.text-diff>.body>tbody>tr>td.blame {+ font-family: monospace;+ text-overflow: ellipsis;+ overflow: hidden;+ white-space: nowrap;+ padding: 0 4px;+ border-left: 1px solid #EEE;+}+.text-diff>.body>tbody>tr>td.blame .hash, .text-diff>.body>tbody>tr>td.blame .date {+ margin-right: 8px;+}+.text-diff>.body>tbody>tr>td.blame .same-as-above {+ margin-left: 100px;+ margin-top: -8px;+ color: #666;+ font-size: 16px;+}+.text-diff>.body>tbody>tr:hover>td {+ background: #E8F2FE !important;+}++.blame-message {+ white-space: pre-wrap;+ word-wrap: break-word;+ position: absolute;+ z-index: 10000;+ font-size: 13px;+ background-color: #FBFCC5;+ border: 1px solid black;+ border-radius: 4px;+ color: black;+ padding: 8px;+}++.diff-tokentooltip {+ background-color: #FBFCC5;+ border: 1px solid black;+ border-radius: 4px;+ color: black;+ font-family: monospace;+ font-size: 10pt;+ overflow: auto;+ padding: 4px 8px;+ z-index: 100;+ max-width: 900px;+ max-height: 600px;+}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.jsindex 01ec1a382a..34df81f571 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/text-diff.js@@ -1,908 +1,917 @@-gitplex.textdiff = {- symbolClasses: ".cm-property, .cm-variable, .cm-variable-2, .cm-variable-3, .cm-def, .cm-meta",- init: function(containerId, symbolTooltipId, oldRev, newRev, scroll, callback,- markSupport, mark, openComment, oldComments, newComments, dirtyContainerId) {- var $container = $("#" + containerId);- $container.data("dirtyContainerId", dirtyContainerId);- $container.data("callback", callback);- $container.data("symbolHover", function() {- var revision;- var $symbol = $(this);- if ($symbol.hasClass("delete")) {- revision = oldRev;- } else {- var $td = $symbol.closest("td");-- // if is deleted line or if it is on left side of split view- if ($td.hasClass("old") && !$td.hasClass("new") || $td.next().is("td"))- revision = oldRev;- else- revision = newRev;- }- var symbolTooltip = document.getElementById(symbolTooltipId);- if (symbolTooltip.onMouseOverSymbol)- symbolTooltip.onMouseOverSymbol(revision, this);- });- $container.data("onMouseOverContent", function() {- if (!gitplex.mouseState.pressed) {- if ($(this).hasClass("left")) {- $container.find("td.content.right").addClass("noselect");- $container.find("td.content.left").removeClass("noselect");- } else if ($(this).hasClass("right")) {- $container.find("td.content.left").addClass("noselect");- $container.find("td.content.right").removeClass("noselect");- }- }- });- var $symbols = $container.find(gitplex.textdiff.symbolClasses);- $symbols.mouseover($container.data("symbolHover"));- $container.find("td.content").mouseover($container.data("onMouseOverContent"));-- gitplex.textdiff.initBlameTooltip(containerId, $container.find("td.blame>a.hash"));-- if (markSupport) {- $container.selectionPopover("init", function() {- var selection = window.getSelection();- if (!selection.rangeCount) {- return "close";- }- var firstRange = selection.getRangeAt(0).cloneRange();- var lastRange = selection.getRangeAt(selection.rangeCount-1).cloneRange();- var $start = $(firstRange.startContainer);- var $end = $(lastRange.endContainer);-- /*- * offset represents offset within $start or $end node, for instance for below selection- * <span>hello</span><span>world</span>- * ^ ^- * $start will be <span>hello</span> and startOffset will be index of character 'l' which is 2,- * $end will be <span>world</span> and endOffset will be index of character 'd' which will be 4- */- var startOffset = firstRange.startOffset;- var endOffset = lastRange.endOffset;-- var $startDiff;- if (!$start.hasClass("text-diff"))- $startDiff = $start.closest(".text-diff");- else- $startDiff = $start;-- var $endDiff;- if (!$end.hasClass("text-diff"))- $endDiff = $end.closest(".text-diff");- else- $endDiff = $end;-- // selection must be within same file- if ($startDiff.length == 0 || $endDiff.length == 0 || !$startDiff.is($endDiff)) {- return "close";- }-- var $startTd = $start.is("td.content")? $start: $start.closest(".text-diff td.content");- var $endTd = $end.is("td.content")? $end: $end.closest(".text-diff td.content");-- // at least one side of selection must be within a table cell- if ($startTd.length == 0 && $endTd.length == 0) {- return "close";- }-- // make sure we are processing td.content on the same side on split view- function getTd($tr) {- var $td = $startTd.length != 0? $startTd: $endTd;- if ($td.hasClass("left"))- return $tr.find("td.content.left");- else if ($td.hasClass("right"))- return $tr.find("td.content.right");- else- return $tr.find("td.content");- }-- /*- * sometimes the selection returns $start and $end as td instead of- * children under td, for instance:- * <td><span>hello</span><span>world</span></td>- * ^- * in this case, both $start and $end is the whole td, and startOffset- * is index of first span element which is 0, and endOffset is index of- * last span element plus 1 which is 2.- *- * this function returns the equivalent child node and offset under td.- * with above example, the equivalent child node will be <span>hello</span>- * and offset will be 0 for selection start, while equivalent end child node- * is <span>world</span> with offset being 5- *- */- function getNodeAndOffsetUnderTd($td, contentIndex) {- var $contents = $td.contents();- for (var i=0; i<$contents.length; i++) {- if (i == contentIndex) {- return {- node: $($contents[i]),- offset: 0- }- }- }- var $lastContent = $contents.last();- return {- node: $lastContent,- offset: $lastContent.text().length- }- }-- // normalize $start to be within td.content- if ($start.parent().parent().is("td.content")) // $start might be the text node under span- $start = $start.parent();- if (!$start.parent().is("td.content")) {- var $td;- if ($start.is("td.content")) { // this happens if we triple click to select a line in firefox- $td = $start;- } else if ($start.is("tr.code")) { // this may happen if we drag mouse to select multiple lines in firefox- $td = getTd($start);- startOffset = startOffset<=$td.index()? 0: $td.contents().length;- } else if ($start.is("tr.expander") || $start.closest("tr.expander").length != 0) { // this may happen if we drag mouse over to expander line- var $tr = $start.is("tr.expander")? $start.next(): $start.closest("tr.expander").next();- if ($tr.length == 0) {- return "close";- }- $td = getTd($tr);- startOffset = 0;- } else {- var $tr = $startDiff.find("tr.code").first();- if ($tr.length == 0) {- return "close";- }- $td = getTd($tr);- startOffset = 0;- }- var nodeAndOffset = getNodeAndOffsetUnderTd($td, startOffset);- $start = nodeAndOffset.node;- startOffset = nodeAndOffset.offset;- }-- // drag mouse over a line below expander, chrome may set $start as the line- // above expander, below code normalizes this case- $startTd = $start.parent();- var $lastContent = $startTd.contents().last();- var noneSelected = $start.is($lastContent) && startOffset >= $lastContent.text().length;- if (noneSelected && $startTd.parent().next().is("tr.expander")) {- var $tr = $startTd.parent().next().next();- if ($tr.length == 0) {- return "close";- }- var $td = getTd($tr);- $start = $td.contents().first();- startOffset = 0;- }-- // normalize $end to be within td.content- if ($end.parent().parent().is("td.content"))- $end = $end.parent();- if (!$end.parent().is("td.content")) {- var $td;- if ($end.is("td.content")) {- $td = $end;- } else if ($end.is("tr.code")) {- $td = getTd($end);- endOffset = endOffset>$td.index()? $td.contents().length: 0;- } else if ($end.is("tr.expander") || $end.closest("tr.expander").length != 0) {- var $tr = $end.is("tr.expander")? $end.prev(): $end.closest("tr.expander").prev();- if ($tr.length == 0) {- return "close";- }- $td = getTd($tr);- endOffset = $td.contents().length;- } else {- var $tr = $endDiff.find("tr.code").last();- if ($tr.length == 0) {- return "close";- }- $td = getTd($tr);- endOffset = $td.contents().length;- }- var nodeAndOffset = getNodeAndOffsetUnderTd($td, endOffset);- $end = nodeAndOffset.node;- endOffset = nodeAndOffset.offset;- }-- // drag mouse over a line above expander, chrome may set $end as the line- // below expander, below code normalizes this case- $endTd = $end.parent();- var $firstContent = $endTd.contents().first();- var noneSelected = $end.is($firstContent) && endOffset == 0;- if (noneSelected && $endTd.parent().prev().is("tr.expander")) {- var $tr = $endTd.parent().prev().prev();- if ($tr.length == 0) {- return "close";- }- var $td = getTd($tr);- $end = $td.contents().last();- endOffset = $end.text().length;- }-- $startTd = $start.parent();- $endTd = $end.parent();-- // selection must not span the split view- if ($startTd.hasClass("left") && $endTd.hasClass("right")- || $startTd.hasClass("right") && $endTd.hasClass("left")) {- return "close";- }-- var $startTr = $startTd.parent();- var $endTr = $endTd.parent();- if ($startTr.index() > $endTr.index()) {- return "close";- }-- function nextContent($content) {- var $td = $content.parent();- var array = $td.contents().toArray();- var index = array.indexOf($content[0]);- if (index == array.length-1) {- var $nextTr = $td.parent().next();- if ($nextTr.hasClass("expander")) {- $nextTr = $nextTr.next();- }- if ($nextTr.length == 0)- return undefined;- return getTd($nextTr).contents().first();- } else {- return $(array[index+1]);- }- }-- function prevContent($content) {- var $td = $content.parent();- var array = $td.contents().toArray();- var index = array.indexOf($content[0]);- if (index == 0) {- var $prevTr = $td.parent().prev();- if ($prevTr.hasClass("expander")) {- $prevTr = $prevTr.next();- }- if ($prevTr.length == 0)- return undefined;- return getTd($prevTr).contents().last();- } else {- return $(array[index-1]);- }- }-- function hasOldOrNewData($content) {- var $td = $content.parent();- return $td.attr("data-old") || $td.attr("data-new");- }-- /*- * continue to normalize $start and $end. This time we convert below selection:- * <span>begin</span><span>middle</span><span>end</span>- * ^ ^- * into this selection:- * <span>begin</span><span>middle</span><span>end</span>- * ^ ^- * this normalization makes it accurate to detect invalid selections where start- * and end of selection points to different revisions- */- var $content = $start;- while (!$content.is($end) && (startOffset >= $content.text().length || !hasOldOrNewData($content))) {- $content = nextContent($content);- if (!$content) {- return "close";- } else {- $start = $content;- startOffset = 0;- }- }-- $content = $end;- while (!$content.is($start) && (endOffset == 0 || !hasOldOrNewData($content))) {- $content = prevContent($content);- if (!$content) {- return "close";- } else {- $end = $content;- endOffset = $content.text().length;- }- }-- // check if there is anything selected- if ($start.is($end) && startOffset >= endOffset- || !hasOldOrNewData($start) || !hasOldOrNewData($end)) {- return "close";- }-- firstRange.collapse(true);- var startRect = firstRange.getClientRects()[0];- lastRange.collapse(false);- var endRect = lastRange.getClientRects()[0];- if (!startRect || !endRect) {- startRect = selection.getRangeAt(0).getClientRects()[0];- endRect = startRect;- }- var position = {- left: (startRect.left + endRect.right)/2,- top: startRect.top- };- position.left += $(window).scrollLeft();- position.top += $(window).scrollTop();-- function showInvalidSelection() {- var $content = $("<div></div>");- $content.append("<a class='invalid'><i class='fa fa-warning'></i> Invalid selection, click for details</a>");- $content.children("a").attr("href", "http://wiki.pmease.com/display/gp/Diff+Selection");- return {- position: position,- content: $content- }- }-- // all lines between selection has been expanded- if ($startTr.nextAll("tr.expander").filter($endTr.prevAll("tr.expander")).length != 0- || $startTr.prevAll("tr.expander").filter($endTr.nextAll("tr.expander")).length != 0) {- return showInvalidSelection();- }-- /*- * cursor.line represents line number of selection and cursor.ch represents- * character index inside text of the whole line, without considering element- * tags.- */- function getCursor($node, offset) {- $nodeTd = $node.parent();- var oldLine, newLine;- if (!$nodeTd.hasClass("old") && !$nodeTd.hasClass("new")- || $nodeTd.hasClass("old") && $nodeTd.hasClass("new")) {- oldLine = $nodeTd.data("old") + 1;- newLine = $nodeTd.data("new") + 1;- } else if ($nodeTd.hasClass("old")) {- oldLine = $nodeTd.data("old") + 1;- } else {- newLine = $nodeTd.data("new") + 1;- }- var $contents = $nodeTd.contents();- var oldOffset = 0, newOffset = 0;- for (var i=0; i<$contents.length; i++) {- var $content = $($contents[i]);- if ($content.is($node)) {- if ($content.hasClass("delete")) {- oldCh = oldOffset + offset;- newCh = undefined;- newLine = undefined;- } else if ($content.hasClass("insert")) {- oldCh = undefined;- oldLine = undefined;- newCh = newOffset + offset;- } else {- oldCh = oldOffset + offset;- newCh = newOffset + offset;- }- break;- } else {- var len = $content.text().length;- if ($content.hasClass("delete")) {- oldOffset += len;- } else if ($content.hasClass("insert")) {- newOffset += len;- } else {- oldOffset += len;- newOffset += len;- }- }- }- if ($nodeTd.hasClass("left")) {- newLine = newCh = undefined;- } else if ($nodeTd.hasClass("right")) {- oldLine = oldCh = undefined;- }- return {- oldLine: oldLine,- oldCh: oldCh,- newLine: newLine,- newCh: newCh- };- }-- var startCursor = getCursor($start, startOffset);- var endCursor = getCursor($end, endOffset);-- if (startCursor.newLine && endCursor.newLine) {- callback("openSelectionPopover", Math.round(position.left), Math.round(position.top), false,- startCursor.newLine-1, startCursor.newCh, endCursor.newLine-1, endCursor.newCh);- } else if (startCursor.oldLine && endCursor.oldLine) {- callback("openSelectionPopover", Math.round(position.left), Math.round(position.top), true,- startCursor.oldLine-1, startCursor.oldCh, endCursor.oldLine-1, endCursor.oldCh);- } else {- return showInvalidSelection();- }- });-- if (openComment) {- $container.data("openComment", openComment);- }- for (var line in oldComments) {- if (oldComments.hasOwnProperty(line)) {- gitplex.textdiff.addCommentIndicator($container, true, line, oldComments[line][1]);- }- }- for (var line in newComments) {- if (newComments.hasOwnProperty(line)) {- gitplex.textdiff.addCommentIndicator($container, false, line, newComments[line][1]);- }- }-- gitplex.textdiff.highlightCommentTrigger($container);-- if (mark) {- $container.data("mark", mark);- gitplex.textdiff.mark($container, mark);- if (scroll && !pmease.commons.history.isVisited())- gitplex.textdiff.scroll($container, mark);- }- }-- },- initBlameTooltip: function(containerId, $hashLink) {- var $container = $("#" + containerId);- var alignment = {targetX: 100, targetY: 100, x: 0, y: 0};- $hashLink.hover(function() {- var $commitLink = $(this);- var $content = $commitLink.closest("tr").children("td.content");- var oldLine = $content.data("old");- if (oldLine == undefined)- oldLine = -1;- var newLine = $content.data("new");- if (newLine == undefined)- newLine = -1;-- var tooltipId = "blame-message-" + containerId + "_" + oldLine + "_" + newLine;- $container.data("callback")("showBlameMessage", tooltipId, $(this).data("hash"));- var $tooltip = $("<div class='blame-message'><div class='loading'>Loading...</div></div>");- $tooltip.attr("id", tooltipId);- $tooltip.data("trigger", this);- $tooltip.data("alignment", alignment);- $container.append($tooltip);- return $tooltip;- }, alignment);- },- showBlameMessage: function(tooltipId, message) {- var $blameTooltip = $("#" + tooltipId);- $blameTooltip.empty().text(message);- $blameTooltip.align({placement: $blameTooltip.data("alignment"), target: {element: $blameTooltip.data("trigger")}});- },- openSelectionPopover: function(containerId, position, mark, markUrl, loggedIn) {- var $container = $("#" + containerId);-- var $content = $("<div><a class='permanent'><i class='fa fa-link'></i> Permanent link of this selection</a>");- $content.children("a.permanent").attr("href", markUrl);- if (loggedIn) {- $content.append("<a class='comment'><i class='fa fa-comment'></i> Add comment on this selection</a>");- $content.children("a.comment").click(function() {- if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;- }- $container.data("callback")("addComment", mark.leftSide,- mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);- });- } else {- $content.append("<span class='comment'><i class='fa fa-warning'></i> Log in to comment on selection</span>");- }-- $container.selectionPopover("open", {- position: position,- content: $content- });- },- expand: function(containerId, blockIndex, expandedHtml) {- var $container = $("#" + containerId);- var $expanderTr = $container.find(".expander" + blockIndex);- var $prevTr = $expanderTr.prev();- var $nextTr = $expanderTr.next();- $expanderTr.replaceWith(expandedHtml);- var $expandedTrs;- if ($prevTr.length != 0 && $nextTr.length != 0) {- $expandedTrs = $prevTr.nextAll().filter($nextTr.prevAll());- } else if ($prevTr.length != 0) {- $expandedTrs = $prevTr.nextAll();- } else {- $expandedTrs = $nextTr.prevAll();- }- var $symbols = $expandedTrs.find(gitplex.textdiff.symbolClasses);- $symbols.mouseover($container.data("symbolHover"));- $expandedTrs.find("td.content").mouseover($container.data("onMouseOverContent"));- var $firstExpandedTr = $expandedTrs.first();- var commitHash = $firstExpandedTr.find(">td.blame>a.hash").data("hash");- var prevCommitHash;- $firstExpandedTr.prevAll().each(function() {- if (!prevCommitHash) {- var $tr = $(this);- var $prevCommitLink = $tr.find(">td.blame>a.hash");- if ($prevCommitLink.length != 0) {- prevCommitHash = $prevCommitLink.data("hash");- }- }- });- if (commitHash == prevCommitHash) {- $firstExpandedTr.children("td.blame").html("<div class='same-as-above'>...</div>");- }-- if ($nextTr.length != 0) {- commitHash = $nextTr.find(">td.blame>a.hash").data("hash");- prevCommitHash = undefined;- $nextTr.prevAll().each(function() {- if (!prevCommitHash) {- var $prevCommitLink = $(this).find(">td.blame>a.hash");- if ($prevCommitLink.length != 0) {- prevCommitHash = $prevCommitLink.data("hash");- }- }- });- if (commitHash == prevCommitHash) {- $nextTr.children("td.blame").html("<div class='same-as-above'>...</div>");- }- }-- gitplex.textdiff.initBlameTooltip(containerId, $expandedTrs.find(">td.blame>a.hash"));-- $(window).resize();- },- getMarkInfo: function($container, mark) {- var oldOrNew = mark.leftSide?"old":"new";- var startCursor = [mark.beginLine+1, mark.beginChar];- var endCursor = [mark.endLine+1, mark.endChar];- var $startTd = $container.find("td.content[data-" + oldOrNew + "='" + (startCursor[0]-1) + "']");- var $endTd = $container.find("td.content[data-" + oldOrNew + "='" + (endCursor[0]-1) + "']");- if ($startTd.length == 0) {- console.error("Unable to find start td!");- $startTd = undefined;- } else if ($startTd.length == 2) {- if (oldOrNew == "old") {- $startTd = $startTd.first();- } else {- $startTd = $startTd.last();- }- }- if ($endTd.length == 0) {- console.error("Unable to find end td!");- $endTd = undefined;- } else if ($endTd.length == 2) {- if (oldOrNew == "old") {- $endTd = $endTd.first();- } else {- $endTd = $endTd.last();- }- }- return {- startTd: $startTd,- startCursor: startCursor,- endTd: $endTd,- endCursor: endCursor,- oldOrNew: oldOrNew- };- },- scroll: function($container, mark) {- // use a timer to scroll after possible view port resize- setTimeout(function() {- var markInfo = gitplex.textdiff.getMarkInfo($container, mark);- var $startTd = markInfo.startTd;- var $endTd = markInfo.endTd;- if ($startTd && $endTd) {- var top = $startTd.offset().top;- var bottom = $endTd.offset().top + $endTd.outerHeight();- var markHeight = bottom - top;- var windowHeight = $(window).height();- if (windowHeight <= markHeight) {- $(window).scrollTop(top-50);- } else {- $(window).scrollTop((top+bottom-windowHeight)/2);- }- }- }, 0);- },- mark: function($container, mark) {- gitplex.textdiff.clearMark($container);-- var markInfo = gitplex.textdiff.getMarkInfo($container, mark);- var $startTd = markInfo.startTd;- var $endTd = markInfo.endTd;- if ($startTd && $endTd) {- var startCursor = markInfo.startCursor;- var endCursor = markInfo.endCursor;- var oldOrNew = markInfo.oldOrNew;- var $td = $startTd;- while (true) {- var ch = 0;- $td.addClass("content-mark");- $td.data("beforemark", $td.html());- $td.contents().each(function() {- var $this = $(this);- var text = $this.text();- function markText(from, to) {- var text = $this.text();- var left = text.substring(0, from);- var middle = text.substring(from, to);- var right = text.substring(to);-- if (left.length == 0 && right.length == 0 && $this.is("span")) {- $this.addClass("content-mark");- } else {- var classes;- if ($this.is("span"))- classes = $this.attr("class");- else- classes = "";-- var $current = $this;- if (left.length != 0) {- $current.after("<span></span>");- $current = $current.next();- $current.attr("class", classes).text(left);- }-- $current.after("<span></span>");- $current = $current.next();- $current.attr("class", classes + " content-mark").text(middle);-- if (right.length != 0) {- $current.after("<span></span>");- $current = $current.next();- $current.attr("class", classes).text(right);- }- $this.remove();- }- }- if ($this.hasClass("insert") && oldOrNew == "old"- || $this.hasClass("delete") && oldOrNew == "new") {- if (!$td.is($startTd) && !$td.is($endTd)) {- markText(0, text.length);- } else if ($td.is($startTd) && $td.is($endTd)) {- if (endCursor[1]>ch && startCursor[1]<ch) {- markText(0, text.length);- }- } else if ($td.is($startTd)) {- if (startCursor[1]<ch) {- markText(0, text.length);- }- } else {- if (endCursor[1]>ch) {- markText(0, text.length);- }- }- } else {- var nextCh = ch + text.length;- if (!$td.is($startTd) && !$td.is($endTd)) {- markText(0, text.length);- } else if ($td.is($startTd) && $td.is($endTd)) {- if (endCursor[1]>ch && startCursor[1]<nextCh) {- if (ch>=startCursor[1] && nextCh<=endCursor[1]) {- markText(0, text.length);- } else if (ch<startCursor[1] && nextCh>endCursor[1]) {- markText(startCursor[1]-ch, endCursor[1]-ch);- } else if (ch<startCursor[1]) {- markText(startCursor[1]-ch, text.length);- } else {- markText(0, endCursor[1]-ch);- }- }- } else if ($td.is($startTd)) {- if (ch>=startCursor[1]) {- markText(0, text.length);- } else if (nextCh>startCursor[1]) {- markText(startCursor[1]-ch, text.length);- }- } else {- if (nextCh<=endCursor[1]) {- markText(0, text.length);- } else if (ch<endCursor[1]) {- markText(0, endCursor[1]-ch);- }- }- ch = nextCh;- }- });- if ($td.is($endTd) || $td.length == 0) {- break;- } else {- if ($startTd.hasClass("left")) {- $td = $td.parent().next().children("td.left");- } else if ($startTd.hasClass("right")) {- $td = $td.parent().next().children("td.right");- } else {- $td = $td.parent().next().children("td.content");- }- }- }- }- },- clearMark: function($container) {- $container.find("td.content.content-mark").each(function() {- var $this = $(this);- $this.html($this.data("beforemark"));- $this.removeClass("content-mark");- $this.removeData("beforemark");- $container = $this.closest(".text-diff").parent();- $this.find(gitplex.textdiff.symbolClasses).mouseover($container.data("symbolHover"));- });- },- restoreMark: function($container) {- var mark = $container.data("mark");- if (mark) {- gitplex.textdiff.mark($container, mark);- } else {- gitplex.textdiff.clearMark($container);- }- },- addCommentIndicator: function($container, leftSide, line, comments) {- var oldOrNew = leftSide?"old":"new";- $container.find("." + oldOrNew + ".comment-popover[data-line='" + line + "']").remove();- var $lineNumTd = gitplex.textdiff.getLineNumTd($container, leftSide, line);-- var callback = $container.data("callback");-- var $indicator = $(document.createElement("a"));- $indicator.addClass("comment-indicator");- $indicator.data("comments", comments);- if (comments.length != 1) {- /*- * when there are multiple comments starts with the same line, we should- * display a comment indicator which will display a comment popover with- * list of comment triggers upon click, user can then click one of the- * trigger link to display the actual comment content- */- var oldOrNew = leftSide?"old":"new";- $indicator.append("<i class='fa fa-comments'></i>");- var content = "";- for (var i in comments) {- var comment = comments[i];- var index = parseInt(i) + 1;- content += "<a class='comment-trigger' title='Click to show comment of marked text'>#" + comment.id + "</a>";- }- $indicator.popover({- html: true,- container: $lineNumTd,- placement: "right auto",- template: "<div class='" + oldOrNew + " popover comment-popover' data-line='" + line + "'><div class='arrow'></div><div class='popover-content'></div></div>",- content: content- });- $indicator.on('shown.bs.popover', function () {- $("." + oldOrNew + ".comment-popover[data-line='" + line + "'] a").each(function() {- $(this).mouseover(function() {- var comment = comments[$(this).index()];- gitplex.textdiff.mark($container, comment.mark);- });- $(this).mouseout(function() {- gitplex.textdiff.restoreMark($container);- });- $(this).click(function() {- if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;- }- var comment = comments[$(this).index()];- callback("openComment", comment.id);- });- });- gitplex.textdiff.highlightCommentTrigger($container);- });- } else {- var comment = comments[0];- $indicator.addClass("comment-trigger").attr("title", "Click to show comment of marked text");- $indicator.append("<i class='fa fa-commenting'></i>");- $indicator.mouseover(function() {- gitplex.textdiff.mark($container, comment.mark);- });- $indicator.mouseout(function() {- gitplex.textdiff.restoreMark($container);- });- $indicator.click(function() {- if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;- }- callback("openComment", comment.id);- });- }- $lineNumTd.children(".comment-indicator").remove();- $lineNumTd.prepend($indicator);- },- getLineNumTd: function($container, leftSide, line) {- if (leftSide) {- var $contentTd = $container.find("td.left.content[data-old='" + line + "']");- if ($contentTd.length == 0)- $contentTd = $container.find("td.content[data-old='" + line + "']");- return $contentTd.prevAll("td.number").last();- } else {- var $contentTd = $container.find("td.right.content[data-new='" + line + "']");- if ($contentTd.length == 0)- $contentTd = $container.find("td.content[data-new='" + line + "']");- return $contentTd.prevAll("td.number").first();- }- },- highlightCommentTrigger: function($container) {- $container.find(".comment-trigger").removeClass("active");- var openComment = $container.data("openComment");- if (openComment) {- var line = parseInt(openComment.mark.beginLine);- var $indicator = gitplex.textdiff.getLineNumTd($container, openComment.mark.leftSide, line).children(".comment-indicator");- if ($indicator.length != 0) {- var comments = $indicator.data("comments");- if (comments.length == 1) {- $indicator.addClass("active");- } else {- var oldOrNew = openComment.mark.leftSide?"old":"new";- $container.find("." + oldOrNew + ".comment-popover[data-line='" + line + "'] a").each(function() {- var comment = comments[$(this).index()];- if (comment.id == openComment.id) {- $(this).addClass("active");- }- });- }- }- }- },- onCommentAdded: function($container, comment) {- $container.data("openComment", comment);- $container.data("mark", comment.mark);-- var line = parseInt(comment.mark.beginLine);- var leftSide = comment.mark.leftSide;-- var $indicator = gitplex.textdiff.getLineNumTd($container, leftSide, line).children(".comment-indicator");- var comments;- if ($indicator.length != 0) {- comments = $indicator.data("comments");- } else {- comments = [];- }- comments.push(comment);- gitplex.textdiff.addCommentIndicator($container, leftSide, line, comments);- gitplex.textdiff.highlightCommentTrigger($container);- },- onCommentDeleted: function($container, comment) {- $container.removeData("openComment");-- var line = parseInt(comment.mark.beginLine);- var leftSide = comment.mark.leftSide;- var $indicator = gitplex.textdiff.getLineNumTd($container, leftSide, line).children(".comment-indicator");- var comments = $indicator.data("comments");- if (comments.length == 1) {- $indicator.remove();- } else {- for (var i in comments) {- var each = comments[i];- if (each.id == comment.id) {- comments.splice(i, 1);- break;- }- }- gitplex.textdiff.addCommentIndicator($container, leftSide, line, comments);- }- gitplex.textdiff.highlightCommentTrigger($container);- },- onOpenComment: function($container, comment) {- $container.data("openComment", comment);- $container.data("mark", comment.mark);- gitplex.textdiff.highlightCommentTrigger($container);- gitplex.textdiff.mark($container, comment.mark);- gitplex.textdiff.scroll($container, comment.mark);- },- onCloseComment: function($container) {- $container.removeData("openComment");- gitplex.textdiff.highlightCommentTrigger($container);- },- onAddComment: function($container, mark) {- $container.removeData("openComment");- $container.data("mark", mark);-- $container.selectionPopover("close");- window.getSelection().removeAllRanges();-- // continue to operate DOM in a timer to give browser a chance to- // clear selections- setTimeout(function() {- gitplex.textdiff.highlightCommentTrigger($container);- gitplex.textdiff.mark($container, mark);- gitplex.textdiff.scroll($container, mark);- }, 100);- }-};+gitplex.textdiff = {+ symbolClasses: ".cm-property, .cm-variable, .cm-variable-2, .cm-variable-3, .cm-def, .cm-meta",+ init: function(containerId, symbolTooltipId, oldRev, newRev, scroll, callback,+ markSupport, mark, openComment, oldComments, newComments, dirtyContainerId) {+ var $container = $("#" + containerId);+ $container.data("dirtyContainerId", dirtyContainerId);+ $container.data("callback", callback);+ $container.data("symbolHover", function() {+ var revision;+ var $symbol = $(this);+ if ($symbol.hasClass("delete")) {+ revision = oldRev;+ } else {+ var $td = $symbol.closest("td");++ // if is deleted line or if it is on left side of split view+ if ($td.hasClass("old") && !$td.hasClass("new") || $td.next().is("td"))+ revision = oldRev;+ else+ revision = newRev;+ }+ var symbolTooltip = document.getElementById(symbolTooltipId);+ if (symbolTooltip.onMouseOverSymbol)+ symbolTooltip.onMouseOverSymbol(revision, this);+ });+ $container.data("onMouseOverContent", function() {+ if (!gitplex.mouseState.pressed) {+ if ($(this).hasClass("left")) {+ $container.find("td.content.right").addClass("noselect");+ $container.find("td.content.left").removeClass("noselect");+ } else if ($(this).hasClass("right")) {+ $container.find("td.content.left").addClass("noselect");+ $container.find("td.content.right").removeClass("noselect");+ }+ }+ });+ var $symbols = $container.find(gitplex.textdiff.symbolClasses);+ $symbols.mouseover($container.data("symbolHover"));+ $container.find("td.content").mouseover($container.data("onMouseOverContent"));++ gitplex.textdiff.initBlameTooltip(containerId, $container.find("td.blame>a.hash"));++ if (markSupport) {+ $container.selectionPopover("init", function() {+ var selection = window.getSelection();+ if (!selection.rangeCount) {+ return "close";+ }+ var firstRange = selection.getRangeAt(0).cloneRange();+ var lastRange = selection.getRangeAt(selection.rangeCount-1).cloneRange();+ var $start = $(firstRange.startContainer);+ var $end = $(lastRange.endContainer);++ /*+ * offset represents offset within $start or $end node, for instance for below selection+ * <span>hello</span><span>world</span>+ * ^ ^+ * $start will be <span>hello</span> and startOffset will be index of character 'l' which is 2,+ * $end will be <span>world</span> and endOffset will be index of character 'd' which will be 4+ */+ var startOffset = firstRange.startOffset;+ var endOffset = lastRange.endOffset;++ var $startDiff;+ if (!$start.hasClass("text-diff"))+ $startDiff = $start.closest(".text-diff");+ else+ $startDiff = $start;++ var $endDiff;+ if (!$end.hasClass("text-diff"))+ $endDiff = $end.closest(".text-diff");+ else+ $endDiff = $end;++ // selection must be within same file+ if ($startDiff.length == 0 || $endDiff.length == 0 || !$startDiff.is($endDiff)) {+ return "close";+ }++ var $startTd = $start.is("td.content")? $start: $start.closest(".text-diff td.content");+ var $endTd = $end.is("td.content")? $end: $end.closest(".text-diff td.content");++ // at least one side of selection must be within a table cell+ if ($startTd.length == 0 && $endTd.length == 0) {+ return "close";+ }++ // make sure we are processing td.content on the same side on split view+ function getTd($tr) {+ var $td = $startTd.length != 0? $startTd: $endTd;+ if ($td.hasClass("left"))+ return $tr.find("td.content.left");+ else if ($td.hasClass("right"))+ return $tr.find("td.content.right");+ else+ return $tr.find("td.content");+ }++ /*+ * sometimes the selection returns $start and $end as td instead of+ * children under td, for instance:+ * <td><span>hello</span><span>world</span></td>+ * ^+ * in this case, both $start and $end is the whole td, and startOffset+ * is index of first span element which is 0, and endOffset is index of+ * last span element plus 1 which is 2.+ *+ * this function returns the equivalent child node and offset under td.+ * with above example, the equivalent child node will be <span>hello</span>+ * and offset will be 0 for selection start, while equivalent end child node+ * is <span>world</span> with offset being 5+ *+ */+ function getNodeAndOffsetUnderTd($td, contentIndex) {+ var $contents = $td.contents();+ for (var i=0; i<$contents.length; i++) {+ if (i == contentIndex) {+ return {+ node: $($contents[i]),+ offset: 0+ }+ }+ }+ var $lastContent = $contents.last();+ return {+ node: $lastContent,+ offset: $lastContent.text().length+ }+ }++ // normalize $start to be within td.content+ if ($start.parent().parent().is("td.content")) // $start might be the text node under span+ $start = $start.parent();+ if (!$start.parent().is("td.content")) {+ var $td;+ if ($start.is("td.content")) { // this happens if we triple click to select a line in firefox+ $td = $start;+ } else if ($start.is("tr.code")) { // this may happen if we drag mouse to select multiple lines in firefox+ $td = getTd($start);+ startOffset = startOffset<=$td.index()? 0: $td.contents().length;+ } else if ($start.is("tr.expander") || $start.closest("tr.expander").length != 0) { // this may happen if we drag mouse over to expander line+ var $tr = $start.is("tr.expander")? $start.next(): $start.closest("tr.expander").next();+ if ($tr.length == 0) {+ return "close";+ }+ $td = getTd($tr);+ startOffset = 0;+ } else {+ var $tr = $startDiff.find("tr.code").first();+ if ($tr.length == 0) {+ return "close";+ }+ $td = getTd($tr);+ startOffset = 0;+ }+ var nodeAndOffset = getNodeAndOffsetUnderTd($td, startOffset);+ $start = nodeAndOffset.node;+ startOffset = nodeAndOffset.offset;+ }++ // drag mouse over a line below expander, chrome may set $start as the line+ // above expander, below code normalizes this case+ $startTd = $start.parent();+ var $lastContent = $startTd.contents().last();+ var noneSelected = $start.is($lastContent) && startOffset >= $lastContent.text().length;+ if (noneSelected && $startTd.parent().next().is("tr.expander")) {+ var $tr = $startTd.parent().next().next();+ if ($tr.length == 0) {+ return "close";+ }+ var $td = getTd($tr);+ $start = $td.contents().first();+ startOffset = 0;+ }++ // normalize $end to be within td.content+ if ($end.parent().parent().is("td.content"))+ $end = $end.parent();+ if (!$end.parent().is("td.content")) {+ var $td;+ if ($end.is("td.content")) {+ $td = $end;+ } else if ($end.is("tr.code")) {+ $td = getTd($end);+ endOffset = endOffset>$td.index()? $td.contents().length: 0;+ } else if ($end.is("tr.expander") || $end.closest("tr.expander").length != 0) {+ var $tr = $end.is("tr.expander")? $end.prev(): $end.closest("tr.expander").prev();+ if ($tr.length == 0) {+ return "close";+ }+ $td = getTd($tr);+ endOffset = $td.contents().length;+ } else {+ var $tr = $endDiff.find("tr.code").last();+ if ($tr.length == 0) {+ return "close";+ }+ $td = getTd($tr);+ endOffset = $td.contents().length;+ }+ var nodeAndOffset = getNodeAndOffsetUnderTd($td, endOffset);+ $end = nodeAndOffset.node;+ endOffset = nodeAndOffset.offset;+ }++ // drag mouse over a line above expander, chrome may set $end as the line+ // below expander, below code normalizes this case+ $endTd = $end.parent();+ var $firstContent = $endTd.contents().first();+ var noneSelected = $end.is($firstContent) && endOffset == 0;+ if (noneSelected && $endTd.parent().prev().is("tr.expander")) {+ var $tr = $endTd.parent().prev().prev();+ if ($tr.length == 0) {+ return "close";+ }+ var $td = getTd($tr);+ $end = $td.contents().last();+ endOffset = $end.text().length;+ }++ $startTd = $start.parent();+ $endTd = $end.parent();++ // selection must not span the split view+ if ($startTd.hasClass("left") && $endTd.hasClass("right")+ || $startTd.hasClass("right") && $endTd.hasClass("left")) {+ return "close";+ }++ var $startTr = $startTd.parent();+ var $endTr = $endTd.parent();+ if ($startTr.index() > $endTr.index()) {+ return "close";+ }++ function nextContent($content) {+ var $td = $content.parent();+ var array = $td.contents().toArray();+ var index = array.indexOf($content[0]);+ if (index == array.length-1) {+ var $nextTr = $td.parent().next();+ if ($nextTr.hasClass("expander")) {+ $nextTr = $nextTr.next();+ }+ if ($nextTr.length == 0)+ return undefined;+ return getTd($nextTr).contents().first();+ } else {+ return $(array[index+1]);+ }+ }++ function prevContent($content) {+ var $td = $content.parent();+ var array = $td.contents().toArray();+ var index = array.indexOf($content[0]);+ if (index == 0) {+ var $prevTr = $td.parent().prev();+ if ($prevTr.hasClass("expander")) {+ $prevTr = $prevTr.next();+ }+ if ($prevTr.length == 0)+ return undefined;+ return getTd($prevTr).contents().last();+ } else {+ return $(array[index-1]);+ }+ }++ function hasOldOrNewData($content) {+ var $td = $content.parent();+ return $td.attr("data-old") || $td.attr("data-new");+ }++ /*+ * continue to normalize $start and $end. This time we convert below selection:+ * <span>begin</span><span>middle</span><span>end</span>+ * ^ ^+ * into this selection:+ * <span>begin</span><span>middle</span><span>end</span>+ * ^ ^+ * this normalization makes it accurate to detect invalid selections where start+ * and end of selection points to different revisions+ */+ var $content = $start;+ while (!$content.is($end) && (startOffset >= $content.text().length || !hasOldOrNewData($content))) {+ $content = nextContent($content);+ if (!$content) {+ return "close";+ } else {+ $start = $content;+ startOffset = 0;+ }+ }++ $content = $end;+ while (!$content.is($start) && (endOffset == 0 || !hasOldOrNewData($content))) {+ $content = prevContent($content);+ if (!$content) {+ return "close";+ } else {+ $end = $content;+ endOffset = $content.text().length;+ }+ }++ // check if there is anything selected+ if ($start.is($end) && startOffset >= endOffset+ || !hasOldOrNewData($start) || !hasOldOrNewData($end)) {+ return "close";+ }++ firstRange.collapse(true);+ var startRect = firstRange.getClientRects()[0];+ lastRange.collapse(false);+ var endRect = lastRange.getClientRects()[0];+ if (!startRect || !endRect) {+ startRect = selection.getRangeAt(0).getClientRects()[0];+ endRect = startRect;+ }+ var position = {+ left: (startRect.left + endRect.right)/2,+ top: startRect.top+ };+ position.left += $(window).scrollLeft();+ position.top += $(window).scrollTop();++ function showInvalidSelection() {+ var $content = $("<div></div>");+ $content.append("<a class='invalid'><i class='fa fa-warning'></i> Invalid selection, click for details</a>");+ $content.children("a").attr("href", "http://wiki.pmease.com/display/gp/Diff+Selection");+ return {+ position: position,+ content: $content+ }+ }++ // all lines between selection has been expanded+ if ($startTr.nextAll("tr.expander").filter($endTr.prevAll("tr.expander")).length != 0+ || $startTr.prevAll("tr.expander").filter($endTr.nextAll("tr.expander")).length != 0) {+ return showInvalidSelection();+ }++ /*+ * cursor.line represents line number of selection and cursor.ch represents+ * character index inside text of the whole line, without considering element+ * tags.+ */+ function getCursor($node, offset) {+ $nodeTd = $node.parent();+ var oldLine, newLine;+ if (!$nodeTd.hasClass("old") && !$nodeTd.hasClass("new")+ || $nodeTd.hasClass("old") && $nodeTd.hasClass("new")) {+ oldLine = $nodeTd.data("old") + 1;+ newLine = $nodeTd.data("new") + 1;+ } else if ($nodeTd.hasClass("old")) {+ oldLine = $nodeTd.data("old") + 1;+ } else {+ newLine = $nodeTd.data("new") + 1;+ }+ var $contents = $nodeTd.contents();+ var oldOffset = 0, newOffset = 0;+ for (var i=0; i<$contents.length; i++) {+ var $content = $($contents[i]);+ if ($content.is($node)) {+ if ($content.hasClass("delete")) {+ oldCh = oldOffset + offset;+ newCh = undefined;+ newLine = undefined;+ } else if ($content.hasClass("insert")) {+ oldCh = undefined;+ oldLine = undefined;+ newCh = newOffset + offset;+ } else {+ oldCh = oldOffset + offset;+ newCh = newOffset + offset;+ }+ break;+ } else {+ var len = $content.text().length;+ if ($content.hasClass("delete")) {+ oldOffset += len;+ } else if ($content.hasClass("insert")) {+ newOffset += len;+ } else {+ oldOffset += len;+ newOffset += len;+ }+ }+ }+ if ($nodeTd.hasClass("left")) {+ newLine = newCh = undefined;+ } else if ($nodeTd.hasClass("right")) {+ oldLine = oldCh = undefined;+ }+ return {+ oldLine: oldLine,+ oldCh: oldCh,+ newLine: newLine,+ newCh: newCh+ };+ }++ var startCursor = getCursor($start, startOffset);+ var endCursor = getCursor($end, endOffset);++ if (startCursor.newLine && endCursor.newLine) {+ callback("openSelectionPopover", Math.round(position.left), Math.round(position.top), false,+ startCursor.newLine-1, startCursor.newCh, endCursor.newLine-1, endCursor.newCh);+ } else if (startCursor.oldLine && endCursor.oldLine) {+ callback("openSelectionPopover", Math.round(position.left), Math.round(position.top), true,+ startCursor.oldLine-1, startCursor.oldCh, endCursor.oldLine-1, endCursor.oldCh);+ } else {+ return showInvalidSelection();+ }+ });++ if (openComment) {+ $container.data("openComment", openComment);+ }+ for (var line in oldComments) {+ if (oldComments.hasOwnProperty(line)) {+ gitplex.textdiff.addCommentIndicator($container, true, line, oldComments[line][1]);+ }+ }+ for (var line in newComments) {+ if (newComments.hasOwnProperty(line)) {+ gitplex.textdiff.addCommentIndicator($container, false, line, newComments[line][1]);+ }+ }++ gitplex.textdiff.highlightCommentTrigger($container);++ if (mark) {+ $container.data("mark", mark);+ gitplex.textdiff.mark($container, mark);+ if (scroll && !pmease.commons.history.isVisited())+ gitplex.textdiff.scroll($container, mark);+ }+ }++ },+ initBlameTooltip: function(containerId, $hashLink) {+ var $container = $("#" + containerId);+ var alignment = {targetX: 100, targetY: 100, x: 0, y: 0};+ $hashLink.hover(function() {+ var $commitLink = $(this);+ var $content = $commitLink.closest("tr").children("td.content");+ var oldLine = $content.data("old");+ if (oldLine == undefined)+ oldLine = -1;+ var newLine = $content.data("new");+ if (newLine == undefined)+ newLine = -1;++ var tooltipId = "blame-message-" + containerId + "_" + oldLine + "_" + newLine;+ $container.data("callback")("showBlameMessage", tooltipId, $(this).data("hash"));+ var $tooltip = $("<div class='blame-message'><div class='loading'>Loading...</div></div>");+ $tooltip.attr("id", tooltipId);+ $tooltip.data("trigger", this);+ $tooltip.data("alignment", alignment);+ $container.append($tooltip);+ return $tooltip;+ }, alignment);+ },+ showBlameMessage: function(tooltipId, message) {+ var $blameTooltip = $("#" + tooltipId);+ $blameTooltip.empty().text(message);+ $blameTooltip.align({placement: $blameTooltip.data("alignment"), target: {element: $blameTooltip.data("trigger")}});+ },+ openSelectionPopover: function(containerId, position, mark, markUrl, loggedIn) {+ var $container = $("#" + containerId);++ var $content = $("<div><a class='permanent'><i class='fa fa-link'></i> Permanent link of this selection</a>");+ $content.children("a.permanent").attr("href", markUrl);+ if (loggedIn) {+ $content.append("<a class='comment'><i class='fa fa-comment'></i> Add comment on this selection</a>");+ $content.children("a.comment").click(function() {+ if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ $container.data("callback")("addComment", mark.leftSide,+ mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);+ });+ } else {+ $content.append("<span class='comment'><i class='fa fa-warning'></i> Log in to comment on selection</span>");+ }++ $container.selectionPopover("open", {+ position: position,+ content: $content+ });+ },+ expand: function(containerId, blockIndex, expandedHtml) {+ var $container = $("#" + containerId);+ var $expanderTr = $container.find(".expander" + blockIndex);+ var $prevTr = $expanderTr.prev();+ var $nextTr = $expanderTr.next();+ $expanderTr.replaceWith(expandedHtml);+ var $expandedTrs;+ if ($prevTr.length != 0 && $nextTr.length != 0) {+ $expandedTrs = $prevTr.nextAll().filter($nextTr.prevAll());+ } else if ($prevTr.length != 0) {+ $expandedTrs = $prevTr.nextAll();+ } else {+ $expandedTrs = $nextTr.prevAll();+ }+ var $symbols = $expandedTrs.find(gitplex.textdiff.symbolClasses);+ $symbols.mouseover($container.data("symbolHover"));+ $expandedTrs.find("td.content").mouseover($container.data("onMouseOverContent"));+ var $firstExpandedTr = $expandedTrs.first();++ function processBlames(index) {+ var commitHash = $firstExpandedTr.children("td.blame").eq(index).children("a.hash").data("hash");+ var prevCommitHash;+ $firstExpandedTr.prevAll().each(function() {+ if (!prevCommitHash) {+ var $tr = $(this);+ var $prevCommitLink = $tr.children("td.blame").eq(index).children("a.hash");+ if ($prevCommitLink.length != 0) {+ prevCommitHash = $prevCommitLink.data("hash");+ }+ }+ });+ if (commitHash == prevCommitHash) {+ $firstExpandedTr.children("td.blame").eq(index).html("<div class='same-as-above'>...</div>");+ }++ if ($nextTr.length != 0) {+ commitHash = $nextTr.children("td.blame").eq(index).children("a.hash").data("hash");+ prevCommitHash = undefined;+ $nextTr.prevAll().each(function() {+ if (!prevCommitHash) {+ var $prevCommitLink = $(this).children("td.blame").eq(index).children("a.hash");+ if ($prevCommitLink.length != 0) {+ prevCommitHash = $prevCommitLink.data("hash");+ }+ }+ });+ if (commitHash == prevCommitHash) {+ $nextTr.children("td.blame").eq(index).html("<div class='same-as-above'>...</div>");+ }+ }+ }+ if ($firstExpandedTr.children("td.blame").length == 1) {+ processBlames(0);+ } else if ($firstExpandedTr.children("td.blame").length == 2) {+ processBlames(0);+ processBlames(1);+ }++ gitplex.textdiff.initBlameTooltip(containerId, $expandedTrs.find(">td.blame>a.hash"));++ $(window).resize();+ },+ getMarkInfo: function($container, mark) {+ var oldOrNew = mark.leftSide?"old":"new";+ var startCursor = [mark.beginLine+1, mark.beginChar];+ var endCursor = [mark.endLine+1, mark.endChar];+ var $startTd = $container.find("td.content[data-" + oldOrNew + "='" + (startCursor[0]-1) + "']");+ var $endTd = $container.find("td.content[data-" + oldOrNew + "='" + (endCursor[0]-1) + "']");+ if ($startTd.length == 0) {+ console.error("Unable to find start td!");+ $startTd = undefined;+ } else if ($startTd.length == 2) {+ if (oldOrNew == "old") {+ $startTd = $startTd.first();+ } else {+ $startTd = $startTd.last();+ }+ }+ if ($endTd.length == 0) {+ console.error("Unable to find end td!");+ $endTd = undefined;+ } else if ($endTd.length == 2) {+ if (oldOrNew == "old") {+ $endTd = $endTd.first();+ } else {+ $endTd = $endTd.last();+ }+ }+ return {+ startTd: $startTd,+ startCursor: startCursor,+ endTd: $endTd,+ endCursor: endCursor,+ oldOrNew: oldOrNew+ };+ },+ scroll: function($container, mark) {+ // use a timer to scroll after possible view port resize+ setTimeout(function() {+ var markInfo = gitplex.textdiff.getMarkInfo($container, mark);+ var $startTd = markInfo.startTd;+ var $endTd = markInfo.endTd;+ if ($startTd && $endTd) {+ var top = $startTd.offset().top;+ var bottom = $endTd.offset().top + $endTd.outerHeight();+ var markHeight = bottom - top;+ var windowHeight = $(window).height();+ if (windowHeight <= markHeight) {+ $(window).scrollTop(top-50);+ } else {+ $(window).scrollTop((top+bottom-windowHeight)/2);+ }+ }+ }, 0);+ },+ mark: function($container, mark) {+ gitplex.textdiff.clearMark($container);++ var markInfo = gitplex.textdiff.getMarkInfo($container, mark);+ var $startTd = markInfo.startTd;+ var $endTd = markInfo.endTd;+ if ($startTd && $endTd) {+ var startCursor = markInfo.startCursor;+ var endCursor = markInfo.endCursor;+ var oldOrNew = markInfo.oldOrNew;+ var $td = $startTd;+ while (true) {+ var ch = 0;+ $td.addClass("content-mark");+ $td.data("beforemark", $td.html());+ $td.contents().each(function() {+ var $this = $(this);+ var text = $this.text();+ function markText(from, to) {+ var text = $this.text();+ var left = text.substring(0, from);+ var middle = text.substring(from, to);+ var right = text.substring(to);++ if (left.length == 0 && right.length == 0 && $this.is("span")) {+ $this.addClass("content-mark");+ } else {+ var classes;+ if ($this.is("span"))+ classes = $this.attr("class");+ else+ classes = "";++ var $current = $this;+ if (left.length != 0) {+ $current.after("<span></span>");+ $current = $current.next();+ $current.attr("class", classes).text(left);+ }++ $current.after("<span></span>");+ $current = $current.next();+ $current.attr("class", classes + " content-mark").text(middle);++ if (right.length != 0) {+ $current.after("<span></span>");+ $current = $current.next();+ $current.attr("class", classes).text(right);+ }+ $this.remove();+ }+ }+ if ($this.hasClass("insert") && oldOrNew == "old"+ || $this.hasClass("delete") && oldOrNew == "new") {+ if (!$td.is($startTd) && !$td.is($endTd)) {+ markText(0, text.length);+ } else if ($td.is($startTd) && $td.is($endTd)) {+ if (endCursor[1]>ch && startCursor[1]<ch) {+ markText(0, text.length);+ }+ } else if ($td.is($startTd)) {+ if (startCursor[1]<ch) {+ markText(0, text.length);+ }+ } else {+ if (endCursor[1]>ch) {+ markText(0, text.length);+ }+ }+ } else {+ var nextCh = ch + text.length;+ if (!$td.is($startTd) && !$td.is($endTd)) {+ markText(0, text.length);+ } else if ($td.is($startTd) && $td.is($endTd)) {+ if (endCursor[1]>ch && startCursor[1]<nextCh) {+ if (ch>=startCursor[1] && nextCh<=endCursor[1]) {+ markText(0, text.length);+ } else if (ch<startCursor[1] && nextCh>endCursor[1]) {+ markText(startCursor[1]-ch, endCursor[1]-ch);+ } else if (ch<startCursor[1]) {+ markText(startCursor[1]-ch, text.length);+ } else {+ markText(0, endCursor[1]-ch);+ }+ }+ } else if ($td.is($startTd)) {+ if (ch>=startCursor[1]) {+ markText(0, text.length);+ } else if (nextCh>startCursor[1]) {+ markText(startCursor[1]-ch, text.length);+ }+ } else {+ if (nextCh<=endCursor[1]) {+ markText(0, text.length);+ } else if (ch<endCursor[1]) {+ markText(0, endCursor[1]-ch);+ }+ }+ ch = nextCh;+ }+ });+ if ($td.is($endTd) || $td.length == 0) {+ break;+ } else {+ if ($startTd.hasClass("left")) {+ $td = $td.parent().next().children("td.left");+ } else if ($startTd.hasClass("right")) {+ $td = $td.parent().next().children("td.right");+ } else {+ $td = $td.parent().next().children("td.content");+ }+ }+ }+ }+ },+ clearMark: function($container) {+ $container.find("td.content.content-mark").each(function() {+ var $this = $(this);+ $this.html($this.data("beforemark"));+ $this.removeClass("content-mark");+ $this.removeData("beforemark");+ $container = $this.closest(".text-diff").parent();+ $this.find(gitplex.textdiff.symbolClasses).mouseover($container.data("symbolHover"));+ });+ },+ restoreMark: function($container) {+ var mark = $container.data("mark");+ if (mark) {+ gitplex.textdiff.mark($container, mark);+ } else {+ gitplex.textdiff.clearMark($container);+ }+ },+ addCommentIndicator: function($container, leftSide, line, comments) {+ var oldOrNew = leftSide?"old":"new";+ $container.find("." + oldOrNew + ".comment-popover[data-line='" + line + "']").remove();+ var $lineNumTd = gitplex.textdiff.getLineNumTd($container, leftSide, line);++ var callback = $container.data("callback");++ var $indicator = $(document.createElement("a"));+ $indicator.addClass("comment-indicator");+ $indicator.data("comments", comments);+ if (comments.length != 1) {+ /*+ * when there are multiple comments starts with the same line, we should+ * display a comment indicator which will display a comment popover with+ * list of comment triggers upon click, user can then click one of the+ * trigger link to display the actual comment content+ */+ var oldOrNew = leftSide?"old":"new";+ $indicator.append("<i class='fa fa-comments'></i>");+ var content = "";+ for (var i in comments) {+ var comment = comments[i];+ var index = parseInt(i) + 1;+ content += "<a class='comment-trigger' title='Click to show comment of marked text'>#" + comment.id + "</a>";+ }+ $indicator.popover({+ html: true,+ container: $lineNumTd,+ placement: "right auto",+ template: "<div class='" + oldOrNew + " popover comment-popover' data-line='" + line + "'><div class='arrow'></div><div class='popover-content'></div></div>",+ content: content+ });+ $indicator.on('shown.bs.popover', function () {+ $("." + oldOrNew + ".comment-popover[data-line='" + line + "'] a").each(function() {+ $(this).mouseover(function() {+ var comment = comments[$(this).index()];+ gitplex.textdiff.mark($container, comment.mark);+ });+ $(this).mouseout(function() {+ gitplex.textdiff.restoreMark($container);+ });+ $(this).click(function() {+ if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ var comment = comments[$(this).index()];+ callback("openComment", comment.id);+ });+ });+ gitplex.textdiff.highlightCommentTrigger($container);+ });+ } else {+ var comment = comments[0];+ $indicator.addClass("comment-trigger").attr("title", "Click to show comment of marked text");+ $indicator.append("<i class='fa fa-commenting'></i>");+ $indicator.mouseover(function() {+ gitplex.textdiff.mark($container, comment.mark);+ });+ $indicator.mouseout(function() {+ gitplex.textdiff.restoreMark($container);+ });+ $indicator.click(function() {+ if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ callback("openComment", comment.id);+ });+ }+ $lineNumTd.children(".comment-indicator").remove();+ $lineNumTd.prepend($indicator);+ },+ getLineNumTd: function($container, leftSide, line) {+ if (leftSide) {+ var $contentTd = $container.find("td.left.content[data-old='" + line + "']");+ if ($contentTd.length == 0)+ $contentTd = $container.find("td.content[data-old='" + line + "']");+ return $contentTd.prevAll("td.number").last();+ } else {+ var $contentTd = $container.find("td.right.content[data-new='" + line + "']");+ if ($contentTd.length == 0)+ $contentTd = $container.find("td.content[data-new='" + line + "']");+ return $contentTd.prevAll("td.number").first();+ }+ },+ highlightCommentTrigger: function($container) {+ $container.find(".comment-trigger").removeClass("active");+ var openComment = $container.data("openComment");+ if (openComment) {+ var line = parseInt(openComment.mark.beginLine);+ var $indicator = gitplex.textdiff.getLineNumTd($container, openComment.mark.leftSide, line).children(".comment-indicator");+ if ($indicator.length != 0) {+ var comments = $indicator.data("comments");+ if (comments.length == 1) {+ $indicator.addClass("active");+ } else {+ var oldOrNew = openComment.mark.leftSide?"old":"new";+ $container.find("." + oldOrNew + ".comment-popover[data-line='" + line + "'] a").each(function() {+ var comment = comments[$(this).index()];+ if (comment.id == openComment.id) {+ $(this).addClass("active");+ }+ });+ }+ }+ }+ },+ onCommentAdded: function($container, comment) {+ $container.data("openComment", comment);+ $container.data("mark", comment.mark);++ var line = parseInt(comment.mark.beginLine);+ var leftSide = comment.mark.leftSide;++ var $indicator = gitplex.textdiff.getLineNumTd($container, leftSide, line).children(".comment-indicator");+ var comments;+ if ($indicator.length != 0) {+ comments = $indicator.data("comments");+ } else {+ comments = [];+ }+ comments.push(comment);+ gitplex.textdiff.addCommentIndicator($container, leftSide, line, comments);+ gitplex.textdiff.highlightCommentTrigger($container);+ },+ onCommentDeleted: function($container, comment) {+ $container.removeData("openComment");++ var line = parseInt(comment.mark.beginLine);+ var leftSide = comment.mark.leftSide;+ var $indicator = gitplex.textdiff.getLineNumTd($container, leftSide, line).children(".comment-indicator");+ var comments = $indicator.data("comments");+ if (comments.length == 1) {+ $indicator.remove();+ } else {+ for (var i in comments) {+ var each = comments[i];+ if (each.id == comment.id) {+ comments.splice(i, 1);+ break;+ }+ }+ gitplex.textdiff.addCommentIndicator($container, leftSide, line, comments);+ }+ gitplex.textdiff.highlightCommentTrigger($container);+ },+ onOpenComment: function($container, comment) {+ $container.data("openComment", comment);+ $container.data("mark", comment.mark);+ gitplex.textdiff.highlightCommentTrigger($container);+ gitplex.textdiff.mark($container, comment.mark);+ gitplex.textdiff.scroll($container, comment.mark);+ },+ onCloseComment: function($container) {+ $container.removeData("openComment");+ gitplex.textdiff.highlightCommentTrigger($container);+ },+ onAddComment: function($container, mark) {+ $container.removeData("openComment");+ $container.data("mark", mark);++ $container.selectionPopover("close");+ window.getSelection().removeAllRanges();++ // continue to operate DOM in a timer to give browser a chance to+ // clear selections+ setTimeout(function() {+ gitplex.textdiff.highlightCommentTrigger($container);+ gitplex.textdiff.mark($container, mark);+ gitplex.textdiff.scroll($container, mark);+ }, 100);+ }+};diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.htmlindex f8fafd68ce..3472eee4ed 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/test/TestPage.html@@ -1,3 +1,14 @@<wicket:extend>- <a wicket:id="test">test</a>+ <table>+ <tr>+ <td class="blame">11</td>+ <td>22</td>+ <td class="blame">33</td>+ </tr>+ </table>+ <script type="text/javascript">+ $(function() {+ console.log($("tr>td.blame:nth-of-type(2)").text());+ });+ </script></wicket:extend>\ No newline at end of file