This repository has been archived on 2024-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
node-fftcg/src/index.coffee

64 lines
1.4 KiB
CoffeeScript
Raw Normal View History

2018-11-29 13:47:49 +00:00
# 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()
# reset forms
$('form').each ->
that = @
@fullReset = ->
$('input', that).each ->
$(that).removeClass 'is-invalid'
$(that).removeClass 'is-valid'
that.reset()
# login form
$('form[name="login"]').submit ->
# inhibit normal form submission
event.preventDefault()
# gather form data
login = $('input[name="login"]', @)
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
@fullReset()
# register form
$('form[name="register"]').submit (event) ->
# inhibit normal form submission
event.preventDefault()
# gather form data
login = $('input[name="login"]', @)
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
@fullReset()
else
confirm.val ''
confirm.addClass 'is-invalid'
confirm.focus()