# libs
window.$ = require('jquery')
# on load
$ ->
# libs requiring full DOM
io = require 'socket.io-client'
# style sheet
require './style/custom.scss'
# init Socket.IO
socket = io()
# login form
$('form[name="login"]').submit ->
# gather form data
uname = $('input[name="uname"]', @)
password = $('input[name="password"]', @)
# transmit form data
socket.emit 'login', uname.val(), password.val()
console.log 'emitted "login", "%s", "%s"', uname.val(), password.val()
# reset form
@reset()
# inhibit actual submission
false
# register form
$('form[name="register"]').submit ->
confirm = $('input[name="confirm"]', @)
# check form data
if password.val() == confirm.val()
socket.emit 'register', uname.val(), password.val()
console.log 'emitted "register", "%s", "%s"', uname.val(), password.val()
$('input', @).each ->
$(@).removeClass 'is-invalid'
$(@).removeClass 'is-valid'
return
else
confirm.val ''
confirm.addClass 'is-invalid'
confirm.focus()