|
@@ -12,52 +12,6 @@
|
|
<script>
|
|
<script>
|
|
const socket = io()
|
|
const socket = io()
|
|
|
|
|
|
- function Inputs(el, onSend){
|
|
|
|
- const nickInput = document.createElement('input')
|
|
|
|
- nickInput.type = 'text'
|
|
|
|
- nickInput.placeholder = 'Nick'
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- const messageInput = document.createElement('input')
|
|
|
|
- messageInput.type = 'text'
|
|
|
|
- messageInput.placeholder = 'Message'
|
|
|
|
-
|
|
|
|
- const button = document.createElement('button')
|
|
|
|
- button.innerText = 'Send'
|
|
|
|
-
|
|
|
|
- button.onclick = () => {
|
|
|
|
- onSend(nickInput.value, messageInput.value)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- messageInput.oninput = () => {
|
|
|
|
- if (typeof this.validate === 'function'){
|
|
|
|
- button.disabled = !this.validate(nickInput.value, messageInput.value)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- nickInput.oninput = messageInput.oninput
|
|
|
|
-
|
|
|
|
- el.appendChild(nickInput)
|
|
|
|
- el.appendChild(messageInput)
|
|
|
|
- el.appendChild(button)
|
|
|
|
-
|
|
|
|
- this.getNick = () => nickInput.value
|
|
|
|
- this.getMessage = () => messageInput.value
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const form = new Inputs(formContainer, function(nick, message){
|
|
|
|
- socket.emit('msg', {nick, message})
|
|
|
|
- })
|
|
|
|
- form.validate = (n, m) => n && m
|
|
|
|
- console.log(form)
|
|
|
|
-
|
|
|
|
-/* setInterval(() =>{
|
|
|
|
- console.log(form.getMessage())
|
|
|
|
- }, 1000) */
|
|
|
|
-
|
|
|
|
</script>
|
|
</script>
|
|
</body>
|
|
</body>
|
|
</html>
|
|
</html>
|