123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <!DOCTYPE HTML>
- <html>
- <head>
- <title>
- Static File Index.HTML
- </title>
- <script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js'></script>
- </head>
- <body>
- <div id='formContainer'>
- </div>
- <script>
- 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>
- </body>
- </html>
|