float button discovering the next and previous diff

This commit is contained in:
hqyn1559 2019-04-22 19:38:23 +08:00
parent 35f86fe528
commit f73095a5ce
9 changed files with 154 additions and 18 deletions

View file

@ -20,7 +20,8 @@
matchWordsThreshold: 0.25, matchWordsThreshold: 0.25,
matchingMaxComparisons: 2500, matchingMaxComparisons: 2500,
maxLineLengthHighlight: 10000, maxLineLengthHighlight: 10000,
renderNothingWhenEmpty: false renderNothingWhenEmpty: false,
showButton: true
}; };
/* /*
@ -42,6 +43,11 @@
diffJson = diffParser.generateDiffJson(diffInput, cfg); diffJson = diffParser.generateDiffJson(diffInput, cfg);
} }
var floatButton = '';
if (cfg.showButton === true) {
floatButton = htmlPrinter.generateFloatButton();
}
var fileList = ''; var fileList = '';
if (cfg.showFiles === true) { if (cfg.showFiles === true) {
fileList = htmlPrinter.generateFileListSummary(diffJson, cfg); fileList = htmlPrinter.generateFileListSummary(diffJson, cfg);
@ -54,7 +60,7 @@
diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, cfg); diffOutput = htmlPrinter.generateLineByLineJsonHtml(diffJson, cfg);
} }
return fileList + diffOutput; return floatButton + fileList + diffOutput;
}; };
/* /*

View file

@ -0,0 +1,25 @@
/*
*
* FloatButtonPrinter (float-button-printer.js)
* Author: PhoebeWho
*
*/
(function() {
var hoganUtils;
var genericTemplatesPath = 'generic';
function FloatButtonPrinter(config) {
this.config = config;
var HoganJsUtils = require('./hoganjs-utils.js').HoganJsUtils;
hoganUtils = new HoganJsUtils(config);
}
FloatButtonPrinter.prototype.generateFloatButton = function() {
return hoganUtils.render(genericTemplatesPath, 'float-button', {});
};
module.exports.FloatButtonPrinter = FloatButtonPrinter;
})();

View file

@ -9,6 +9,7 @@
var LineByLinePrinter = require('./line-by-line-printer.js').LineByLinePrinter; var LineByLinePrinter = require('./line-by-line-printer.js').LineByLinePrinter;
var SideBySidePrinter = require('./side-by-side-printer.js').SideBySidePrinter; var SideBySidePrinter = require('./side-by-side-printer.js').SideBySidePrinter;
var FileListPrinter = require('./file-list-printer.js').FileListPrinter; var FileListPrinter = require('./file-list-printer.js').FileListPrinter;
var FloatButtonPrinter = require('./float-button-printer.js').FloatButtonPrinter;
function HtmlPrinter() { function HtmlPrinter() {
} }
@ -28,5 +29,10 @@
return fileListPrinter.generateFileList(diffJson); return fileListPrinter.generateFileList(diffJson);
}; };
HtmlPrinter.prototype.generateFloatButton = function() {
var floatButtonPrinter = new FloatButtonPrinter();
return floatButtonPrinter.generateFloatButton();
};
module.exports.HtmlPrinter = new HtmlPrinter(); module.exports.HtmlPrinter = new HtmlPrinter();
})(); })();

View file

@ -10,6 +10,8 @@
var printerUtils = require('./printer-utils.js').PrinterUtils; var printerUtils = require('./printer-utils.js').PrinterUtils;
var utils = require('./utils.js').Utils; var utils = require('./utils.js').Utils;
var Rematch = require('./rematch.js').Rematch; var Rematch = require('./rematch.js').Rematch;
var diffBlockIdx = 0;
var blockFlag = true;
var hoganUtils; var hoganUtils;
@ -87,6 +89,7 @@
var lines = that.makeColumnLineNumberHtml(block); var lines = that.makeColumnLineNumberHtml(block);
var oldLines = []; var oldLines = [];
var newLines = []; var newLines = [];
blockFlag = true;
function processChangeBlock() { function processChangeBlock() {
var matches; var matches;
@ -124,10 +127,15 @@
that.config.isCombined = file.isCombined; that.config.isCombined = file.isCombined;
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config); var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
var tid = '';
if (blockFlag && oldLines.length && newLines.length) {
tid = 'diff-block-' + diffBlockIdx;
diffBlockIdx += 1;
blockFlag = false;
}
processedOldLines += processedOldLines +=
that.makeLineHtml(file.isCombined, deleteType, oldLine.oldNumber, oldLine.newNumber, that.makeLineHtml(file.isCombined, deleteType, oldLine.oldNumber, oldLine.newNumber,
diff.first.line, diff.first.prefix); diff.first.line, diff.first.prefix, tid);
processedNewLines += processedNewLines +=
that.makeLineHtml(file.isCombined, insertType, newLine.oldNumber, newLine.newNumber, that.makeLineHtml(file.isCombined, insertType, newLine.oldNumber, newLine.newNumber,
diff.second.line, diff.second.prefix); diff.second.line, diff.second.prefix);
@ -151,9 +159,16 @@
} }
if (line.type === diffParser.LINE_TYPE.CONTEXT) { if (line.type === diffParser.LINE_TYPE.CONTEXT) {
blockFlag = true;
lines += that.makeLineHtml(file.isCombined, line.type, line.oldNumber, line.newNumber, escapedLine); lines += that.makeLineHtml(file.isCombined, line.type, line.oldNumber, line.newNumber, escapedLine);
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) { } else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
lines += that.makeLineHtml(file.isCombined, line.type, line.oldNumber, line.newNumber, escapedLine); var tid = '';
if (blockFlag) {
tid = 'diff-block-' + diffBlockIdx;
diffBlockIdx += 1;
blockFlag = false;
}
lines += that.makeLineHtml(file.isCombined, line.type, line.oldNumber, line.newNumber, escapedLine, '', tid);
} else if (line.type === diffParser.LINE_TYPE.DELETES) { } else if (line.type === diffParser.LINE_TYPE.DELETES) {
oldLines.push(line); oldLines.push(line);
} else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) { } else if (line.type === diffParser.LINE_TYPE.INSERTS && Boolean(oldLines.length)) {
@ -172,23 +187,36 @@
LineByLinePrinter.prototype._processLines = function(isCombined, oldLines, newLines) { LineByLinePrinter.prototype._processLines = function(isCombined, oldLines, newLines) {
var lines = ''; var lines = '';
var LineBlockFlag = true;
var tid;
for (var i = 0; i < oldLines.length; i++) { for (var i = 0; i < oldLines.length; i++) {
var oldLine = oldLines[i]; var oldLine = oldLines[i];
var oldEscapedLine = utils.escape(oldLine.content); var oldEscapedLine = utils.escape(oldLine.content);
lines += this.makeLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine); if (LineBlockFlag && blockFlag) {
tid = 'diff-block-' + diffBlockIdx;
diffBlockIdx += 1;
blockFlag = false;
LineBlockFlag = false;
}
lines += this.makeLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldLine.newNumber, oldEscapedLine, '', tid);
} }
for (var j = 0; j < newLines.length; j++) { for (var j = 0; j < newLines.length; j++) {
var newLine = newLines[j]; var newLine = newLines[j];
var newEscapedLine = utils.escape(newLine.content); var newEscapedLine = utils.escape(newLine.content);
lines += this.makeLineHtml(isCombined, newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine); if (LineBlockFlag && blockFlag) {
tid = 'diff-block-' + diffBlockIdx;
diffBlockIdx += 1;
blockFlag = false;
LineBlockFlag = false;
}
lines += this.makeLineHtml(isCombined, newLine.type, newLine.oldNumber, newLine.newNumber, newEscapedLine, '', tid);
} }
return lines; return lines;
}; };
LineByLinePrinter.prototype.makeLineHtml = function(isCombined, type, oldNumber, newNumber, content, possiblePrefix) { LineByLinePrinter.prototype.makeLineHtml = function(isCombined, type, oldNumber, newNumber, content, possiblePrefix, tid) {
var lineNumberTemplate = hoganUtils.render(baseTemplatesPath, 'numbers', { var lineNumberTemplate = hoganUtils.render(baseTemplatesPath, 'numbers', {
oldNumber: utils.valueOrEmpty(oldNumber), oldNumber: utils.valueOrEmpty(oldNumber),
newNumber: utils.valueOrEmpty(newNumber) newNumber: utils.valueOrEmpty(newNumber)
@ -196,6 +224,11 @@
var lineWithoutPrefix = content; var lineWithoutPrefix = content;
var prefix = possiblePrefix; var prefix = possiblePrefix;
var idxStr = '';
if (tid) {
idxStr += tid;
}
if (!prefix) { if (!prefix) {
var lineWithPrefix = printerUtils.separatePrefix(isCombined, content); var lineWithPrefix = printerUtils.separatePrefix(isCombined, content);
@ -210,7 +243,8 @@
contentClass: 'd2h-code-line', contentClass: 'd2h-code-line',
prefix: prefix, prefix: prefix,
content: lineWithoutPrefix, content: lineWithoutPrefix,
lineNumber: lineNumberTemplate lineNumber: lineNumberTemplate,
eleID: idxStr
}); });
}; };

View file

@ -10,6 +10,8 @@
var printerUtils = require('./printer-utils.js').PrinterUtils; var printerUtils = require('./printer-utils.js').PrinterUtils;
var utils = require('./utils.js').Utils; var utils = require('./utils.js').Utils;
var Rematch = require('./rematch.js').Rematch; var Rematch = require('./rematch.js').Rematch;
var diffBlockIdx = 0;
var blockFlag = true;
var hoganUtils; var hoganUtils;
@ -89,6 +91,7 @@
var oldLines = []; var oldLines = [];
var newLines = []; var newLines = [];
blockFlag = true;
function processChangeBlock() { function processChangeBlock() {
var matches; var matches;
@ -124,10 +127,15 @@
that.config.isCombined = file.isCombined; that.config.isCombined = file.isCombined;
var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config); var diff = printerUtils.diffHighlight(oldLine.content, newLine.content, that.config);
var tid = '';
if (blockFlag && oldLines.length && newLines.length) {
tid = 'diff-block-' + diffBlockIdx;
diffBlockIdx += 1;
blockFlag = false;
}
fileHtml.left += fileHtml.left +=
that.generateSingleLineHtml(file.isCombined, deleteType, oldLine.oldNumber, that.generateSingleLineHtml(file.isCombined, deleteType, oldLine.oldNumber,
diff.first.line, diff.first.prefix); diff.first.line, diff.first.prefix, tid);
fileHtml.right += fileHtml.right +=
that.generateSingleLineHtml(file.isCombined, insertType, newLine.newNumber, that.generateSingleLineHtml(file.isCombined, insertType, newLine.newNumber,
diff.second.line, diff.second.prefix); diff.second.line, diff.second.prefix);
@ -158,10 +166,17 @@
} }
if (line.type === diffParser.LINE_TYPE.CONTEXT) { if (line.type === diffParser.LINE_TYPE.CONTEXT) {
blockFlag = true;
fileHtml.left += that.generateSingleLineHtml(file.isCombined, line.type, line.oldNumber, escapedLine, prefix); fileHtml.left += that.generateSingleLineHtml(file.isCombined, line.type, line.oldNumber, escapedLine, prefix);
fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix); fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix);
} else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) { } else if (line.type === diffParser.LINE_TYPE.INSERTS && !oldLines.length) {
fileHtml.left += that.generateSingleLineHtml(file.isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', ''); var tid = '';
if (blockFlag) {
tid = 'diff-block-' + diffBlockIdx;
diffBlockIdx += 1;
blockFlag = false;
}
fileHtml.left += that.generateSingleLineHtml(file.isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '', tid);
fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix); fileHtml.right += that.generateSingleLineHtml(file.isCombined, line.type, line.newNumber, escapedLine, prefix);
} else if (line.type === diffParser.LINE_TYPE.DELETES) { } else if (line.type === diffParser.LINE_TYPE.DELETES) {
oldLines.push(line); oldLines.push(line);
@ -184,6 +199,7 @@
var fileHtml = {}; var fileHtml = {};
fileHtml.left = ''; fileHtml.left = '';
fileHtml.right = ''; fileHtml.right = '';
var LineBlockFlag = true;
var maxLinesNumber = Math.max(oldLines.length, newLines.length); var maxLinesNumber = Math.max(oldLines.length, newLines.length);
for (var i = 0; i < maxLinesNumber; i++) { for (var i = 0; i < maxLinesNumber; i++) {
@ -208,7 +224,15 @@
fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix); fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix);
fileHtml.right += that.generateSingleLineHtml(isCombined, newLine.type, newLine.newNumber, newContent, newPrefix); fileHtml.right += that.generateSingleLineHtml(isCombined, newLine.type, newLine.newNumber, newContent, newPrefix);
} else if (oldLine) { } else if (oldLine) {
fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix); var tid = '';
if (LineBlockFlag && blockFlag) {
tid = 'diff-block-' + diffBlockIdx;
diffBlockIdx += 1;
blockFlag = false;
LineBlockFlag = false;
} else {
}
fileHtml.left += that.generateSingleLineHtml(isCombined, oldLine.type, oldLine.oldNumber, oldContent, oldPrefix, tid);
fileHtml.right += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', ''); fileHtml.right += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '');
} else if (newLine) { } else if (newLine) {
fileHtml.left += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', ''); fileHtml.left += that.generateSingleLineHtml(isCombined, diffParser.LINE_TYPE.CONTEXT, '', '', '');
@ -221,11 +245,12 @@
return fileHtml; return fileHtml;
}; };
SideBySidePrinter.prototype.generateSingleLineHtml = function(isCombined, type, number, content, possiblePrefix) { SideBySidePrinter.prototype.generateSingleLineHtml = function(isCombined, type, number, content, possiblePrefix, tid) {
var lineWithoutPrefix = content; var lineWithoutPrefix = content;
var prefix = possiblePrefix; var prefix = possiblePrefix;
var lineClass = 'd2h-code-side-linenumber'; var lineClass = 'd2h-code-side-linenumber';
var contentClass = 'd2h-code-side-line'; var contentClass = 'd2h-code-side-line';
var idxStr = '';
if (!number && !content) { if (!number && !content) {
lineClass += ' d2h-code-side-emptyplaceholder'; lineClass += ' d2h-code-side-emptyplaceholder';
@ -233,6 +258,10 @@
type += ' d2h-emptyplaceholder'; type += ' d2h-emptyplaceholder';
} }
if (tid) {
idxStr += tid;
}
if (!prefix) { if (!prefix) {
var lineWithPrefix = printerUtils.separatePrefix(isCombined, content); var lineWithPrefix = printerUtils.separatePrefix(isCombined, content);
prefix = lineWithPrefix.prefix; prefix = lineWithPrefix.prefix;
@ -246,7 +275,8 @@
contentClass: contentClass, contentClass: contentClass,
prefix: prefix, prefix: prefix,
content: lineWithoutPrefix, content: lineWithoutPrefix,
lineNumber: number lineNumber: number,
eleID: idxStr
}); });
}; };

View file

@ -5,13 +5,14 @@ global.browserTemplates["file-summary-wrapper"] = new Hogan.Template({code: func
global.browserTemplates["generic-column-line-number"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<tr>");t.b("\n" + i);t.b(" <td class=\"");t.b(t.v(t.f("lineClass",c,p,0)));t.b(" ");t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0)));t.b("\"></td>");t.b("\n" + i);t.b(" <td class=\"");t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" <div class=\"");t.b(t.v(t.f("contentClass",c,p,0)));t.b(" ");t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0)));t.b("\">");t.b(t.t(t.f("blockHeader",c,p,0)));t.b("</div>");t.b("\n" + i);t.b(" </td>");t.b("\n" + i);t.b("</tr>");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["generic-column-line-number"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<tr>");t.b("\n" + i);t.b(" <td class=\"");t.b(t.v(t.f("lineClass",c,p,0)));t.b(" ");t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0)));t.b("\"></td>");t.b("\n" + i);t.b(" <td class=\"");t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" <div class=\"");t.b(t.v(t.f("contentClass",c,p,0)));t.b(" ");t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0)));t.b("\">");t.b(t.t(t.f("blockHeader",c,p,0)));t.b("</div>");t.b("\n" + i);t.b(" </td>");t.b("\n" + i);t.b("</tr>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["generic-empty-diff"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<tr>");t.b("\n" + i);t.b(" <td class=\"");t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" <div class=\"");t.b(t.v(t.f("contentClass",c,p,0)));t.b(" ");t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" File without changes");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" </td>");t.b("\n" + i);t.b("</tr>");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["generic-empty-diff"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<tr>");t.b("\n" + i);t.b(" <td class=\"");t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" <div class=\"");t.b(t.v(t.f("contentClass",c,p,0)));t.b(" ");t.b(t.v(t.d("diffParser.LINE_TYPE.INFO",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" File without changes");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" </td>");t.b("\n" + i);t.b("</tr>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["generic-file-path"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<span class=\"d2h-file-name-wrapper\">");t.b("\n" + i);t.b(t.rp("<fileIcon0",c,p," "));t.b(" <span class=\"d2h-file-name\">");t.b(t.v(t.f("fileDiffName",c,p,0)));t.b("</span>");t.b("\n" + i);t.b(t.rp("<fileTag1",c,p," "));t.b("</span>");return t.fl(); },partials: {"<fileIcon0":{name:"fileIcon", partials: {}, subs: { }},"<fileTag1":{name:"fileTag", partials: {}, subs: { }}}, subs: { }}); global.browserTemplates["generic-file-path"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<span class=\"d2h-file-name-wrapper\">");t.b("\n" + i);t.b(t.rp("<fileIcon0",c,p," "));t.b(" <span class=\"d2h-file-name\">");t.b(t.v(t.f("fileDiffName",c,p,0)));t.b("</span>");t.b("\n" + i);t.b(t.rp("<fileTag1",c,p," "));t.b("</span>");return t.fl(); },partials: {"<fileIcon0":{name:"fileIcon", partials: {}, subs: { }},"<fileTag1":{name:"fileTag", partials: {}, subs: { }}}, subs: { }});
global.browserTemplates["generic-float-button"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<div class=\"btn-group-vertical\" role=\"group\" style=\"position: fixed;left: 100px;\">\r");t.b("\n" + i);t.b(" <span class=\"glyphicon glyphicon-chevron-up\" aria-hidden=\"true\"></span>\r");t.b("\n" + i);t.b(" <button type=\"button\" class=\"btn btn-danger\">Previous</button>\r");t.b("\n" + i);t.b(" <button type=\"button\" class=\"btn btn-danger\">Next</button>\r");t.b("\n" + i);t.b(" <span class=\"glyphicon glyphicon-chevron-down\" aria-hidden=\"true\"></span>\r");t.b("\n" + i);t.b("</div>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["generic-line"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<tr>");t.b("\n" + i);t.b(" <td class=\"");t.b(t.v(t.f("lineClass",c,p,0)));t.b(" ");t.b(t.v(t.f("type",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("lineNumber",c,p,0)));t.b("\n" + i);t.b(" </td>");t.b("\n" + i);t.b(" <td class=\"");t.b(t.v(t.f("type",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" <div class=\"");t.b(t.v(t.f("contentClass",c,p,0)));t.b(" ");t.b(t.v(t.f("type",c,p,0)));t.b("\">");t.b("\n" + i);if(t.s(t.f("prefix",c,p,1),c,p,0,171,247,"{{ }}")){t.rs(c,p,function(c,p,t){t.b(" <span class=\"d2h-code-line-prefix\">");t.b(t.t(t.f("prefix",c,p,0)));t.b("</span>");t.b("\n" + i);});c.pop();}if(t.s(t.f("content",c,p,1),c,p,0,279,353,"{{ }}")){t.rs(c,p,function(c,p,t){t.b(" <span class=\"d2h-code-line-ctn\">");t.b(t.t(t.f("content",c,p,0)));t.b("</span>");t.b("\n" + i);});c.pop();}t.b(" </div>");t.b("\n" + i);t.b(" </td>");t.b("\n" + i);t.b("</tr>");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["generic-line"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<tr>");t.b("\n" + i);t.b(" <td class=\"");t.b(t.v(t.f("lineClass",c,p,0)));t.b(" ");t.b(t.v(t.f("type",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("lineNumber",c,p,0)));t.b("\n" + i);t.b(" </td>");t.b("\n" + i);t.b(" <td class=\"");t.b(t.v(t.f("type",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" <div class=\"");t.b(t.v(t.f("contentClass",c,p,0)));t.b(" ");t.b(t.v(t.f("type",c,p,0)));t.b("\">");t.b("\n" + i);if(t.s(t.f("prefix",c,p,1),c,p,0,171,247,"{{ }}")){t.rs(c,p,function(c,p,t){t.b(" <span class=\"d2h-code-line-prefix\">");t.b(t.t(t.f("prefix",c,p,0)));t.b("</span>");t.b("\n" + i);});c.pop();}if(t.s(t.f("content",c,p,1),c,p,0,279,353,"{{ }}")){t.rs(c,p,function(c,p,t){t.b(" <span class=\"d2h-code-line-ctn\">");t.b(t.t(t.f("content",c,p,0)));t.b("</span>");t.b("\n" + i);});c.pop();}t.b(" </div>");t.b("\n" + i);t.b(" </td>");t.b("\n" + i);t.b("</tr>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["generic-wrapper"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<div class=\"d2h-wrapper\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("content",c,p,0)));t.b("\n" + i);t.b("</div>");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["generic-wrapper"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<div class=\"d2h-wrapper\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("content",c,p,0)));t.b("\n" + i);t.b("</div>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["icon-file-added"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-added\" height=\"16\" title=\"added\" version=\"1.1\" viewBox=\"0 0 14 16\"");t.b("\n" + i);t.b(" width=\"14\">");t.b("\n" + i);t.b(" <path d=\"M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM6 9H3V7h3V4h2v3h3v2H8v3H6V9z\"></path>");t.b("\n" + i);t.b("</svg>");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["icon-file-added"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-added\" height=\"16\" title=\"added\" version=\"1.1\" viewBox=\"0 0 14 16\"");t.b("\n" + i);t.b(" width=\"14\">");t.b("\n" + i);t.b(" <path d=\"M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM6 9H3V7h3V4h2v3h3v2H8v3H6V9z\"></path>");t.b("\n" + i);t.b("</svg>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["icon-file-changed"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-changed\" height=\"16\" title=\"modified\" version=\"1.1\"");t.b("\n" + i);t.b(" viewBox=\"0 0 14 16\" width=\"14\">");t.b("\n" + i);t.b(" <path d=\"M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM4 8c0-1.66 1.34-3 3-3s3 1.34 3 3-1.34 3-3 3-3-1.34-3-3z\"></path>");t.b("\n" + i);t.b("</svg>");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["icon-file-changed"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-changed\" height=\"16\" title=\"modified\" version=\"1.1\"");t.b("\n" + i);t.b(" viewBox=\"0 0 14 16\" width=\"14\">");t.b("\n" + i);t.b(" <path d=\"M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM4 8c0-1.66 1.34-3 3-3s3 1.34 3 3-1.34 3-3 3-3-1.34-3-3z\"></path>");t.b("\n" + i);t.b("</svg>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["icon-file-deleted"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-deleted\" height=\"16\" title=\"removed\" version=\"1.1\"");t.b("\n" + i);t.b(" viewBox=\"0 0 14 16\" width=\"14\">");t.b("\n" + i);t.b(" <path d=\"M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM11 9H3V7h8v2z\"></path>");t.b("\n" + i);t.b("</svg>");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["icon-file-deleted"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-deleted\" height=\"16\" title=\"removed\" version=\"1.1\"");t.b("\n" + i);t.b(" viewBox=\"0 0 14 16\" width=\"14\">");t.b("\n" + i);t.b(" <path d=\"M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM11 9H3V7h8v2z\"></path>");t.b("\n" + i);t.b("</svg>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["icon-file-renamed"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-moved\" height=\"16\" title=\"renamed\" version=\"1.1\"");t.b("\n" + i);t.b(" viewBox=\"0 0 14 16\" width=\"14\">");t.b("\n" + i);t.b(" <path d=\"M6 9H3V7h3V4l5 4-5 4V9z m8-7v12c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h12c0.55 0 1 0.45 1 1z m-1 0H1v12h12V2z\"></path>");t.b("\n" + i);t.b("</svg>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["icon-file"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<svg aria-hidden=\"true\" class=\"d2h-icon\" height=\"16\" version=\"1.1\" viewBox=\"0 0 12 16\" width=\"12\">");t.b("\n" + i);t.b(" <path d=\"M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z\"></path>");t.b("\n" + i);t.b("</svg>");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["icon-file"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<svg aria-hidden=\"true\" class=\"d2h-icon\" height=\"16\" version=\"1.1\" viewBox=\"0 0 12 16\" width=\"12\">");t.b("\n" + i);t.b(" <path d=\"M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z\"></path>");t.b("\n" + i);t.b("</svg>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["icon-file-renamed"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<svg aria-hidden=\"true\" class=\"d2h-icon d2h-moved\" height=\"16\" title=\"renamed\" version=\"1.1\"");t.b("\n" + i);t.b(" viewBox=\"0 0 14 16\" width=\"14\">");t.b("\n" + i);t.b(" <path d=\"M6 9H3V7h3V4l5 4-5 4V9z m8-7v12c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h12c0.55 0 1 0.45 1 1z m-1 0H1v12h12V2z\"></path>");t.b("\n" + i);t.b("</svg>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["line-by-line-file-diff"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<div id=\"");t.b(t.v(t.f("fileHtmlId",c,p,0)));t.b("\" class=\"d2h-file-wrapper\" data-lang=\"");t.b(t.v(t.d("file.language",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" <div class=\"d2h-file-header\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("filePath",c,p,0)));t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" <div class=\"d2h-file-diff\">");t.b("\n" + i);t.b(" <div class=\"d2h-code-wrapper\">");t.b("\n" + i);t.b(" <table class=\"d2h-diff-table\">");t.b("\n" + i);t.b(" <tbody class=\"d2h-diff-tbody\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("diffs",c,p,0)));t.b("\n" + i);t.b(" </tbody>");t.b("\n" + i);t.b(" </table>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b("</div>");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["line-by-line-file-diff"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<div id=\"");t.b(t.v(t.f("fileHtmlId",c,p,0)));t.b("\" class=\"d2h-file-wrapper\" data-lang=\"");t.b(t.v(t.d("file.language",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" <div class=\"d2h-file-header\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("filePath",c,p,0)));t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" <div class=\"d2h-file-diff\">");t.b("\n" + i);t.b(" <div class=\"d2h-code-wrapper\">");t.b("\n" + i);t.b(" <table class=\"d2h-diff-table\">");t.b("\n" + i);t.b(" <tbody class=\"d2h-diff-tbody\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("diffs",c,p,0)));t.b("\n" + i);t.b(" </tbody>");t.b("\n" + i);t.b(" </table>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b("</div>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["line-by-line-numbers"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<div class=\"line-num1\">");t.b(t.v(t.f("oldNumber",c,p,0)));t.b("</div>");t.b("\n" + i);t.b("<div class=\"line-num2\">");t.b(t.v(t.f("newNumber",c,p,0)));t.b("</div>");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["line-by-line-numbers"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<div class=\"line-num1\">");t.b(t.v(t.f("oldNumber",c,p,0)));t.b("</div>");t.b("\n" + i);t.b("<div class=\"line-num2\">");t.b(t.v(t.f("newNumber",c,p,0)));t.b("</div>");return t.fl(); },partials: {}, subs: { }});
global.browserTemplates["side-by-side-file-diff"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<div id=\"");t.b(t.v(t.f("fileHtmlId",c,p,0)));t.b("\" class=\"d2h-file-wrapper\" data-lang=\"");t.b(t.v(t.d("file.language",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" <div class=\"d2h-file-header\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("filePath",c,p,0)));t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" <div class=\"d2h-files-diff\">");t.b("\n" + i);t.b(" <div class=\"d2h-file-side-diff\">");t.b("\n" + i);t.b(" <div class=\"d2h-code-wrapper\">");t.b("\n" + i);t.b(" <table class=\"d2h-diff-table\">");t.b("\n" + i);t.b(" <tbody class=\"d2h-diff-tbody\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.d("diffs.left",c,p,0)));t.b("\n" + i);t.b(" </tbody>");t.b("\n" + i);t.b(" </table>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" <div class=\"d2h-file-side-diff\">");t.b("\n" + i);t.b(" <div class=\"d2h-code-wrapper\">");t.b("\n" + i);t.b(" <table class=\"d2h-diff-table\">");t.b("\n" + i);t.b(" <tbody class=\"d2h-diff-tbody\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.d("diffs.right",c,p,0)));t.b("\n" + i);t.b(" </tbody>");t.b("\n" + i);t.b(" </table>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b("</div>");return t.fl(); },partials: {}, subs: { }}); global.browserTemplates["side-by-side-file-diff"] = new Hogan.Template({code: function (c,p,i) { var t=this;t.b(i=i||"");t.b("<div id=\"");t.b(t.v(t.f("fileHtmlId",c,p,0)));t.b("\" class=\"d2h-file-wrapper\" data-lang=\"");t.b(t.v(t.d("file.language",c,p,0)));t.b("\">");t.b("\n" + i);t.b(" <div class=\"d2h-file-header\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.f("filePath",c,p,0)));t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" <div class=\"d2h-files-diff\">");t.b("\n" + i);t.b(" <div class=\"d2h-file-side-diff\">");t.b("\n" + i);t.b(" <div class=\"d2h-code-wrapper\">");t.b("\n" + i);t.b(" <table class=\"d2h-diff-table\">");t.b("\n" + i);t.b(" <tbody class=\"d2h-diff-tbody\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.d("diffs.left",c,p,0)));t.b("\n" + i);t.b(" </tbody>");t.b("\n" + i);t.b(" </table>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" <div class=\"d2h-file-side-diff\">");t.b("\n" + i);t.b(" <div class=\"d2h-code-wrapper\">");t.b("\n" + i);t.b(" <table class=\"d2h-diff-table\">");t.b("\n" + i);t.b(" <tbody class=\"d2h-diff-tbody\">");t.b("\n" + i);t.b(" ");t.b(t.t(t.d("diffs.right",c,p,0)));t.b("\n" + i);t.b(" </tbody>");t.b("\n" + i);t.b(" </table>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b(" </div>");t.b("\n" + i);t.b("</div>");return t.fl(); },partials: {}, subs: { }});

View file

@ -0,0 +1,6 @@
<div class="btn-group-vertical" role="group" style="position: fixed;left: 100px;">
<span class="glyphicon glyphicon-chevron-up" aria-hidden="true"></span>
<button type="button" class="btn btn-danger btn-previous">Previous</button>
<button type="button" class="btn btn-danger btn-next">Next</button>
<span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span>
</div>

View file

@ -1,5 +1,5 @@
<tr> <tr>
<td class="{{lineClass}} {{type}}"> <td class="{{lineClass}} {{type}}" id="{{eleID}}">
{{{lineNumber}}} {{{lineNumber}}}
</td> </td>
<td class="{{type}}"> <td class="{{type}}">

View file

@ -16,6 +16,7 @@
var diffJson = null; var diffJson = null;
var defaultTarget = 'body'; var defaultTarget = 'body';
var currentSelectionColumnId = -1; var currentSelectionColumnId = -1;
var currentDiffBlockIdx = -1;
function Diff2HtmlUI(config) { function Diff2HtmlUI(config) {
var cfg = config || {}; var cfg = config || {};
@ -190,6 +191,33 @@
clipboardData.setData('text', text); clipboardData.setData('text', text);
event.preventDefault(); event.preventDefault();
}); });
body.on('mousedown', '.btn-previous', function() {
if (currentDiffBlockIdx === -1){
return;
}
currentDiffBlockIdx -= 1;
var target = document.getElementById('diff-block-' + currentDiffBlockIdx);
if (target) {
var top = target.offsetTop + 200;
window.scrollTo(0, top);
} else {
currentDiffBlockIdx = 0;
alert('already first');
}
});
body.on('mousedown', '.btn-next', function() {
currentDiffBlockIdx += 1;
var target = document.getElementById('diff-block-' + currentDiffBlockIdx);
if (target) {
var top = target.offsetTop + 200;
window.scrollTo(0, top);
} else {
currentDiffBlockIdx -= 1;
alert('already last');
}
});
}; };
Diff2HtmlUI.prototype._getSelectedText = function() { Diff2HtmlUI.prototype._getSelectedText = function() {