-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
62 lines (55 loc) · 2.16 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="Author" content="Toni Helminen [email protected]" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<title>Try sacrifice</title>
<script src="sacrifice.js"></script>
<script src="unittests.js"></script>
</head>
<body>
<div class="container">
<h1>Try sacrifice</h1>
<form action="#">
<div class="form-group"><label for="equation">Input</label><textarea class="form-control" rows="5" name="json" id="idInput" rows="3"></textarea></div>
<input type="submit" value="Validate" onclick="return validateCallback()" />
<input type="submit" value="Trim" onclick="return trimCallback()" />
</form>
<div class="p-2"><b class="h2" id="answer"></b></div>
<div class="footer-copyright text-center py-3">© 2020 Copyright: <a href="https://github.com/SamuraiDangyo/">SamuraiDangyo</a></div>
</div>
<script>
let validateCallback = 0, trimCallback = 0;
(function(){
function validJSON() {
const elem = document.getElementById("answer");
elem.classList.remove("text-danger");
elem.classList.add("text-success");
elem.innerHTML = "Valid JSON";
}
function invalidJSON() {
const elem = document.getElementById("answer");
elem.classList.remove("text-success");
elem.classList.add("text-danger");
elem.innerHTML = sacrifice.errorMsg;
}
validateCallback = function() {
if (sacrifice.validate(document.getElementById("idInput").value)) validJSON(); else invalidJSON();
return false;
};
trimCallback = function() {
const elem = document.getElementById("idInput"), value = elem.value;
if (!sacrifice.validate(value)) {invalidJSON(); return false;}
validJSON();
elem.value = sacrifice.trim(value);
return false;
};
sacrifice.unittests(); // Do unittests anyway
})();
</script>
</body>
</html>