-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
168 lines (140 loc) · 4.61 KB
/
Copy pathscript.js
File metadata and controls
168 lines (140 loc) · 4.61 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
"use strict"
var more = false;
//function use Enter key
window.onload = init;
function init() {
useEnterKeyboard();
displayTime();
setupStyle();
callLoginButton();
modifyDOM();
//3.
//create event for h2 Touchme
var clickMeDIV = document.getElementById("clickMe");
var clickMeH2 = document.createElement("h2");
var textMore = document.getElementById("textMore");
var clickMeText = document.createTextNode("Touch me!");
clickMeH2.addEventListener("click", function (e) {
var addr = document.getElementById("addr");
addr.classList.add("displayAddr");
});
clickMeH2.addEventListener("dblclick", function (e) {
var addr = document.getElementById("addr");
addr.classList.remove("displayAddr");
});
clickMeH2.appendChild(clickMeText);
clickMeDIV.appendChild(clickMeH2);
var styleMore = document.createElement("style");
styleMore.textContent =
'#textMore {\
background-color: rgba(68,94,186,0.6); \
color: blue; \
font-family: "Roboto Mono", monospace;}';
document.head.append(styleMore);
textMore.addEventListener("click", function (e) {
more = !more;
if (more == true) {
textMore.innerText = "less...";
modifyDOM();
}
else {
textMore.innerText = "more...";
resetDOM();
}
});
}
function useEnterKeyboard() {
var inputUsers = document.getElementsByClassName("inputUser");
for (var i = 0; i < 4; i++) {
const index = i;
if (i < 3) {
inputUsers[i].addEventListener("keyup", (e) =>{
if (e.keyCode === 13) {
inputUsers[index + 1].focus();
e.preventDefault();
}
});
}
else {
inputUsers[i].addEventListener("keyup", function (e) {
if (e.keyCode === 13) {
document.getElementById("login_button").click();
e.preventDefault();
}
});
}
}
}
function callLoginButton() {
var loginButton = document.getElementById("login_button");
loginButton.addEventListener("click", function (e) {
if (clientAcc() == 4) {
window.location.href = "boba_menu.html";
}
else {
alert("Please, fill out the form!")
}
});
}
function clientAcc() {
var fName = document.getElementById("fname");
var lName = document.getElementById("lname");
var phoneNum = document.getElementById("phoneNum");
var email = document.getElementById("email");
var fieldIndex = 0;
if (fName.value == "") {
fName.setCustomValidity("Please, Enter your first name");
}
else {
fieldIndex++;
}
if (lName.value == "") {
lName.setCustomValidity("Please, Enter your last name");
}
else {
fieldIndex++;
}
if (phoneNum.value == "") {
phoneNum.setCustomValidity("Please, Enter your phone number");
}
else {
fieldIndex++;
}
if (email.value == "") {
email.setCustomValidity("Please, Enter your email");
}
else {
fieldIndex++;
}
return fieldIndex;
}
// display time
function displayTime() {
var thisDate = new Date();
document.getElementById("currentTime").innerHTML = thisDate.toLocaleString();
setTimeout(displayTime, 1000);
}
//set up page view for boba_index.html
//setup style
function setupStyle() {
var pageStyle = document.createElement("link");
pageStyle.setAttribute("rel", "stylesheet");
pageStyle.setAttribute("href", "css/ss_insert.css");
document.head.append(pageStyle);
}
//11, 3, 12
function modifyDOM() {
var text = document.getElementById("text");
var textStr = "As pioneers in the Boba Tea industry,\
we have a track record of 26 years in research and development, \
just to bring you the best quality tea at the best price. Find the drink that will make your day today.";
text.textContent = textStr;
}
function resetDOM() {
var text = document.getElementById("text");
var textStr = "Brown sugar milk is the latest beverage trend to hit the bubble tea market and it has won hearts and palates from Singapore to Shanghai for its central ingredient — \
brown sugar caramel. While bubble tea used to be made traditionally with simple syrup from white sugar, brown sugar, \
when caramelised into a syrup, has toasty, nutty nuances that make the drink so delicious. \
If you can't get enough of this trendy drink, here's some good news for you.";
text.textContent = textStr;
}