parent
87726e0bb2
commit
427cf105a3
@ -1,112 +1,110 @@
|
|||||||
var a = document.getElementById('a');
|
var a = document.getElementById("a");
|
||||||
var b = document.getElementById('b');
|
var b = document.getElementById("b");
|
||||||
var result = document.getElementById('result');
|
var result = document.getElementById("result");
|
||||||
|
|
||||||
function changed() {
|
function changed() {
|
||||||
// https://github.com/kpdecker/jsdiff/issues/389
|
// https://github.com/kpdecker/jsdiff/issues/389
|
||||||
// I would love to use `{ignoreWhitespace: true}` here but it breaks the formatting
|
// I would love to use `{ignoreWhitespace: true}` here but it breaks the formatting
|
||||||
options = {ignoreWhitespace: document.getElementById('ignoreWhitespace').checked};
|
options = {
|
||||||
|
ignoreWhitespace: document.getElementById("ignoreWhitespace").checked,
|
||||||
var diff = Diff[window.diffType](a.textContent, b.textContent, options);
|
};
|
||||||
var fragment = document.createDocumentFragment();
|
|
||||||
for (var i = 0; i < diff.length; i++) {
|
var diff = Diff[window.diffType](a.textContent, b.textContent, options);
|
||||||
|
var fragment = document.createDocumentFragment();
|
||||||
if (diff[i].added && diff[i + 1] && diff[i + 1].removed) {
|
for (var i = 0; i < diff.length; i++) {
|
||||||
var swap = diff[i];
|
if (diff[i].added && diff[i + 1] && diff[i + 1].removed) {
|
||||||
diff[i] = diff[i + 1];
|
var swap = diff[i];
|
||||||
diff[i + 1] = swap;
|
diff[i] = diff[i + 1];
|
||||||
}
|
diff[i + 1] = swap;
|
||||||
|
|
||||||
var node;
|
|
||||||
if (diff[i].removed) {
|
|
||||||
node = document.createElement('del');
|
|
||||||
node.classList.add("change");
|
|
||||||
node.appendChild(document.createTextNode(diff[i].value));
|
|
||||||
|
|
||||||
} else if (diff[i].added) {
|
|
||||||
node = document.createElement('ins');
|
|
||||||
node.classList.add("change");
|
|
||||||
node.appendChild(document.createTextNode(diff[i].value));
|
|
||||||
} else {
|
|
||||||
node = document.createTextNode(diff[i].value);
|
|
||||||
}
|
|
||||||
fragment.appendChild(node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.textContent = '';
|
var node;
|
||||||
result.appendChild(fragment);
|
if (diff[i].removed) {
|
||||||
|
node = document.createElement("del");
|
||||||
|
node.classList.add("change");
|
||||||
|
const wrapper = node.appendChild(document.createElement("span"));
|
||||||
|
wrapper.appendChild(document.createTextNode(diff[i].value));
|
||||||
|
} else if (diff[i].added) {
|
||||||
|
node = document.createElement("ins");
|
||||||
|
node.classList.add("change");
|
||||||
|
const wrapper = node.appendChild(document.createElement("span"));
|
||||||
|
wrapper.appendChild(document.createTextNode(diff[i].value));
|
||||||
|
} else {
|
||||||
|
node = document.createTextNode(diff[i].value);
|
||||||
|
}
|
||||||
|
fragment.appendChild(node);
|
||||||
|
}
|
||||||
|
|
||||||
// Jump at start
|
result.textContent = "";
|
||||||
inputs.current = 0;
|
result.appendChild(fragment);
|
||||||
next_diff();
|
|
||||||
|
// Jump at start
|
||||||
|
inputs.current = 0;
|
||||||
|
next_diff();
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
|
/* Convert what is options from UTC time.time() to local browser time */
|
||||||
|
var diffList = document.getElementById("diff-version");
|
||||||
/* Convert what is options from UTC time.time() to local browser time */
|
if (typeof diffList != "undefined" && diffList != null) {
|
||||||
var diffList = document.getElementById("diff-version");
|
for (var option of diffList.options) {
|
||||||
if (typeof (diffList) != 'undefined' && diffList != null) {
|
var dateObject = new Date(option.value * 1000);
|
||||||
for (var option of diffList.options) {
|
option.label = dateObject.toLocaleString();
|
||||||
var dateObject = new Date(option.value * 1000);
|
|
||||||
option.label = dateObject.toLocaleString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/* Set current version date as local time in the browser also */
|
|
||||||
var current_v = document.getElementById("current-v-date");
|
/* Set current version date as local time in the browser also */
|
||||||
var dateObject = new Date(newest_version_timestamp*1000);
|
var current_v = document.getElementById("current-v-date");
|
||||||
current_v.innerHTML = dateObject.toLocaleString();
|
var dateObject = new Date(newest_version_timestamp * 1000);
|
||||||
onDiffTypeChange(document.querySelector('#settings [name="diff_type"]:checked'));
|
current_v.innerHTML = dateObject.toLocaleString();
|
||||||
changed();
|
onDiffTypeChange(
|
||||||
|
document.querySelector('#settings [name="diff_type"]:checked'),
|
||||||
|
);
|
||||||
|
changed();
|
||||||
};
|
};
|
||||||
|
|
||||||
a.onpaste = a.onchange =
|
a.onpaste = a.onchange = b.onpaste = b.onchange = changed;
|
||||||
b.onpaste = b.onchange = changed;
|
|
||||||
|
|
||||||
if ('oninput' in a) {
|
if ("oninput" in a) {
|
||||||
a.oninput = b.oninput = changed;
|
a.oninput = b.oninput = changed;
|
||||||
} else {
|
} else {
|
||||||
a.onkeyup = b.onkeyup = changed;
|
a.onkeyup = b.onkeyup = changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDiffTypeChange(radio) {
|
function onDiffTypeChange(radio) {
|
||||||
window.diffType = radio.value;
|
window.diffType = radio.value;
|
||||||
// Not necessary
|
// Not necessary
|
||||||
// document.title = "Diff " + radio.value.slice(4);
|
// document.title = "Diff " + radio.value.slice(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
var radio = document.getElementsByName('diff_type');
|
var radio = document.getElementsByName("diff_type");
|
||||||
for (var i = 0; i < radio.length; i++) {
|
for (var i = 0; i < radio.length; i++) {
|
||||||
radio[i].onchange = function (e) {
|
radio[i].onchange = function (e) {
|
||||||
onDiffTypeChange(e.target);
|
onDiffTypeChange(e.target);
|
||||||
changed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('ignoreWhitespace').onchange = function (e) {
|
|
||||||
changed();
|
changed();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.getElementById("ignoreWhitespace").onchange = function (e) {
|
||||||
|
changed();
|
||||||
|
};
|
||||||
|
|
||||||
var inputs = document.getElementsByClassName('change');
|
var inputs = document.getElementsByClassName("change");
|
||||||
inputs.current = 0;
|
inputs.current = 0;
|
||||||
|
|
||||||
|
|
||||||
function next_diff() {
|
function next_diff() {
|
||||||
|
var element = inputs[inputs.current];
|
||||||
var element = inputs[inputs.current];
|
var headerOffset = 80;
|
||||||
var headerOffset = 80;
|
var elementPosition = element.getBoundingClientRect().top;
|
||||||
var elementPosition = element.getBoundingClientRect().top;
|
var offsetPosition = elementPosition - headerOffset + window.scrollY;
|
||||||
var offsetPosition = elementPosition - headerOffset + window.scrollY;
|
|
||||||
|
window.scrollTo({
|
||||||
window.scrollTo({
|
top: offsetPosition,
|
||||||
top: offsetPosition,
|
behavior: "smooth",
|
||||||
behavior: "smooth"
|
});
|
||||||
});
|
|
||||||
|
inputs.current++;
|
||||||
inputs.current++;
|
if (inputs.current >= inputs.length) {
|
||||||
if (inputs.current >= inputs.length) {
|
inputs.current = 0;
|
||||||
inputs.current = 0;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Toggles theme between light and dark mode.
|
||||||
|
*/
|
||||||
|
$(document).ready(function () {
|
||||||
|
const url = "/toggle-theme";
|
||||||
|
|
||||||
|
const button = document.getElementsByClassName("toggle-theme")[0];
|
||||||
|
|
||||||
|
button.onclick = () => {
|
||||||
|
fetch(url)
|
||||||
|
.then(function () {
|
||||||
|
const htmlElement = document.getElementsByTagName("html");
|
||||||
|
const isDarkMode = htmlElement[0].dataset.darkmode === "true";
|
||||||
|
htmlElement[0].dataset.darkmode = !isDarkMode;
|
||||||
|
if (isDarkMode) {
|
||||||
|
button.classList.remove("dark");
|
||||||
|
} else {
|
||||||
|
button.classList.add("dark");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(function (e) {
|
||||||
|
console.log("Can't toggle the theme. Error was: ", e);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
Loading…
Reference in new issue