Use hashcode instead of filename for file list id

This commit is contained in:
Nuno Teixeira 2015-10-19 15:43:16 +01:00
parent f1db9a9d6f
commit c2fb4bf1da
4 changed files with 29 additions and 5 deletions

15
dist/diff2html.js vendored
View file

@ -458,7 +458,7 @@
} }
FileListPrinter.prototype.generateFileList = function (diffFiles) { FileListPrinter.prototype.generateFileList = function (diffFiles) {
var hideId = utils.getRandomId("d2h-hide"); var hideId = utils.getRandomId("d2h-hide"); //necessary if there are 2 elements like this in the same page
var showId = utils.getRandomId("d2h-show"); var showId = utils.getRandomId("d2h-show");
return '<div class="d2h-file-list-wrapper">\n' + return '<div class="d2h-file-list-wrapper">\n' +
' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')&nbsp&nbsp</div>\n' + ' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')&nbsp&nbsp</div>\n' +
@ -505,7 +505,18 @@
} }
PrinterUtils.prototype.getHtmlId = function(file) { PrinterUtils.prototype.getHtmlId = function(file) {
return "d2h-" + this.getDiffName(file); var hashCode = function(text) {
var hash = 0, i, chr, len;
if (text.length == 0) return hash;
for (i = 0, len = text.length; i < len; i++) {
chr = text.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
return "d2h-" + hashCode(this.getDiffName(file)).toString().slice(-6);
}; };
PrinterUtils.prototype.getDiffName = function(file) { PrinterUtils.prototype.getDiffName = function(file) {

File diff suppressed because one or more lines are too long

View file

@ -14,7 +14,7 @@
} }
FileListPrinter.prototype.generateFileList = function (diffFiles) { FileListPrinter.prototype.generateFileList = function (diffFiles) {
var hideId = utils.getRandomId("d2h-hide"); var hideId = utils.getRandomId("d2h-hide"); //necessary if there are 2 elements like this in the same page
var showId = utils.getRandomId("d2h-show"); var showId = utils.getRandomId("d2h-show");
return '<div class="d2h-file-list-wrapper">\n' + return '<div class="d2h-file-list-wrapper">\n' +
' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')&nbsp&nbsp</div>\n' + ' <div class="d2h-file-list-header">Files changed (' + diffFiles.length + ')&nbsp&nbsp</div>\n' +

View file

@ -14,7 +14,18 @@
} }
PrinterUtils.prototype.getHtmlId = function(file) { PrinterUtils.prototype.getHtmlId = function(file) {
return "d2h-" + this.getDiffName(file); var hashCode = function(text) {
var hash = 0, i, chr, len;
if (text.length == 0) return hash;
for (i = 0, len = text.length; i < len; i++) {
chr = text.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
return "d2h-" + hashCode(this.getDiffName(file)).toString().slice(-6);
}; };
PrinterUtils.prototype.getDiffName = function(file) { PrinterUtils.prototype.getDiffName = function(file) {