-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidateHtml-render.js
More file actions
34 lines (34 loc) · 1.12 KB
/
validateHtml-render.js
File metadata and controls
34 lines (34 loc) · 1.12 KB
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
function(data) {
this.simplyData = data;
var element = this;
let htmlData = "<!doctype html><html lang='en'><head><title>Test</title></head><body>" + data + "</body></html>";
if (typeof element.validateTimeout !== "undefined") {
window.clearTimeout(element.validateTimeout);
}
element.validateTimeout = window.setTimeout(function() {
// fetch("https://validator.w3.org/nu/?out=json", {
fetch("http://localhost:8888/?out=json", {
mode : 'cors',
headers: {
"Content-type" : "text/html; charset=utf-8"
},
method: "POST",
body: htmlData
})
.then(function(result) {
return result.json();
})
.then(function(validateResult) {
element.dataBinding.config.data.validateResult = validateResult;
if(validateResult.messages.length) {
element.className = "simplycode-html-invalid";
element.innerHTML = "HTML validation failed:";
} else {
element.innerHTML = "HTML validated!";
element.className = "simplycode-html-valid";
}
});
}, 1000);
element.dataBinding.config.data.validateResult = {};
return "Validating...";
}