diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-08-05 01:21:38 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-08-05 01:21:38 -0400 |
| commit | 18f6f0219474f0f43e7403a5f5f8cff7c3dd0246 (patch) | |
| tree | 228fd343f36da554e540a70a0522eae489ad62fc /public/js/lib | |
| parent | d0b4cd4f7e6364a35a420f2f3b0fcdbb502d8a9a (diff) | |
login view, lobby view
Diffstat (limited to 'public/js/lib')
| -rw-r--r-- | public/js/lib/user.js | 4 | ||||
| -rw-r--r-- | public/js/lib/views/index.js | 9 | ||||
| -rw-r--r-- | public/js/lib/views/lobby/index.js | 8 | ||||
| -rw-r--r-- | public/js/lib/views/login.js | 29 | ||||
| -rw-r--r-- | public/js/lib/views/room/index.js | 3 | ||||
| -rw-r--r-- | public/js/lib/ws.js | 9 |
6 files changed, 54 insertions, 8 deletions
diff --git a/public/js/lib/user.js b/public/js/lib/user.js index f96946f..1293895 100644 --- a/public/js/lib/user.js +++ b/public/js/lib/user.js @@ -2,10 +2,9 @@ var user = (function(){ var user = {} user.init = function(){ user.load() - user.bind() } user.bind = function(){ - $("#username").on("input", user.save) + // $("#username").on("input", user.save) } user.load = function(){ user.username = user.getCookie() @@ -38,6 +37,7 @@ var user = (function(){ } user.save = function(){ var username = user.sanitize() + if (! username.length) return if (username != user.username) user.setCookie(username); } user.setCookie = function(username){ diff --git a/public/js/lib/views/index.js b/public/js/lib/views/index.js index d96bffb..d5ec35d 100644 --- a/public/js/lib/views/index.js +++ b/public/js/lib/views/index.js @@ -10,13 +10,20 @@ var SiteRouter = Router.extend({ }, initialize: function(){ - this.route() + if (! user.username) { + $("#login").show() + } + else { + this.route() + } }, lobby: function(){ + this.view = new LobbyView () }, room: function(name){ + this.view = new RoomView (name) }, })
\ No newline at end of file diff --git a/public/js/lib/views/lobby/index.js b/public/js/lib/views/lobby/index.js index 5ed1966..70b63c4 100644 --- a/public/js/lib/views/lobby/index.js +++ b/public/js/lib/views/lobby/index.js @@ -1,9 +1,17 @@ var LobbyView = View.extend({ events: { + "form submit": "join" }, initialize: function(){ + this.$createRoom = this.$("#create-room") + }, + + join: function(){ + var name = this.$createRoom.sanitize() + if (! name) { return } + window.location.href = "/v/" + name } })
\ No newline at end of file diff --git a/public/js/lib/views/login.js b/public/js/lib/views/login.js new file mode 100644 index 0000000..325d22d --- /dev/null +++ b/public/js/lib/views/login.js @@ -0,0 +1,29 @@ +var LoginView = View.extend({ + el: "#login", + + events: { + "form submit": "save", + }, + + initialize: function(){ + this.$el.show() + }, + + save: function(e){ + e.preventDefault() + user.save() + var that = this + if (user.username.length) { + app.router.route() + oktween.add({ + obj: this.el.style, + from: { opacity: 1 }, + to: { opacity: 0 }, + duration: 500, + finished: function(){ + that.el.style.display = "none" + } + }) + } + }, +})
\ No newline at end of file diff --git a/public/js/lib/views/room/index.js b/public/js/lib/views/room/index.js index b266e29..58d7449 100644 --- a/public/js/lib/views/room/index.js +++ b/public/js/lib/views/room/index.js @@ -3,7 +3,8 @@ var RoomView = View.extend({ events: { }, - initialize: function(){ + initialize: function(name){ + app.socket = ws.connect(name) } })
\ No newline at end of file diff --git a/public/js/lib/ws.js b/public/js/lib/ws.js index fbf9211..15af8a1 100644 --- a/public/js/lib/ws.js +++ b/public/js/lib/ws.js @@ -1,9 +1,9 @@ -var ws = function(){ +var ws = (function(){ var ws = {} var socket, socketIsReady - ws.connect = function () { + ws.connect = function (room) { if (this.socket) return; - var socketPath = window.location.origin + '/' + posthang.room.subdomain + var socketPath = window.location.origin + '/' + room ws.socket = socket = io(socketPath) // this.socket.on('connect', function(){ console.log(new Date(), "connected")}) @@ -41,4 +41,5 @@ var ws = function(){ console.log(new Date(), "disconnected") // this.chatView.appendInfo({ content: "Disconnected." }) } -} + return ws +})() |
