mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 22:15:51 +01:00
Move duplicated JavaScript and CSS for diff to common files
This commit is contained in:
@@ -81,56 +81,7 @@
|
||||
<script type="text/javascript" src="@assets/jsdifflib/difflib.js"></script>
|
||||
<script type="text/javascript" src="@assets/jsdifflib/diffview.js"></script>
|
||||
<link href="@assets/jsdifflib/diffview.css" type="text/css" rel="stylesheet" />
|
||||
<style type="text/css">
|
||||
table.inlinediff {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.inlinediff thead {
|
||||
display: none;
|
||||
}
|
||||
|
||||
td.insert, td.equal, td.delete {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function diffUsingJS(oldTextId, newTextId, outputId) {
|
||||
// get the baseText and newText values from the two textboxes, and split them into lines
|
||||
var oldText = document.getElementById(oldTextId).value;
|
||||
if(oldText == ''){
|
||||
var oldLines = [];
|
||||
} else {
|
||||
var oldLines = difflib.stringAsLines(oldText);
|
||||
}
|
||||
|
||||
var newText = document.getElementById(newTextId).value
|
||||
if(newText == ''){
|
||||
var newLines = [];
|
||||
} else {
|
||||
var newLines = difflib.stringAsLines(newText);
|
||||
}
|
||||
|
||||
// create a SequenceMatcher instance that diffs the two sets of lines
|
||||
var sm = new difflib.SequenceMatcher(oldLines, newLines);
|
||||
|
||||
// get the opcodes from the SequenceMatcher instance
|
||||
// opcodes is a list of 3-tuples describing what changes should be made to the base text
|
||||
// in order to yield the new text
|
||||
var opcodes = sm.get_opcodes();
|
||||
var diffoutputdiv = document.getElementById(outputId);
|
||||
while (diffoutputdiv.firstChild) diffoutputdiv.removeChild(diffoutputdiv.firstChild);
|
||||
|
||||
// build the diff view and add it to the current DOM
|
||||
diffoutputdiv.appendChild(diffview.buildView({
|
||||
baseTextLines: oldLines,
|
||||
newTextLines: newLines,
|
||||
opcodes: opcodes,
|
||||
contextSize: 4,
|
||||
viewType: 1
|
||||
}));
|
||||
}
|
||||
|
||||
$(function(){
|
||||
@if(showIndex){
|
||||
$('#toggle-file-list').click(function(){
|
||||
|
||||
@@ -54,56 +54,7 @@
|
||||
<script type="text/javascript" src="@assets/jsdifflib/difflib.js"></script>
|
||||
<script type="text/javascript" src="@assets/jsdifflib/diffview.js"></script>
|
||||
<link href="@assets/jsdifflib/diffview.css" type="text/css" rel="stylesheet" />
|
||||
<style type="text/css">
|
||||
table.inlinediff {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.inlinediff thead {
|
||||
display: none;
|
||||
}
|
||||
|
||||
td.insert, td.equal, td.delete {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function diffUsingJS(oldTextId, newTextId, outputId) {
|
||||
// get the baseText and newText values from the two textboxes, and split them into lines
|
||||
var oldText = document.getElementById(oldTextId).value;
|
||||
if(oldText == ''){
|
||||
var oldLines = [];
|
||||
} else {
|
||||
var oldLines = difflib.stringAsLines(oldText);
|
||||
}
|
||||
|
||||
var newText = document.getElementById(newTextId).value
|
||||
if(newText == ''){
|
||||
var newLines = [];
|
||||
} else {
|
||||
var newLines = difflib.stringAsLines(newText);
|
||||
}
|
||||
|
||||
// create a SequenceMatcher instance that diffs the two sets of lines
|
||||
var sm = new difflib.SequenceMatcher(oldLines, newLines);
|
||||
|
||||
// get the opcodes from the SequenceMatcher instance
|
||||
// opcodes is a list of 3-tuples describing what changes should be made to the base text
|
||||
// in order to yield the new text
|
||||
var opcodes = sm.get_opcodes();
|
||||
var diffoutputdiv = document.getElementById(outputId);
|
||||
while (diffoutputdiv.firstChild) diffoutputdiv.removeChild(diffoutputdiv.firstChild);
|
||||
|
||||
// build the diff view and add it to the current DOM
|
||||
diffoutputdiv.appendChild(diffview.buildView({
|
||||
baseTextLines: oldLines,
|
||||
newTextLines: newLines,
|
||||
opcodes: opcodes,
|
||||
contextSize: 4,
|
||||
viewType: 1
|
||||
}));
|
||||
}
|
||||
|
||||
$(function(){
|
||||
diffUsingJS('oldText', 'newText', 'diffText');
|
||||
});
|
||||
|
||||
@@ -712,6 +712,21 @@ a.absent {
|
||||
color: #c00;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/* Diff */
|
||||
/****************************************************************************/
|
||||
table.inlinediff {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table.inlinediff thead {
|
||||
display: none;
|
||||
}
|
||||
|
||||
td.insert, td.equal, td.delete {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/* Repository Settings */
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -66,4 +66,40 @@ function displayErrors(data){
|
||||
window.clearInterval(timer);
|
||||
});
|
||||
};
|
||||
})(jQuery);
|
||||
})(jQuery);
|
||||
|
||||
function diffUsingJS(oldTextId, newTextId, outputId) {
|
||||
// get the baseText and newText values from the two textboxes, and split them into lines
|
||||
var oldText = document.getElementById(oldTextId).value;
|
||||
if(oldText == ''){
|
||||
var oldLines = [];
|
||||
} else {
|
||||
var oldLines = difflib.stringAsLines(oldText);
|
||||
}
|
||||
|
||||
var newText = document.getElementById(newTextId).value
|
||||
if(newText == ''){
|
||||
var newLines = [];
|
||||
} else {
|
||||
var newLines = difflib.stringAsLines(newText);
|
||||
}
|
||||
|
||||
// create a SequenceMatcher instance that diffs the two sets of lines
|
||||
var sm = new difflib.SequenceMatcher(oldLines, newLines);
|
||||
|
||||
// get the opcodes from the SequenceMatcher instance
|
||||
// opcodes is a list of 3-tuples describing what changes should be made to the base text
|
||||
// in order to yield the new text
|
||||
var opcodes = sm.get_opcodes();
|
||||
var diffoutputdiv = document.getElementById(outputId);
|
||||
while (diffoutputdiv.firstChild) diffoutputdiv.removeChild(diffoutputdiv.firstChild);
|
||||
|
||||
// build the diff view and add it to the current DOM
|
||||
diffoutputdiv.appendChild(diffview.buildView({
|
||||
baseTextLines: oldLines,
|
||||
newTextLines: newLines,
|
||||
opcodes: opcodes,
|
||||
contextSize: 4,
|
||||
viewType: 1
|
||||
}));
|
||||
}
|
||||
Reference in New Issue
Block a user