Reformated jsonFormatter.js

This commit is contained in:
2023-05-15 11:58:05 +02:00
parent 18d9e654d2
commit cad01a4285

View File

@@ -161,21 +161,6 @@ const mergeHTMLPlugin = (function () {
}()); }());
/**
* This function is executed after the page is loaded.
*
* @function
* @name init
* @kind function
*/
function init() {
// Make sure that only plain text is pasted
configurePastingInElement("jsonBlock");
hljs.addPlugin(mergeHTMLPlugin);
}
function formatAndValidateJson(errorElement) { function formatAndValidateJson(errorElement) {
const input = document.querySelector('#jsonBlock'); const input = document.querySelector('#jsonBlock');
const processInfo = document.getElementById(errorElement); const processInfo = document.getElementById(errorElement);
@@ -205,9 +190,9 @@ function formatAndValidateJson(errorElement) {
processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>"; processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>";
console.error('Error:', error); console.error('Error:', error);
}); });
} }
function minimizeJson(errorElement) { function minimizeJson(errorElement) {
const input = document.querySelector('#jsonBlock'); const input = document.querySelector('#jsonBlock');
const processInfo = document.getElementById(errorElement); const processInfo = document.getElementById(errorElement);
@@ -236,15 +221,30 @@ function formatAndValidateJson(errorElement) {
processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>"; processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>";
console.error('Error:', error); console.error('Error:', error);
}); });
} }
function clearJsonData() { function clearJsonData() {
const input = document.querySelector('#jsonBlock'); const input = document.querySelector('#jsonBlock');
input.textContent = ""; input.textContent = "";
} }
function insertDefaultJson() { function insertDefaultJson() {
const input = document.querySelector('#jsonBlock'); const input = document.querySelector('#jsonBlock');
input.textContent = "{\"enter\": \"your\", \"json\": \"here\"}"; input.textContent = "{\"enter\": \"your\", \"json\": \"here\"}";
hljs.highlightElement(input); hljs.highlightElement(input);
} }
/**
* This function is executed after the page is loaded.
*
* @function
* @name init
* @kind function
*/
function init() {
// Make sure that only plain text is pasted
configurePastingInElement("jsonBlock");
hljs.addPlugin(mergeHTMLPlugin);
}