-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
153 lines (144 loc) · 3.92 KB
/
app.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
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
let data =
[
{
user: {
name: "Adam Sheehan",
avatar_url: "http://placekitten.com/g/50/50"
},
content: "Want to me to diagram that for you?",
liked: false,
comments: [
{
user: {
name: "Everyone Everywhere",
avatar_url: "http://placekitten.com/g/50/50"
},
content: "Yes!"
}
]
},
{
user: {
name: "Eric Kelly",
avatar_url: "http://placekitten.com/g/50/50"
},
content: "Everyone, please set up the preferences in Apollo for Sublime.",
liked: true,
comments: [
{
user: {
name: "Helen Hood",
avatar_url: "http://placekitten.com/g/50/50"
},
content: "Cats are awesome! Especially Mr. G."
}
]
},
{
user: {
name: "Helen Hood",
avatar_url: "http://placekitten.com/g/50/50"
},
content: "One day I will steal Mr. G!",
liked: false,
comments: [
{
user: {
name: "Eric Kelly",
avatar_url: "http://placekitten.com/g/50/50"
},
content: "NEVARRRR!"
}
]
},
{
user: {
name: "Sam McTaggart",
avatar_url: "http://placekitten.com/g/50/50"
},
content: "Objective C is incredible.",
liked: false,
comments: [
{
user: {
name: "Faizaan Shamsi",
avatar_url: "http://placekitten.com/g/50/50"
},
content: "Have you seen Ruby Motion?"
}
]
}
]
let items = document.getElementById('list-of-posts')
data.forEach(post => {
listItem = document.createElement('li')
items.appendChild(listItem)
div1 = document.createElement('div')
div1.className='media-img'
listItem.appendChild(div1)
img1 = document.createElement('img')
img1.id='avatar-url'
img1.src=`${post.user.avatar_url}`
div1.appendChild(img1)
div2 = document.createElement('div')
div2.className='media-body'
listItem.appendChild(div2)
h4 = document.createElement('h4')
h4.innerHTML=`${post.user.name}`
div2.appendChild(h4)
p1 = document.createElement('p')
p1.innerHTML=`${post.content}`
div2.appendChild(p1)
ul2 = document.createElement('ul')
ul2.className = "inline-list post-actions"
listItem.appendChild(ul2)
li1 = document.createElement('li')
a1 = document.createElement('a')
a1.href="#"
a1.innerHTML="Like"
li1.appendChild(a1)
ul2.appendChild(li1)
li2 = document.createElement('li')
a2 = document.createElement('a')
a2.href="#"
a2.innerHTML="Comment"
li2.appendChild(a2)
ul2.appendChild(li2)
li3 = document.createElement('li')
a3 = document.createElement('a')
a3.href="#"
a3.innerHTML="Share"
li3.appendChild(a3)
ul2.appendChild(li3)
})
//Code for address-form-launchbook goes here
let addressForm = document.mailingAddressForm
let firstName = document.getElementById("first-name")
let lastName = document.getElementById("last-name")
let address = document.getElementById("address")
let city = document.getElementById("city")
let state = document.getElementById("state")
let zipCode = document.getElementById("zip-code")
let phoneNum = document.getElementById("phone-number")
let email = document.getElementById("email")
let isValid = (field) => {
let paragraph = document.createElement('p')
let fieldName = field.name.replace(/([A-Z]+)/g, " $1")
let text = document.createTextNode(`- ${fieldName.toLowerCase()} cannot be blank`)
if (!field.value) {
paragraph.appendChild(text)
paragraph.classList.add("error")
addressForm.appendChild(paragraph)
}
}
addressForm.addEventListener("submit", (event) => {
event.preventDefault()
isValid(firstName)
isValid(lastName)
isValid(address)
isValid(city)
isValid(state)
isValid(zipCode)
isValid(phoneNum)
isValid(email)
})