summaryrefslogtreecommitdiff
path: root/public/js/lib/views
diff options
context:
space:
mode:
Diffstat (limited to 'public/js/lib/views')
-rw-r--r--public/js/lib/views/index.js29
-rw-r--r--public/js/lib/views/lobby/index.js17
-rw-r--r--public/js/lib/views/login.js29
-rw-r--r--public/js/lib/views/room/index.js10
4 files changed, 85 insertions, 0 deletions
diff --git a/public/js/lib/views/index.js b/public/js/lib/views/index.js
new file mode 100644
index 0000000..d5ec35d
--- /dev/null
+++ b/public/js/lib/views/index.js
@@ -0,0 +1,29 @@
+var SiteRouter = Router.extend({
+ el: "body",
+
+ events: {
+ },
+
+ routes: {
+ "/": 'lobby',
+ "/v/:name": 'room',
+ },
+
+ initialize: function(){
+ 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
new file mode 100644
index 0000000..0306445
--- /dev/null
+++ b/public/js/lib/views/lobby/index.js
@@ -0,0 +1,17 @@
+var LobbyView = View.extend({
+
+ events: {
+ "form submit": "join"
+ },
+
+ initialize: function(){
+ this.$createRoom = this.$("#create-room")
+ },
+
+ join: function(){
+ var name = this.$createRoom.sanitizeName()
+ 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
new file mode 100644
index 0000000..58d7449
--- /dev/null
+++ b/public/js/lib/views/room/index.js
@@ -0,0 +1,10 @@
+var RoomView = View.extend({
+
+ events: {
+ },
+
+ initialize: function(name){
+ app.socket = ws.connect(name)
+ }
+
+}) \ No newline at end of file