main.js autoformat
This commit is contained in:
parent
a4f637eda0
commit
3940844fc9
1 changed files with 17 additions and 19 deletions
36
main.js
36
main.js
|
@ -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×tamp=' + 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(() => {
|
||||
|
|
Loading…
Reference in a new issue