59 lines
1.3 KiB
CoffeeScript
59 lines
1.3 KiB
CoffeeScript
# 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 ->
|
|
# gather form data
|
|
uname = $('input[name="uname"]', @)
|
|
password = $('input[name="password"]', @)
|
|
confirm = $('input[name="confirm"]', @)
|
|
|
|
# check form data
|
|
if password.val() == confirm.val()
|
|
|
|
# transmit form data
|
|
socket.emit 'register', uname.val(), password.val()
|
|
console.log 'emitted "register", "%s", "%s"', uname.val(), password.val()
|
|
|
|
# reset form
|
|
$('input', @).each ->
|
|
$(@).removeClass 'is-invalid'
|
|
$(@).removeClass 'is-valid'
|
|
return
|
|
|
|
@reset()
|
|
|
|
else
|
|
confirm.val ''
|
|
confirm.addClass 'is-invalid'
|
|
confirm.focus()
|
|
|
|
# inhibit actual submission
|
|
false
|