-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientmain_pre.js
45 lines (40 loc) · 1.14 KB
/
clientmain_pre.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
$(() => {
var $window=$(window);
var $loginPage = $('.login.page');
var $usernameInput = $('.usernameInput');
var $currentInput = $usernameInput.focus();
var username;
const setUsername = () => {
username = cleanInput($usernameInput.val().trim());
}
const gotoChatPage=()=>{
if (username) {
// Tell the server your username
if($("input[name='1']:checked").val()!=undefined){
$loginPage.fadeOut();
$loginPage.off('click');
document.cookie="pre_name="+username;
document.cookie="pre_gender="+$("input[name='1']:checked").val()
window.location.href = "/chat";
}
else
alert("请先选择性别");
}
}
const cleanInput = (input) => {
return $('<div/>').text(input).html();
}
$usernameInput.keypress((e) => {
if (e.which == 13) {
setUsername()
gotoChatPage()
}
});
$window.keydown(event => {
// Auto-focus the current input when a key is typed
if (!(event.ctrlKey || event.metaKey || event.altKey)) {
$currentInput.focus();
}
// When the client hits ENTER on their keyboard
});
})