You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
4.7 KiB
174 lines
4.7 KiB
4 years ago
|
{% extends 'base.html' %}
|
||
|
|
||
|
{% block content %}
|
||
|
|
||
4 years ago
|
<div id="settings">
|
||
|
<h1>Differences</h1>
|
||
|
<form class="pure-form " action="" method="GET">
|
||
|
<fieldset>
|
||
|
|
||
|
<label for="diffWords" class="pure-checkbox">
|
||
4 years ago
|
<input type="radio" name="diff_type" id="diffWords" value="diffWords"/> Words</label>
|
||
4 years ago
|
<label for="diffLines" class="pure-checkbox">
|
||
4 years ago
|
<input type="radio" name="diff_type" id="diffLines" value="diffLines" checked=""/> Lines</label>
|
||
4 years ago
|
|
||
|
<label for="diffChars" class="pure-checkbox">
|
||
|
<input type="radio" name="diff_type" id="diffChars" value="diffChars"/> Chars</label>
|
||
|
|
||
|
{% if versions|length >= 1 %}
|
||
4 years ago
|
<label for="diff-version">Compare newest (<span id="current-v-date"></span>) with</label>
|
||
4 years ago
|
<select id="diff-version" name="previous_version">
|
||
|
{% for version in versions %}
|
||
4 years ago
|
<option value="{{version}}" {% if version== current_previous_version %} selected="" {% endif %}>
|
||
|
{{version}}
|
||
|
</option>
|
||
4 years ago
|
{% endfor %}
|
||
|
</select>
|
||
|
<button type="submit" class="pure-button pure-button-primary">Go</button>
|
||
|
{% endif %}
|
||
|
</fieldset>
|
||
|
</form>
|
||
4 years ago
|
<del>Removed text</del>
|
||
|
<ins>Inserted Text</ins>
|
||
|
</div>
|
||
|
|
||
4 years ago
|
<div id="diff-jump">
|
||
|
<a onclick="next_diff();">Jump</a>
|
||
|
</div>
|
||
4 years ago
|
<div id="diff-ui">
|
||
4 years ago
|
<table>
|
||
|
<tbody>
|
||
|
<tr>
|
||
4 years ago
|
<!-- just proof of concept copied straight from github.com/kpdecker/jsdiff -->
|
||
4 years ago
|
<td id="a" style="display: none;">{{previous}}</td>
|
||
|
<td id="b" style="display: none;">{{newest}}</td>
|
||
4 years ago
|
<td id="diff-col">
|
||
4 years ago
|
<span id="result"></span>
|
||
4 years ago
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
4 years ago
|
Diff algorithm from the amazing <a href="https://github.com/kpdecker/jsdiff">github.com/kpdecker/jsdiff</a>
|
||
|
|
||
4 years ago
|
</div>
|
||
|
|
||
3 years ago
|
|
||
|
<script type="text/javascript" src="{{url_for('static_content', group='js', filename='diff.js')}}"></script>
|
||
|
|
||
4 years ago
|
<script defer="">
|
||
4 years ago
|
|
||
|
|
||
4 years ago
|
var a = document.getElementById('a');
|
||
|
var b = document.getElementById('b');
|
||
|
var result = document.getElementById('result');
|
||
|
|
||
|
function changed() {
|
||
|
var diff = JsDiff[window.diffType](a.textContent, b.textContent);
|
||
|
var fragment = document.createDocumentFragment();
|
||
|
for (var i=0; i < diff.length; i++) {
|
||
|
|
||
|
if (diff[i].added && diff[i + 1] && diff[i + 1].removed) {
|
||
|
var swap = diff[i];
|
||
|
diff[i] = diff[i + 1];
|
||
|
diff[i + 1] = swap;
|
||
|
}
|
||
|
|
||
|
var node;
|
||
|
if (diff[i].removed) {
|
||
|
node = document.createElement('del');
|
||
4 years ago
|
node.classList.add("change");
|
||
4 years ago
|
node.appendChild(document.createTextNode(diff[i].value));
|
||
4 years ago
|
|
||
4 years ago
|
} else if (diff[i].added) {
|
||
|
node = document.createElement('ins');
|
||
4 years ago
|
node.classList.add("change");
|
||
4 years ago
|
node.appendChild(document.createTextNode(diff[i].value));
|
||
|
} else {
|
||
|
node = document.createTextNode(diff[i].value);
|
||
|
}
|
||
|
fragment.appendChild(node);
|
||
|
}
|
||
|
|
||
|
result.textContent = '';
|
||
|
result.appendChild(fragment);
|
||
4 years ago
|
|
||
|
// Jump at start
|
||
|
inputs.current=0;
|
||
|
next_diff();
|
||
4 years ago
|
}
|
||
|
|
||
|
window.onload = function() {
|
||
4 years ago
|
|
||
|
|
||
|
/* Convert what is options from UTC time.time() to local browser time */
|
||
|
var diffList=document.getElementById("diff-version");
|
||
|
if (typeof(diffList) != 'undefined' && diffList != null) {
|
||
|
for (var option of diffList.options) {
|
||
|
var dateObject = new Date(option.value*1000);
|
||
|
option.label=dateObject.toLocaleString();
|
||
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
/* Set current version date as local time in the browser also */
|
||
|
var current_v = document.getElementById("current-v-date");
|
||
|
var dateObject = new Date({{ newest_version_timestamp }}*1000);
|
||
|
current_v.innerHTML=dateObject.toLocaleString();
|
||
|
|
||
4 years ago
|
|
||
4 years ago
|
onDiffTypeChange(document.querySelector('#settings [name="diff_type"]:checked'));
|
||
|
changed();
|
||
4 years ago
|
|
||
4 years ago
|
};
|
||
|
|
||
|
a.onpaste = a.onchange =
|
||
|
b.onpaste = b.onchange = changed;
|
||
|
|
||
|
if ('oninput' in a) {
|
||
|
a.oninput = b.oninput = changed;
|
||
|
} else {
|
||
|
a.onkeyup = b.onkeyup = changed;
|
||
|
}
|
||
|
|
||
|
function onDiffTypeChange(radio) {
|
||
|
window.diffType = radio.value;
|
||
4 years ago
|
// Not necessary
|
||
|
// document.title = "Diff " + radio.value.slice(4);
|
||
4 years ago
|
}
|
||
|
|
||
|
var radio = document.getElementsByName('diff_type');
|
||
|
for (var i = 0; i < radio.length; i++) {
|
||
|
radio[i].onchange = function(e) {
|
||
|
onDiffTypeChange(e.target);
|
||
|
changed();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
4 years ago
|
var inputs = document.getElementsByClassName('change');
|
||
|
inputs.current=0;
|
||
4 years ago
|
|
||
4 years ago
|
|
||
|
function next_diff() {
|
||
|
|
||
|
var element = inputs[inputs.current];
|
||
|
var headerOffset = 80;
|
||
|
var elementPosition = element.getBoundingClientRect().top;
|
||
|
var offsetPosition = elementPosition - headerOffset + window.scrollY;
|
||
4 years ago
|
|
||
4 years ago
|
window.scrollTo({
|
||
|
top: offsetPosition,
|
||
|
behavior: "smooth"
|
||
|
});
|
||
|
|
||
|
inputs.current++;
|
||
|
if(inputs.current >= inputs.length) {
|
||
|
inputs.current=0;
|
||
|
}
|
||
|
}
|
||
4 years ago
|
|
||
|
|
||
4 years ago
|
|
||
4 years ago
|
</script>
|
||
|
|
||
4 years ago
|
|
||
|
{% endblock %}
|