main.js autoformat

This commit is contained in:
Tomáš Mládek 2019-11-04 18:05:54 +01:00
parent a4f637eda0
commit 3940844fc9

36
main.js
View file

@ -9,15 +9,15 @@ if (document.querySelector('.modal__form-submit')) {
date = new Date(date);
const expires = '; expires=' + date.toUTCString();
document.cookie = 'outchat_name=' + (value || '') + expires + '; path=/';
window.location.href = ''
window.location.href = '';
}
})
});
}
document.querySelector('.form__input-message').addEventListener('keydown', function (e) {
if (!e.ctrlKey && e.keyCode === 13) {
e.preventDefault();
document.querySelector('.form__input-submit').click()
document.querySelector('.form__input-submit').click();
}
});
@ -34,16 +34,14 @@ document.querySelector('.form__input-submit').addEventListener('click', function
fetch('api.php?action=createMessage', {
method: 'post',
headers: {
"Content-Type": "application/x-www-form-urlencoded"
"Content-Type": "application/x-www-form-urlencoded",
},
body: 'name=' + name + '&text=' + text
})
.then(() => {
getMessages()
})
.catch((error) => {
console.log(error)
})
body: 'name=' + name + '&text=' + text,
}).then(() => {
getMessages();
}).catch((error) => {
console.log(error);
});
});
function getMessages() {
@ -51,23 +49,23 @@ function getMessages() {
return fetch('api.php?action=getMessages&timestamp=' + timestamp)
.then(function (data) {
return data.json()
return data.json();
})
.then(function (data) {
if (data.length > 0) {
if ((window.scrollY + window.innerHeight) === document.body.scrollHeight) {
setTimeout(function () {
scrollWindowDown()
}, 100)
scrollWindowDown();
}, 100);
}
for (message of data) {
createMessageNode(message.name, message.text_processed, message.timestamp, message.datetime)
createMessageNode(message.name, message.text_processed, message.timestamp, message.datetime);
}
}
})
.catch(function (error) {
console.log(error)
})
console.log(error);
});
}
function createMessageNode(name, text, timestamp, datetime) {
@ -104,7 +102,7 @@ function createMessageNode(name, text, timestamp, datetime) {
document.querySelector('.chat').appendChild(elementMain);
return true
return true;
}
getMessages().then(() => {