-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
175 lines (134 loc) · 5.35 KB
/
script.js
File metadata and controls
175 lines (134 loc) · 5.35 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
165
166
167
168
169
170
171
172
173
174
175
// object structure
const arrayChannels = [
{
name: "Canal1",
content: [
{
author: "Thomas Anderson",
time: "13:00",
avatar: "img/avatar.jpg",
text:
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
},
{
author: "Thomas Anderson",
time: "13:00",
avatar: "img/avatar.jpg",
text:
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
},
{
author: "Thomas Anderson",
time: "13:00",
avatar: "img/avatar.jpg",
text:
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
},
],
},
{
name: "Canal2",
content: [
{
author: "Eliot Alderson",
time: "13:00",
avatar: "img/cowboy.png",
text:
"Fuck society",
},
{
author: "Thomas Anderson",
time: "13:00",
avatar: "img/cowboy.png",
text:
"El problema es la elección",
},
{
author: "Jhonny Mnemonic",
time: "13:00",
avatar: "img/cowboy.png",
text:
"I'm just a hard drive, man",
},
],
},
];
//_______ Cambiar por la variable del evento click________________
const nameChannel= "Canal2";
//optener el canal correcto para iterarlo en la función de imprimir mensaje
function getChannel(nameChannel){
return arrayChannels.find(function (channel){
return channel.name === nameChannel;
});
}
//variable que guarda el objeto completo del canal seleccionado
const channel = getChannel(nameChannel);
function printMessage (channel){
channel.content.forEach( function (message) {
//creación de elemento y asignación de atributos
const messageBox = document.createElement('div');
const messageMetaData = document.createElement('div');
const avatar = document.createElement('img')
const avatarImage = document.createElement('div');
const userName = document.createElement('div');
const timeStamp = document.createElement('div');
const userMessage = document.createElement('div');
const textMessage = document.createElement('p');
messageBox.className = "messageBox";
messageBox.appendChild(messageMetaData);
messageMetaData.className = "messageBox";
messageMetaData.appendChild(avatar);
avatar.src = message.avatar
messageMetaData.className = "messageMetaData";
messageMetaData.appendChild(avatarImage);
avatarImage.className = "avatarImage";
messageMetaData.appendChild(avatarImage)
userName.className = "userName";
messageMetaData.appendChild(userName);
userName.textContent = message.author;
timeStamp.className="timeStamp";
messageMetaData.appendChild(timeStamp);
timeStamp.textContent= message.time;
userMessage.className = "userMessage";
messageBox.appendChild(userMessage);
textMessage.className = "userMessage";
userMessage.appendChild(textMessage)
textMessage.textContent = message.text;
msgContainer.appendChild(messageBox);
});
};
printMessage(channel)
//capture info from input event
//_____ get input function______
const $form = document.getElementById("chatForm");
const $inputValue =document.getElementById('inputText').value;
const $buttonSubmit = document.getElementById("sendButton");
// $form.addEventListener("submit", (evt) =>{
// evt.preventDefault();
// evt.stopPropagation();
// });
console.log($inputValue);
// function messageObject(author, time, avatar, text){
// this.author = author;
// this. time = time;
// this.avatar = avatar;
// this.text = text;
// };
$buttonSubmit.addEventListener("click",function (evt) {
evt.preventDefault();
// const author= "Sigfrid Blake";
// const time = "19:05";
// const avatar = "img/avatarSig.png"
// const text = $inputValue;
const messageObject = {
author: "Sigfrid Blake",
time: "19:05",
avatar: "img/avatarSig.png",
text: $inputValue,
};
// const msg = messageObject(author,time,avatar,text);
arrayChannels[1].content.push(messageObject);
printMessage(channel)
});
//const $button = document.querySelector(".sendButton");
console.log("ït works!");