Permalink
Browse files

You can now hit the return key when focused on the check box

  • Loading branch information...
1 parent f1934ee commit 3d8be00c92a1ed7a91afb90f72f8fde619b8bd70 @iangilman iangilman committed Mar 29, 2012
Showing with 29 additions and 28 deletions.
  1. +27 −26 demos/messages/Scripts/main.js
  2. +2 −2 demos/messages/index.html
@@ -30,34 +30,35 @@ window.Main = {
this.$members = $("#members");
this.$name = $("#name")
- .keypress(function(event) {
- if (event.which == 13) { // return key
- var name = self.$name.val();
- if (name) {
- var $status = $("#login-status")
- .text("Connecting…");
-
- if (self.$socketsCheckbox.prop("checked"))
- self.server = new SocketServer(receive);
- else
- self.server = new PollingServer(receive);
+ .focus();
+
+ $("#login")
+ .submit(function(event) {
+ event.preventDefault();
+ var name = self.$name.val();
+ if (name) {
+ var $status = $("#login-status")
+ .text("Connecting…");
+
+ if (self.$socketsCheckbox.prop("checked"))
+ self.server = new SocketServer(receive);
+ else
+ self.server = new PollingServer(receive);
- self.server.send("connect", {
- From: name
- }, function(result) {
- if (result && result.code == "success") {
- self.user = self.addMember(result);
- $("#login").hide();
- $("#chat").show();
- self.$entry.focus();
- } else {
- $status.text("Failed to connect.");
- }
- });
- }
+ self.server.send("connect", {
+ From: name
+ }, function(result) {
+ if (result && result.code == "success") {
+ self.user = self.addMember(result);
+ $("#login").hide();
+ $("#chat").show();
+ self.$entry.focus();
+ } else {
+ $status.text("Failed to connect.");
+ }
+ });
}
- })
- .focus();
+ });
this.$socketsCheckbox = $("#sockets")
.change(function() {
@@ -7,12 +7,12 @@
<link href="Styles/site.css" rel="stylesheet" type="text/css" />
</head>
<body>
- <div id="login" class="box-round box-shadow">
+ <form id="login" class="box-round box-shadow">
<p>Choose a name and hit return:</p>
<input id="name" type="text" />
<label id="sockets-label"><input id="sockets" type="checkbox"> Use WebSockets</label>
<div id="login-status"></div>
- </div>
+ </form>
<div id="chat">
<div id="members">
</div>

0 comments on commit 3d8be00

Please sign in to comment.