fix empty lines (needs refactor)

This commit is contained in:
Rodrigo Fernandes 2014-09-27 01:29:32 +01:00
parent aea62331f3
commit f4dc516c25
6 changed files with 352 additions and 307 deletions

View file

@ -3,7 +3,7 @@
* Diff to HTML (diff2html.css)
* Author: rtfpessoa
* Date: Friday 29 August 2014
* Last Update: Sunday 14 September 2014
* Last Update: Saturday 27 September 2014
*
*/
@ -109,7 +109,7 @@
display: inline-block;
margin-top: -1px;
text-decoration: none;
background-color: #f99;
background-color: #ffb6ba;
font-weight: 700;
border-radius: 0.2em;
}
@ -119,7 +119,7 @@
display: inline-block;
margin-top: -1px;
text-decoration: none;
background-color: #6f7;
background-color: #97f295;
font-weight: 700;
border-radius: 0.2em;
}
@ -174,12 +174,12 @@
}
.d2h-del {
background-color: #f7c8c8;
background-color: #fee8e9;
border-color: #e9aeae;
}
.d2h-ins {
background-color: #ceffce;
background-color: #dfd;
border-color: #b4e2b4;
}

View file

@ -3,10 +3,10 @@
* Diff to HTML (diff2html.js)
* Author: rtfpessoa
* Date: Friday 29 August 2014
* Last Update: Sunday 14 September 2014
* Last Update: Saturday 27 September 2014
*
* Diff command:
* git diff --word-diff-regex=. HEAD~1
* git diff
*/
(function (window) {
@ -16,14 +16,8 @@
var LINE_TYPE = {
INSERTS: "d2h-ins",
ALL_NEW: "d2h-all-ins",
DELETES: "d2h-del",
ALL_DELETED: "d2h-all-del",
INSERTS_AND_DELETES: "d2h-ins-and-del",
CONTEXT: "d2h-cntx",
INFO: "d2h-info"
};
@ -127,74 +121,34 @@
};
var createLine = function (line) {
/* Line Types */
var isLineWithInserts = /{\+.*?\+}/.exec(line);
var isNewLine = /^{\+.*?\+}$/.exec(line);
var isLineWithDeletes = /\[-.*?-\]/.exec(line);
var isRemovedLine = /^\[-.*?-\]$/.exec(line);
var isLineWithBoth = isLineWithInserts && isLineWithDeletes;
var isContextLine = !isLineWithInserts && !isLineWithDeletes;
var currentLine = {};
currentLine.content = line;
/* fill the line data */
if (isLineWithBoth) {
currentFile.deletedLines++;
if (startsWith(line, "+")) {
currentFile.addedLines++;
currentLine.type = LINE_TYPE.INSERTS_AND_DELETES;
currentLine.oldNumber = oldLine++;
currentLine.newNumber = newLine++;
currentBlock.lines.push(currentLine);
} else if (isContextLine) {
currentLine.type = LINE_TYPE.CONTEXT;
currentLine.oldNumber = oldLine++;
currentLine.newNumber = newLine++;
currentBlock.lines.push(currentLine);
} else if (isNewLine) {
currentFile.addedLines++;
currentLine.type = LINE_TYPE.ALL_NEW;
currentLine.type = LINE_TYPE.INSERTS;
currentLine.oldNumber = null;
currentLine.newNumber = newLine++;
currentBlock.lines.push(currentLine);
} else if (isRemovedLine) {
} else if (startsWith(line, "-")) {
currentFile.deletedLines++;
currentLine.type = LINE_TYPE.ALL_DELETED;
currentLine.type = LINE_TYPE.DELETES;
currentLine.oldNumber = oldLine++;
currentLine.newNumber = null;
currentBlock.lines.push(currentLine);
} else if (isLineWithInserts) {
currentFile.addedLines++;
currentLine.type = LINE_TYPE.INSERTS;
} else {
currentLine.type = LINE_TYPE.CONTEXT;
currentLine.oldNumber = oldLine++;
currentLine.newNumber = newLine++;
currentBlock.lines.push(currentLine);
} else if (isLineWithDeletes) {
currentFile.deletedLines++;
currentLine.type = LINE_TYPE.DELETES;
currentLine.oldNumber = oldLine++;
currentLine.newNumber = newLine++;
currentBlock.lines.push(currentLine);
}
};
@ -256,75 +210,47 @@
var generateFileHtml = function (file) {
return file.blocks.map(function (block) {
return "<tr>\n" +
var lines = "<tr>\n" +
" <td class=\"d2h-code-linenumber " + LINE_TYPE.INFO + "\" colspan=\"2\"></td>\n" +
" <td class=\"" + LINE_TYPE.INFO + "\">" +
" <div class=\"d2h-code-line " + LINE_TYPE.INFO + "\">" + escape(block.header) + "</div>" +
" </td>\n" +
"</tr>\n" +
"</tr>\n";
block.lines.map(function (line) {
for (var i = 0; i < block.lines.length; i++) {
var line = block.lines[i];
var newLine = block.lines[i + 1];
var newLine = function () {
var lineData = {};
lineData.oldLine = valueOrEmpty(line.oldNumber);
lineData.newLine = valueOrEmpty(line.newNumber);
return lineData;
};
if (line.type == LINE_TYPE.DELETES &&
newLine && newLine.type == LINE_TYPE.INSERTS) {
i++;
var escapedLine = escape(line.content);
var nextEscapedLine = escape(newLine.content);
var lines = [];
var lineData = {};
var diff = diffString(escapedLine, nextEscapedLine);
switch (line.type) {
case LINE_TYPE.INSERTS:
case LINE_TYPE.ALL_NEW:
lineData = newLine();
lineData.content = generateLineInsertions(escapedLine);
lineData.type = LINE_TYPE.INSERTS;
lines.push(lineData);
break;
case LINE_TYPE.DELETES:
case LINE_TYPE.ALL_DELETED:
lineData = newLine();
lineData.content = generateLineDeletions(escapedLine);
lineData.type = LINE_TYPE.DELETES;
lines.push(lineData);
break;
case LINE_TYPE.INSERTS_AND_DELETES:
lineData = newLine();
lineData.content = generateLineDeletions(escapedLine);
lineData.type = LINE_TYPE.DELETES;
lines.push(lineData);
lineData = newLine();
lineData.content = generateLineInsertions(escapedLine);
lineData.type = LINE_TYPE.INSERTS;
lines.push(lineData);
break;
default:
lineData = newLine();
lineData.content = escapedLine;
lineData.type = LINE_TYPE.CONTEXT;
lines.push(lineData);
break;
lines = lines +
generateLineHtml(line.type, line.oldNumber, line.newNumber, removeIns(diff)) +
generateLineHtml(newLine.type, newLine.oldNumber, newLine.newNumber, removeDel(diff));
} else {
lines = lines +
generateLineHtml(line.type, line.oldNumber, line.newNumber, line.content);
}
}
return lines.map(generateLineHtml).join("\n");
}).join("\n");
return lines;
}).join("\n");
};
var generateLineHtml = function (line) {
var generateLineHtml = function (type, oldNumber, newNumber, content) {
return "<tr>\n" +
" <td class=\"d2h-code-linenumber " + line.type + "\">" +
" <div class=\"line-num1\">" + line.oldLine + "</div>" +
" <div class=\"line-num2\">" + line.newLine + "</div>" +
" <td class=\"d2h-code-linenumber " + type + "\">" +
" <div class=\"line-num1\">" + valueOrEmpty(oldNumber) + "</div>" +
" <div class=\"line-num2\">" + valueOrEmpty(newNumber) + "</div>" +
" </td>\n" +
" <td class=\"" + line.type + "\">" +
" <div class=\"d2h-code-line " + line.type + "\">" + line.content + "</div>" +
" <td class=\"" + type + "\">" +
" <div class=\"d2h-code-line " + type + "\">" + content + "</div>" +
" </td>\n" +
"</tr>\n";
};
@ -336,6 +262,8 @@
var generateSideBySideJsonHtml = function (diffFiles) {
return "<div class=\"d2h-wrapper\">\n" +
diffFiles.map(function (file) {
var diffs = generateSideBySideFileHtml(file);
return "<div class=\"d2h-file-wrapper\">\n" +
" <div class=\"d2h-file-header\">\n" +
" <div class=\"d2h-file-stats\">\n" +
@ -349,7 +277,7 @@
" <div class=\"d2h-code-wrapper\">\n" +
" <table class=\"d2h-diff-table\">\n" +
" <tbody class=\"d2h-diff-tbody\">\n" +
" " + generateLeftSideFileHtml(file) +
" " + diffs.left +
" </tbody>\n" +
" </table>\n" +
" </div>\n" +
@ -358,7 +286,7 @@
" <div class=\"d2h-code-wrapper\">\n" +
" <table class=\"d2h-diff-table\">\n" +
" <tbody class=\"d2h-diff-tbody\">\n" +
" " + generateRightSideFileHtml(file) +
" " + diffs.right +
" </tbody>\n" +
" </table>\n" +
" </div>\n" +
@ -369,154 +297,70 @@
"</div>\n";
};
var generateLeftSideFileHtml = function (file) {
return file.blocks.map(function (block) {
var generateSideBySideFileHtml = function (file) {
var fileHtml = {};
fileHtml.left = "";
fileHtml.right = "";
return "<tr>\n" +
file.blocks.forEach(function (block) {
fileHtml.left += "<tr>\n" +
" <td class=\"d2h-code-side-linenumber " + LINE_TYPE.INFO + "\"></td>\n" +
" <td class=\"" + LINE_TYPE.INFO + "\" colspan=\"3\">" +
" <div class=\"d2h-code-side-line " + LINE_TYPE.INFO + "\">" + escape(block.header) + "</div>" +
" </td>\n" +
"</tr>\n" +
"</tr>\n";
block.lines.map(function (line) {
var emptyLine = function () {
var lineData = {};
lineData.number = "";
lineData.content = "";
lineData.type = LINE_TYPE.CONTEXT;
return lineData;
};
var escapedLine = escape(line.content);
var lines = [];
var lineData = {};
switch (line.type) {
case LINE_TYPE.INSERTS:
lineData = {};
lineData.number = valueOrEmpty(line.oldNumber);
lineData.content = removeInserts(escapedLine);
lineData.type = LINE_TYPE.CONTEXT;
lines.push(lineData);
break;
case LINE_TYPE.ALL_NEW:
lines.push(new emptyLine());
break;
case LINE_TYPE.DELETES:
lineData = {};
lineData.number = valueOrEmpty(line.oldNumber);
lineData.content = generateLineDeletions(escapedLine);
lineData.type = LINE_TYPE.DELETES;
lines.push(lineData);
break;
case LINE_TYPE.ALL_DELETED:
lineData = {};
lineData.number = valueOrEmpty(line.oldNumber);
lineData.content = generateLineDeletions(escapedLine);
lineData.type = LINE_TYPE.DELETES;
lines.push(lineData);
break;
case LINE_TYPE.INSERTS_AND_DELETES:
lineData = {};
lineData.number = valueOrEmpty(line.oldNumber);
lineData.content = generateLineDeletions(escapedLine);
lineData.type = LINE_TYPE.DELETES;
lines.push(lineData);
break;
default:
lineData = {};
lineData.number = valueOrEmpty(line.oldNumber);
lineData.content = escapedLine;
lineData.type = LINE_TYPE.CONTEXT;
lines.push(lineData);
break;
}
return "<tr>\n" + lines.map(generateSingleLineHtml).join("\n") + "</tr>\n";
}).join("\n");
}).join("\n");
};
var generateRightSideFileHtml = function (file) {
return file.blocks.map(function (block) {
return "<tr>\n" +
fileHtml.right += "<tr>\n" +
" <td class=\"d2h-code-side-linenumber " + LINE_TYPE.INFO + "\"></td>\n" +
" <td class=\"" + LINE_TYPE.INFO + "\" colspan=\"3\">" +
" <div class=\"d2h-code-side-line " + LINE_TYPE.INFO + "\"></div>" +
" </td>\n" +
"</tr>\n" +
"</tr>\n";
block.lines.map(function (line) {
for (var i = 0; i < block.lines.length; i++) {
var emptyLine = function () {
var lineData = {};
lineData.number = "";
lineData.content = "";
lineData.type = LINE_TYPE.CONTEXT;
fileHtml.left += "<tr>\n";
fileHtml.right += "<tr>\n";
return lineData;
};
var line = block.lines[i];
var newLine = block.lines[i + 1];
if (line.type == LINE_TYPE.DELETES &&
newLine && newLine.type == LINE_TYPE.INSERTS) {
i++;
var escapedLine = escape(line.content);
var nextEscapedLine = escape(newLine.content);
var lines = [];
var lineData = {};
var diff = diffString(escapedLine, nextEscapedLine);
switch (line.type) {
case LINE_TYPE.INSERTS:
lineData = {};
lineData.number = valueOrEmpty(line.newNumber);
lineData.content = generateLineInsertions(escapedLine);
lineData.type = LINE_TYPE.INSERTS;
lines.push(lineData);
break;
case LINE_TYPE.ALL_NEW:
lineData = {};
lineData.number = valueOrEmpty(line.newNumber);
lineData.content = generateLineInsertions(escapedLine);
lineData.type = LINE_TYPE.INSERTS;
lines.push(lineData);
break;
case LINE_TYPE.DELETES:
lineData = {};
lineData.number = valueOrEmpty(line.newNumber);
lineData.content = removeDeletes(escapedLine);
lineData.type = LINE_TYPE.CONTEXT;
lines.push(lineData);
break;
case LINE_TYPE.ALL_DELETED:
lines.push(new emptyLine());
break;
case LINE_TYPE.INSERTS_AND_DELETES:
lineData = {};
lineData.number = valueOrEmpty(line.newNumber);
lineData.content = generateLineInsertions(escapedLine);
lineData.type = LINE_TYPE.INSERTS;
lines.push(lineData);
break;
default:
lineData = {};
lineData.number = valueOrEmpty(line.newNumber);
lineData.content = escapedLine;
lineData.type = LINE_TYPE.CONTEXT;
lines.push(lineData);
break;
fileHtml.left += generateSingleLineHtml(line.type, line.oldNumber, removeIns(diff));
fileHtml.right += generateSingleLineHtml(newLine.type, newLine.newNumber, removeDel(diff));
} else if (line.type == LINE_TYPE.DELETES) {
fileHtml.left += generateSingleLineHtml(line.type, line.oldNumber, line.content);
fileHtml.right += generateSingleLineHtml(LINE_TYPE.CONTEXT, "", "", "");
} else if (line.type == LINE_TYPE.INSERTS) {
fileHtml.left += generateSingleLineHtml(LINE_TYPE.CONTEXT, "", "", "");
fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, line.content);
} else {
fileHtml.left += generateSingleLineHtml(line.type, line.oldNumber, line.content);
fileHtml.right += generateSingleLineHtml(line.type, line.newNumber, line.content);
}
return "<tr>\n" + lines.map(generateSingleLineHtml).join("\n") + "</tr>\n";
}).join("\n");
}).join("\n");
fileHtml.left += "</tr>\n";
fileHtml.right += "</tr>\n";
}
});
return fileHtml;
};
var generateSingleLineHtml = function (line) {
return "<td class=\"d2h-code-side-linenumber " + line.type + "\">" + line.number + "</td>\n" +
" <td class=\"" + line.type + "\">" +
" <div class=\"d2h-code-side-line " + line.type + "\">" + line.content + "</div>" +
var generateSingleLineHtml = function (type, number, content) {
return "<td class=\"d2h-code-side-linenumber " + type + "\">" + number + "</td>\n" +
" <td class=\"" + type + "\">" +
" <div class=\"d2h-code-side-line " + type + "\">" + content + "</div>" +
" </td>\n";
};
@ -528,24 +372,12 @@
return oldFilename === newFilename ? newFilename : oldFilename + " -> " + newFilename;
};
var generateLineInsertions = function (line) {
return line.slice(0).replace(/(\[-.*?-\])/g, "").
replace(/({\+(.*?)\+})/g, "<ins>$2</ins>");
var removeIns = function (line) {
return line.replace(/(<ins>(.*?)<\/ins>)/g, "");
};
var generateLineDeletions = function (line) {
return line.slice(0).replace(/({\+.*?\+})/g, "").
replace(/(\[-(.*?)-\])/g, "<del>$2</del>");
};
var removeDeletes = function (line) {
return line.slice(0).replace(/({\+.*?\+})/g, "").
replace(/(\[-.*?-\])/g, "");
};
var removeInserts = function (line) {
return line.slice(0).replace(/({\+.*?\+})/g, "").
replace(/(\[-.*?-\])/g, "");
var removeDel = function (line) {
return line.replace(/(<del>(.*?)<\/del>)/g, "");
};
/*

2
diff2html.min.css vendored
View file

@ -1 +1 @@
.d2h-wrapper{display:block;margin:0 auto;text-align:left;width:100%}.d2h-file-wrapper{border:1px solid #ddd;border-radius:3px;margin-bottom:1em}.d2h-file-header{padding:5px 10px;border-bottom:1px solid #d8d8d8;background-color:#f7f7f7;font:13px Helvetica,arial,freesans,clean,sans-serif,"Segoe UI Emoji","Segoe UI Symbol"}.d2h-file-stats{display:inline;font-size:12px;text-align:center;max-width:15%}.d2h-lines-added{background-color:#ceffce;border:1px solid #b4e2b4;color:#399839;border-radius:5px 0 0 5px;padding:2px;width:25px}.d2h-lines-deleted{background-color:#f7c8c8;border:1px solid #e9aeae;color:#c33;border-radius:0 5px 5px 0;padding:2px;width:25px}.d2h-file-name{display:inline;height:33px;line-height:33px;max-width:80%;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.d2h-diff-table{border-collapse:collapse;font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;height:18px;line-height:18px;width:100%}.d2h-files-diff{width:100%}.d2h-file-diff{overflow-x:scroll}.d2h-file-side-diff{display:inline-block;overflow-x:scroll;width:50%;margin-right:-4px}.d2h-code-line{white-space:pre;padding-left:10px;padding-right:10px;height:18px;line-height:18px;margin-left:80px}.d2h-code-side-line{white-space:pre;padding-left:10px;padding-right:10px;height:18px;line-height:18px;margin-left:50px}.d2h-code-line del,.d2h-code-side-line del{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#f99;font-weight:700;border-radius:.2em}.d2h-code-line ins,.d2h-code-side-line ins{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#6f7;font-weight:700;border-radius:.2em}.line-num1{display:inline-block;float:left;width:30px;overflow:hidden;text-overflow:ellipsis}.line-num2{display:inline-block;float:right;width:30px;overflow:hidden;text-overflow:ellipsis}.d2h-code-linenumber{position:absolute;width:2%;min-width:65px;padding-left:10px;padding-right:10px;height:18px;line-height:18px;background-color:#fff;color:rgba(0,0,0,.3);text-align:right;border:solid #eee;border-width:0 1px;cursor:pointer}.d2h-code-side-linenumber{position:absolute;width:35px;padding-left:10px;padding-right:10px;height:18px;line-height:18px;background-color:#fff;color:rgba(0,0,0,.3);text-align:right;border:solid #eee;border-width:0 1px;cursor:pointer;overflow:hidden;text-overflow:ellipsis}.d2h-del{background-color:#f7c8c8;border-color:#e9aeae}.d2h-ins{background-color:#ceffce;border-color:#b4e2b4}.d2h-info{background-color:#f8fafd;color:rgba(0,0,0,.3);border-color:#d5e4f2}
.d2h-wrapper{display:block;margin:0 auto;text-align:left;width:100%}.d2h-file-wrapper{border:1px solid #ddd;border-radius:3px;margin-bottom:1em}.d2h-file-header{padding:5px 10px;border-bottom:1px solid #d8d8d8;background-color:#f7f7f7;font:13px Helvetica,arial,freesans,clean,sans-serif,"Segoe UI Emoji","Segoe UI Symbol"}.d2h-file-stats{display:inline;font-size:12px;text-align:center;max-width:15%}.d2h-lines-added{background-color:#ceffce;border:1px solid #b4e2b4;color:#399839;border-radius:5px 0 0 5px;padding:2px;width:25px}.d2h-lines-deleted{background-color:#f7c8c8;border:1px solid #e9aeae;color:#c33;border-radius:0 5px 5px 0;padding:2px;width:25px}.d2h-file-name{display:inline;height:33px;line-height:33px;max-width:80%;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}.d2h-diff-table{border-collapse:collapse;font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;height:18px;line-height:18px;width:100%}.d2h-files-diff{width:100%}.d2h-file-diff{overflow-x:scroll}.d2h-file-side-diff{display:inline-block;overflow-x:scroll;width:50%;margin-right:-4px}.d2h-code-line{white-space:pre;padding-left:10px;padding-right:10px;height:18px;line-height:18px;margin-left:80px}.d2h-code-side-line{white-space:pre;padding-left:10px;padding-right:10px;height:18px;line-height:18px;margin-left:50px}.d2h-code-line del,.d2h-code-side-line del{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#ffb6ba;font-weight:700;border-radius:.2em}.d2h-code-line ins,.d2h-code-side-line ins{display:inline-block;margin-top:-1px;text-decoration:none;background-color:#97f295;font-weight:700;border-radius:.2em}.line-num1{display:inline-block;float:left;width:30px;overflow:hidden;text-overflow:ellipsis}.line-num2{display:inline-block;float:right;width:30px;overflow:hidden;text-overflow:ellipsis}.d2h-code-linenumber{position:absolute;width:2%;min-width:65px;padding-left:10px;padding-right:10px;height:18px;line-height:18px;background-color:#fff;color:rgba(0,0,0,.3);text-align:right;border:solid #eee;border-width:0 1px;cursor:pointer}.d2h-code-side-linenumber{position:absolute;width:35px;padding-left:10px;padding-right:10px;height:18px;line-height:18px;background-color:#fff;color:rgba(0,0,0,.3);text-align:right;border:solid #eee;border-width:0 1px;cursor:pointer;overflow:hidden;text-overflow:ellipsis}.d2h-del{background-color:#fee8e9;border-color:#e9aeae}.d2h-ins{background-color:#dfd;border-color:#b4e2b4}.d2h-info{background-color:#f8fafd;color:rgba(0,0,0,.3);border-color:#d5e4f2}

2
diff2html.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -8,59 +8,174 @@
Diff to HTML (template.html)
Author: rtfpessoa
Date: Friday 29 August 2014
Last Update: Sunday 14 September 2014
Last Update: Saturday 27 September 2014
-->
<!--<link rel="stylesheet" type="text/css" href="diff2html.css">-->
<link rel="stylesheet" type="text/css" href="diff2html.min.css">
<link rel="stylesheet" type="text/css" href="diff2html.css">
<!--<script type="text/javascript" src="diff2html.js"></script>-->
<script type="text/javascript" src="diff2html.min.js"></script>
<script type="text/javascript" src="jsdiff.js"></script>
<script type="text/javascript" src="diff2html.js"></script>
<script>
var exInput = 'diff --git a/src/app/language/en.json b/src/app/language/en.json\n' +
'index ccf92c9..68b8345 100644\n' +
'--- a/src/app/language/en.json\n' +
'+++ b/src/app/language/en.json\n' +
'@@ -270,5 +270,6 @@\n' +
' "Open Item Details": "Open Item Details",\n' +
' "Add Item to Favorites": "Add Item to Favorites",\n' +
' "Mark as Seen": "Mark as Seen",\n' +
' "Open Settings": "Open Settings"{+,+}\n' +
'{+ "Custom...": "Custom..."+}\n' +
'}\n' +
'diff --git a/src/app/language/fr.json b/src/app/language/fr.json\n' +
'index 9c773c5..8fb637a 100644\n' +
'--- a/src/app/language/fr.json\n' +
'+++ b/src/app/language/fr.json\n' +
'@@ -266,5 +266,6 @@\n' +
' "Add Item to Favorites": "Ajouter aux favoris",\n' +
' "Mark as Seen": "Marquer comme vu",\n' +
' "Open this screen": "Afficher cette page",\n' +
' "Open Settings": "Ouvrir les Réglages"{+,+}\n' +
'{+ "Custom...": "Ajouter un fichier..."+}\n' +
'}\n' +
'diff --git a/src/app/vendor/videojsplugins.js b/src/app/vendor/videojsplugins.js\n' +
'index 10856e3..892b7ca 100644\n' +
'--- a/src/app/vendor/videojsplugins.js\n' +
'+++ b/src/app/vendor/videojsplugins.js\n' +
'@@ -83,7 +83,7 @@ videojs.plugin(\'customSubtitles\', function() {\n' +
' options[\'track\'] = {\n' +
' kind: function() { return \'subtitles\'; },\n' +
' player: player,\n' +
' label: function(){ return [-\'-]{+i18n.__("+}Custom...[-\'-]{+")+} },\n' +
' dflt: function(){ return false; },\n' +
' mode: function(){ return false; }\n' +
var lineDiffExample = 'diff --git a/src/attributes/attr.js b/src/attributes/attr.js\n' +
'index facdd41..b627fe8 100644\n' +
'--- a/src/attributes/attr.js\n' +
'+++ b/src/attributes/attr.js\n' +
'@@ -1,11 +1,10 @@\n' +
' define([\n' +
' "../core",\n' +
' "../var/rnotwhite",\n' +
'- "../var/strundefined",\n' +
' "../core/access",\n' +
' "./support",\n' +
' "../selector"\n' +
'-], function( jQuery, rnotwhite, strundefined, access, support ) {\n' +
'+], function( jQuery, rnotwhite, access, support ) {\n' +
' \n' +
' var nodeHook, boolHook,\n' +
' attrHandle = jQuery.expr.attrHandle;\n' +
'@@ -33,7 +32,7 @@ jQuery.extend({\n' +
' }\n' +
' \n' +
' // Fallback to prop when attributes are not supported\n' +
'- if ( typeof elem.getAttribute === strundefined ) {\n' +
'+ if ( !elem.getAttribute ) {\n' +
' return jQuery.prop( elem, name, value );\n' +
' }\n' +
' \n' +
'diff --git a/src/attributes/classes.js b/src/attributes/classes.js\n' +
'index c617824..c8d1393 100644\n' +
'--- a/src/attributes/classes.js\n' +
'+++ b/src/attributes/classes.js\n' +
'@@ -1,10 +1,9 @@\n' +
' define([\n' +
' "../core",\n' +
' "../var/rnotwhite",\n' +
'- "../var/strundefined",\n' +
' "../data/var/dataPriv",\n' +
' "../core/init"\n' +
'-], function( jQuery, rnotwhite, strundefined, dataPriv ) {\n' +
'+], function( jQuery, rnotwhite, dataPriv ) {\n' +
' \n' +
' var rclass = /[\t\r\n\f]/g;\n' +
' \n' +
'@@ -128,7 +127,7 @@ jQuery.fn.extend({\n' +
' }\n' +
' \n' +
' // Toggle whole class name\n' +
'- } else if ( type === strundefined || type === "boolean" ) {\n' +
'+ } else if ( value === undefined || type === "boolean" ) {\n' +
' if ( this.className ) {\n' +
' // store className if set\n' +
' dataPriv.set( this, "__className__", this.className );\n' +
'diff --git a/src/core/init.js b/src/core/init.js\n' +
'index e49196a..50f310c 100644\n' +
'--- a/src/core/init.js\n' +
'+++ b/src/core/init.js\n' +
'@@ -101,7 +101,7 @@ var rootjQuery,\n' +
' // HANDLE: $(function)\n' +
' // Shortcut for document ready\n' +
' } else if ( jQuery.isFunction( selector ) ) {\n' +
'- return typeof rootjQuery.ready !== "undefined" ?\n' +
'+ return rootjQuery.ready !== undefined ?\n' +
' rootjQuery.ready( selector ) :\n' +
' // Execute immediately if ready is not present\n' +
' selector( jQuery );\n' +
'diff --git a/src/event.js b/src/event.js\n' +
'index 7336f4d..6183f70 100644\n' +
'--- a/src/event.js\n' +
'+++ b/src/event.js\n' +
'@@ -1,6 +1,5 @@\n' +
' define([\n' +
' "./core",\n' +
'- "./var/strundefined",\n' +
' "./var/rnotwhite",\n' +
' "./var/hasOwn",\n' +
' "./var/slice",\n' +
'@@ -10,7 +9,7 @@ define([\n' +
' "./core/init",\n' +
' "./data/accepts",\n' +
' "./selector"\n' +
'-], function( jQuery, strundefined, rnotwhite, hasOwn, slice, support, dataPriv ) {\n' +
'+], function( jQuery, rnotwhite, hasOwn, slice, support, dataPriv ) {\n' +
' \n' +
' var\n' +
' rkeyEvent = /^key/,\n' +
'@@ -72,7 +71,7 @@ jQuery.event = {\n' +
' eventHandle = elemData.handle = function( e ) {\n' +
' // Discard the second event of a jQuery.event.trigger() and\n' +
' // when an event is called after a page has unloaded\n' +
'- return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?\n' +
'+ return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ?\n' +
' jQuery.event.dispatch.apply( elem, arguments ) : undefined;\n' +
' };\n' +
'@@ -107,7 +107,7 @@ videojs.plugin(\'customSubtitles\', function() {\n' +
'\n' +
' CustomTrackMenuItem.prototype.loadSubtitle = function(filePath) {\n' +
' // TODO Delete old track\n' +
' this.track = this.player_.addTextTrack(\'subtitles\', [-\'-]{+i18n.__("+}Custom...[-\'-]{+")+}, \'00\', { src: filePath });\n' +
' vjs.TextTrackMenuItem.prototype.onClick.call(this); // redirect to TextTrackMenuItem.onClick\n' +
' }\n';
' }\n' +
'diff --git a/src/exports/global.js b/src/exports/global.js\n' +
'index 6513287..1db4144 100644\n' +
'--- a/src/exports/global.js\n' +
'+++ b/src/exports/global.js\n' +
'@@ -1,7 +1,9 @@\n' +
' define([\n' +
'- "../core",\n' +
'- "../var/strundefined"\n' +
'-], function( jQuery, strundefined ) {\n' +
'+ "../core"\n' +
'+], function( jQuery ) {\n' +
'+\n' +
'+/* exported noGlobal */\n' +
'+/* global noGlobal: false */\n' +
' \n' +
' var\n' +
' // Map over jQuery in case of overwrite\n' +
'@@ -25,7 +27,7 @@ jQuery.noConflict = function( deep ) {\n' +
' // Expose jQuery and $ identifiers, even in AMD\n' +
' // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)\n' +
' // and CommonJS for browser emulators (#13566)\n' +
'-if ( typeof noGlobal === strundefined ) {\n' +
'+if ( !noGlobal ) {\n' +
' window.jQuery = window.$ = jQuery;\n' +
' }\n' +
' \n' +
'diff --git a/src/offset.js b/src/offset.js\n' +
'index cc6ffb4..fa51f18 100644\n' +
'--- a/src/offset.js\n' +
'+++ b/src/offset.js\n' +
'@@ -1,6 +1,5 @@\n' +
' define([\n' +
' "./core",\n' +
'- "./var/strundefined",\n' +
' "./core/access",\n' +
' "./css/var/rnumnonpx",\n' +
' "./css/curCSS",\n' +
'@@ -10,7 +9,7 @@ define([\n' +
' "./core/init",\n' +
' "./css",\n' +
' "./selector" // contains\n' +
'-], function( jQuery, strundefined, access, rnumnonpx, curCSS, addGetHookIf, support ) {\n' +
'+], function( jQuery, access, rnumnonpx, curCSS, addGetHookIf, support ) {\n' +
' \n' +
' var docElem = window.document.documentElement;\n' +
' \n' +
'@@ -99,7 +98,7 @@ jQuery.fn.extend({\n' +
' \n' +
' // Support: BlackBerry 5, iOS 3 (original iPhone)\n' +
' // If we dont have gBCR, just use 0,0 rather than error\n' +
'- if ( typeof elem.getBoundingClientRect !== strundefined ) {\n' +
'+ if ( elem.getBoundingClientRect !== undefined ) {\n' +
' box = elem.getBoundingClientRect();\n' +
' }\n' +
' win = getWindow( doc );\n' +
'diff --git a/src/var/strundefined.js b/src/var/strundefined.js\n' +
'deleted file mode 100644\n' +
'index 04e16b0..0000000\n' +
'--- a/src/var/strundefined.js\n' +
'+++ /dev/null\n' +
'@@ -1,3 +0,0 @@\n' +
'-define(function() {\n' +
'- return typeof undefined;\n' +
'-});\n';
document.onreadystatechange = function () {
var diffJson = Diff2Html.getJsonFromDiff(exInput);
var diffJson = Diff2Html.getJsonFromDiff(lineDiffExample);
var lineByLineDiffHtml = Diff2Html.getPrettyHtmlFromJson(diffJson);
document.getElementById('line-by-line').innerHTML = lineByLineDiffHtml;
var sideBySideDiffHtml = Diff2Html.getPrettySideBySideHtmlFromJson(diffJson);

98
jsdiff.js Normal file
View file

@ -0,0 +1,98 @@
/*
* Javascript Diff Algorithm
* By John Resig (http://ejohn.org/)
* Modified by Chu Alan "sprite"
* Modified by Rodrigo Fernandes (rtfpessoa)
*
* Released under the MIT license.
*
* More Info:
* http://ejohn.org/projects/javascript-diff-algorithm/
*/
function escape(s) {
var n = s;
n = n.replace(/&/g, "&amp;");
n = n.replace(/</g, "&lt;");
n = n.replace(/>/g, "&gt;");
n = n.replace(/"/g, "&quot;");
return n;
}
function diffString(o, n) {
o = o.replace(/\s+$/, '');
n = n.replace(/\s+$/, '');
var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/));
var str = "";
if (out.n.length == 0) {
for (var i = 0; i < out.o.length; i++) {
str += '<del>' + escape(out.o[i]) + "</del>";
}
} else {
if (out.n[0].text == null) {
for (n = 0; n < out.o.length && out.o[n].text == null; n++) {
str += '<del>' + escape(out.o[n]) + "</del>";
}
}
for (var i = 0; i < out.n.length; i++) {
if (out.n[i].text == null) {
str += '<ins>' + escape(out.n[i]) + "</ins>";
} else {
var pre = "";
for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++) {
pre += '<del>' + escape(out.o[n]) + "</del>";
}
str += " " + out.n[i].text + pre;
}
}
}
return str;
}
function diff(o, n) {
var ns = new Object();
var os = new Object();
for (var i = 0; i < n.length; i++) {
if (ns[ n[i] ] == null)
ns[ n[i] ] = { rows: new Array(), o: null };
ns[ n[i] ].rows.push(i);
}
for (var i = 0; i < o.length; i++) {
if (os[ o[i] ] == null)
os[ o[i] ] = { rows: new Array(), n: null };
os[ o[i] ].rows.push(i);
}
for (var i in ns) {
if (ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1) {
n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] };
o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] };
}
}
for (var i = 0; i < n.length - 1; i++) {
if (n[i].text != null && n[i + 1].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null &&
n[i + 1] == o[ n[i].row + 1 ]) {
n[i + 1] = { text: n[i + 1], row: n[i].row + 1 };
o[n[i].row + 1] = { text: o[n[i].row + 1], row: i + 1 };
}
}
for (var i = n.length - 1; i > 0; i--) {
if (n[i].text != null && n[i - 1].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null &&
n[i - 1] == o[ n[i].row - 1 ]) {
n[i - 1] = { text: n[i - 1], row: n[i].row - 1 };
o[n[i].row - 1] = { text: o[n[i].row - 1], row: i - 1 };
}
}
return { o: o, n: n };
}