-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.js
91 lines (84 loc) · 3.31 KB
/
index.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
function ValidateForm() {
var botPage = document.getElementById("botPage");
var botCat = document.getElementById("botCat");
var botLinked = document.getElementById("botLinked");
var submitButton; // From StackOverflow user3126867
if (typeof event.explicitOriginalTarget !== "undefined") {
submitButton = event.explicitOriginalTarget;
} else if(typeof document.activeElement.value !== "undefined"){ // IE
submitButton = document.activeElement;
}
if (submitButton.id === "PageSubmit") {
if (botPage.value.trim() === "") {
botPage.classList.add("error");
submitButton.disabled = "disabled";
return false;
}
document.getElementById("PageSpinner").style.display = "inline-block";
} else if (submitButton.id === "CatSubmit") {
if (botCat.value.trim() === "") {
botCat.classList.add("error");
submitButton.disabled = "disabled";
return false;
}
document.getElementById("CatSpinner").style.display = "inline-block";
} else if (submitButton.id === "LinkedSubmit") {
if (botLinked.value.trim() === "") {
botLinked.classList.add("error");
submitButton.disabled = "disabled";
return false;
}
document.getElementById("LinkSpinner").style.display = "inline-block";
}
document.getElementById("PageSubmit").disabled = "disabled";
document.getElementById("CatSubmit").disabled = "disabled";
document.getElementById("LinkedSubmit").disabled = "disabled";
return true;
}
function ValidatePageName() {
document.getElementById("PageSubmit").innerHTML = "Process page" +
((document.getElementById("botPage").value.indexOf("|") > -1) ? "s" : "");
if (this.value.trim() === "") {
this.classList.add("error");
document.getElementById("PageSubmit").disabled = "disabled";
} else {
this.classList.remove("error");
document.getElementById("PageSubmit").disabled = false;
}
}
function ValidateCategory() {
if (this.value.trim() === "") {
this.classList.add("error");
document.getElementById("CatSubmit").disabled = "disabled";
} else {
this.classList.remove("error");
document.getElementById("CatSubmit").disabled = false;
}
}
function ValidateLinked() {
if (this.value.trim() === "") {
this.classList.add("error");
document.getElementById("LinkedSubmit").disabled = "disabled";
} else {
this.classList.remove("error");
document.getElementById("LinkedSubmit").disabled = false;
}
}
function InitializeForm() {
document.getElementById("botForm").onsubmit = ValidateForm;
document.getElementById("botPage").oninput = ValidatePageName;
document.getElementById("botCat").oninput = ValidateCategory;
document.getElementById("botLinked").oninput= ValidateLinked;
document.getElementById("CatSubmit").disabled = false;
document.getElementById("PageSubmit").disabled = false;
document.getElementById("LinkedSubmit").disabled = false;
document.getElementById("PageSpinner").style.display = "none";
document.getElementById("CatSpinner").style.display = "none";
document.getElementById("LinkSpinner").style.display = "none";
document.getElementById("botPage").value = "";
document.getElementById("botCat").value = "";
document.getElementById("botLinked").value = "";
this.classList.remove("error");
}
window.onload = InitializeForm;
window.addEventListener('pageshow', InitializeForm);