forked from mrdoob/glsl-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added jsdifflib to show the difference between versions.
- Loading branch information
Showing
6 changed files
with
846 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/*** | ||
This is part of jsdifflib v1.0. <https://github.com/cemerick/jsdifflib> | ||
Copyright (c) 2007, Snowtide Informatics Systems, Inc. | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
* Neither the name of the Snowtide Informatics Systems nor the names of its | ||
contributors may be used to endorse or promote products derived from this | ||
software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY | ||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT | ||
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | ||
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
DAMAGE. | ||
***/ | ||
/* Author: Chas Emerick <[email protected]> */ | ||
table.diff { | ||
border-collapse:collapse; | ||
border:1px solid darkgray | ||
} | ||
table.diff tbody { | ||
font-family:Courier, monospace | ||
} | ||
table.diff tbody th { | ||
font-family:verdana,arial,'Bitstream Vera Sans',helvetica,sans-serif; | ||
background:#EED; | ||
font-size:11px; | ||
font-weight:normal; | ||
border:1px solid #BBC; | ||
color:#886; | ||
padding:.3em .5em .1em 2em; | ||
text-align:right; | ||
vertical-align:top | ||
} | ||
table.diff thead { | ||
border-bottom:1px solid #BBC; | ||
background:#EFEFEF; | ||
font-family:Verdana | ||
} | ||
table.diff thead th.texttitle { | ||
text-align:left | ||
} | ||
table.diff tbody td { | ||
padding:0px .4em; | ||
padding-top:.4em; | ||
vertical-align:top; | ||
} | ||
table.diff .empty { | ||
background-color:#DDD; | ||
} | ||
table.diff .replace { | ||
background-color:#FD8 | ||
} | ||
table.diff .delete { | ||
background-color:#E99; | ||
} | ||
table.diff .skip { | ||
background-color:#EFEFEF; | ||
border:1px solid #AAA; | ||
border-right:1px solid #BBC; | ||
} | ||
table.diff .insert { | ||
background-color:#9E9 | ||
} | ||
table.diff th.author { | ||
text-align:right; | ||
border-top:1px solid #BBC; | ||
background:#EFEFEF | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> | ||
<title>GLSL Sandbox Diff</title> | ||
<link rel="stylesheet" type="text/css" href="css/diffview.css"/> | ||
<script type="text/javascript" src="js/difflib.js"></script> | ||
<script type="text/javascript" src="js/diffview.js"></script> | ||
<script type="text/javascript" src='js/jquery.js'></script> | ||
<style type="text/css"> | ||
body { | ||
font-size: 12px; | ||
font-family: Sans-Serif; | ||
} | ||
h2 { | ||
margin: 0.5em 0 0.1em; | ||
text-align: center; | ||
} | ||
label:hover { | ||
text-decoration: underline; | ||
} | ||
table.diff { | ||
white-space: pre-wrap; | ||
} | ||
.textInput { | ||
display: block; | ||
width: 49%; | ||
float: left; | ||
} | ||
.spacer { | ||
margin-left: 10px; | ||
} | ||
#diffOutput { | ||
width: 100%; | ||
} | ||
</style> | ||
|
||
<script type="text/javascript"> | ||
var leftSide = { id: '', code: '', name: '', parent: null, loaded: false }, | ||
rightSide = { id: '', code: '', name: '', parent: null, loaded: false }, | ||
viewTypes = { sideBySide: 0, viewInline: 1 }; | ||
|
||
function showDiff(viewType) { | ||
var sm = new difflib.SequenceMatcher(leftSide.code, rightSide.code); | ||
var opcodes = sm.get_opcodes(); | ||
var diffoutputdiv = document.getElementById("diffoutput"); | ||
diffoutputdiv.innerHTML = ""; | ||
//var contextSize = document.getElementById("contextSize").value; | ||
contextSize = contextSize ? contextSize : null; | ||
diffoutputdiv.appendChild(diffview.buildView({ baseTextLines:leftSide.code, | ||
newTextLines:rightSide.code, | ||
opcodes:opcodes, | ||
baseTextName:leftSide.name, | ||
newTextName:rightSide.name, | ||
//contextSize:contextSize, | ||
viewType: viewType })); | ||
} | ||
|
||
function computeNames() { | ||
if (!leftSide.loaded) { | ||
leftSide.name = 'Not loaded'; | ||
} else if (rightSide.parent === leftSide.id) { | ||
leftSide.name = '<a href="e#' + leftSide.id + '">Parent effect ' + leftSide.id + '</a>'; | ||
} else { | ||
leftSide.name = '<a href="e#' + leftSide.id + '">Effect ' + leftSide.id + '</a>'; | ||
} | ||
|
||
if (!rightSide.loaded) { | ||
rightSide.name = 'Not loaded'; | ||
} else if (leftSide.parent === rightSide.id) { | ||
rightSide.name = '<a href="e#' + rightSide.id + '">Parent effect ' + rightSide.id + '</a>'; | ||
} else { | ||
rightSide.name = '<a href="e#' + rightSide.id + '">Effect ' + rightSide.id + '</a>'; | ||
} | ||
} | ||
|
||
function load_code(side) { | ||
$.getJSON('item/'+side.id, function(result) { | ||
side.code = result.code; | ||
side.parent = result.parent; | ||
side.loaded = true; | ||
if (leftSide.loaded && rightSide.loaded) { | ||
computeNames(); | ||
showDiff(viewTypes.sideBySide); | ||
} | ||
}).error(function (jqXHR, textStatus, errorThrown) { | ||
alert(textStatus); | ||
}); | ||
} | ||
|
||
function onHashChange() { | ||
// hash format: #a-vs-b | ||
var hash = window.location.hash, | ||
pos = hash.indexOf('-vs-'), | ||
newLeftID = null, | ||
newRightID = null; | ||
|
||
if ((pos < 2) || ((hash.length - pos) < 5)) { | ||
leftSide.loaded = rightSide.loaded = false; | ||
leftSide.name = rightSide.name = 'invalid'; | ||
leftSide.code = rightSide.code = 'invalid'; | ||
leftSide.parent = rightSide.parent = null; | ||
document.getElementById("diffoutput").innerHTML = "Invalid Diff URL."; | ||
} else { | ||
newLeftID = hash.substring(1, pos); | ||
newRightID = hash.substring(pos + 4); | ||
if (newLeftID !== leftSide.id) { | ||
leftSide.id = newLeftID; | ||
leftSide.name = 'Loading...'; | ||
leftSide.code = ''; | ||
leftSide.parent = null; | ||
leftSide.loaded = false; | ||
} | ||
if (newRightID !== rightSide.id) { | ||
rightSide.id = newRightID; | ||
rightSide.name = 'Loading...'; | ||
rightSide.code = ''; | ||
rightSide.parent = null; | ||
rightSide.loaded = false; | ||
} | ||
if (!(leftSide.loaded && rightSide.loaded)) { | ||
document.getElementById("diffoutput").innerHTML = "Loading..."; | ||
if (!leftSide.loaded) { | ||
load_code(leftSide); | ||
} | ||
if (!rightSide.loaded) { | ||
load_code(rightSide); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// on DOM ready | ||
$(function () { | ||
window.onhashchange = function { onHashChange(); }; | ||
onHashChange(); | ||
}); | ||
|
||
</script> | ||
</head> | ||
<body> | ||
<h1><a href="/">GLSL Sandbox</a> Diff</h1> | ||
<div> | ||
<input type="button" value="Side-by-side diff" onclick="showDiff(0);"/> | ||
| ||
<input type="button" value="Inline diff" onclick="showDiff(1);"/> | ||
</div> | ||
<div id="diffoutput">Loading...</div> | ||
</body> | ||
</html> |
Oops, something went wrong.