/
scripts.js
97 lines (77 loc) · 2.48 KB
/
scripts.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function onPageLoad() {
}
function generateQuery() {
var nodeKind = document.getElementById("nodeKind").value;
var openCurlyOnNewLine = getCheckboxValue("openCurlyOnNewLine");
var closeCurlyOnNewLine = getCheckboxValue("closeCurlyOnNewLine");
var preserveOriginalWhitespace = getCheckboxValue("preserveOriginalWhitespace");
var keepRedundantApiCalls = getCheckboxValue("keepRedundantApiCalls");
var avoidUsingStatic = getCheckboxValue("avoidUsingStatic");
var query = "api/quoter/?sourceText=" + encodeURIComponent(inputBox.value);
query = query + "&nodeKind=" + nodeKind;
if (openCurlyOnNewLine) {
query = query + "&openCurlyOnNewLine=true";
}
if (closeCurlyOnNewLine) {
query = query + "&closeCurlyOnNewLine=true";
}
if (preserveOriginalWhitespace) {
query = query + "&preserveOriginalWhitespace=true";
}
if (keepRedundantApiCalls) {
query = query + "&keepRedundantApiCalls=true";
}
if (avoidUsingStatic) {
query = query + "&avoidUsingStatic=true";
}
return query;
}
function onSubmitClick() {
var query = generateQuery();
getUrl(query, loadResults);
}
function onSubmitLINQPad() {
var query = generateQuery();
query = query + "&generateLINQPad=true";
window.location = query;
}
function getCheckboxValue(id) {
return document.getElementById(id).checked;
}
function getUrl(url, callback) {
enableSubmit(false);
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader("Accept", "text/html");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
var data = xhr.responseText;
if (typeof data === "string" && data.length > 0) {
callback(data);
}
}
enableSubmit(true);
};
xhr.send();
return xhr;
}
function enableSubmit(enabled) {
var submitButton = document.getElementById("submitButton");
submitButton.disabled = !enabled;
var working = document.getElementById("working");
if (enabled) {
working.style.display = "none";
} else {
working.style.display = "inline";
setResult("");
}
}
function setResult(data) {
var container = document.getElementById("outputDiv");
if (container) {
container.innerHTML = data;
}
}
function loadResults(data) {
setResult(data);
}