summaryrefslogtreecommitdiff
path: root/public/js/lib
diff options
context:
space:
mode:
Diffstat (limited to 'public/js/lib')
-rw-r--r--public/js/lib/bg.js4
-rw-r--r--public/js/lib/user.js3
-rw-r--r--public/js/lib/video.js8
-rw-r--r--public/js/lib/views/room/room.js7
-rw-r--r--public/js/lib/views/room/settings.js82
-rw-r--r--public/js/lib/views/room/userlist.js5
6 files changed, 97 insertions, 12 deletions
diff --git a/public/js/lib/bg.js b/public/js/lib/bg.js
index 6fa75d5..2bcd284 100644
--- a/public/js/lib/bg.js
+++ b/public/js/lib/bg.js
@@ -11,7 +11,7 @@ var bg = (function(){
from: { opacity: 1 },
to: { opacity: 0 },
easing: "circ_in",
- duration: 500,
+ duration: 200,
finished: function(){
bg.el.style.backgroundImage = "url(" + picture.url + ")"
bg.el.className = picture.tile ? "tile" : ""
@@ -20,7 +20,7 @@ var bg = (function(){
delay: 500,
to: { opacity: 1 },
easing: "circ_in",
- duration: 500,
+ duration: 200,
})
}
return bg
diff --git a/public/js/lib/user.js b/public/js/lib/user.js
index 1293895..3c6d907 100644
--- a/public/js/lib/user.js
+++ b/public/js/lib/user.js
@@ -43,7 +43,8 @@ var user = (function(){
user.setCookie = function(username){
console.log("setting to " + username)
document.cookie = "imname="+username+";path=/;domain=.asdf.us;max-age=1086400"
- localStorage.setItem("im.name", username);
+ localStorage.setItem("im.name", username)
+ user.username = username
}
return user
})()
diff --git a/public/js/lib/video.js b/public/js/lib/video.js
index aa01d23..91bbfe6 100644
--- a/public/js/lib/video.js
+++ b/public/js/lib/video.js
@@ -3,13 +3,11 @@ var VideoView = View.extend({
events: {
},
- initialize: function(media){
- this.media = media
- this.mx
- this.build(media)
+ initialize: function(){
},
- build: function(media){
+ load: function(media){
+ this.media = media
var mxType
switch (media.type) {
case 'video':
diff --git a/public/js/lib/views/room/room.js b/public/js/lib/views/room/room.js
index 13f08ce..f8b6324 100644
--- a/public/js/lib/views/room/room.js
+++ b/public/js/lib/views/room/room.js
@@ -9,15 +9,18 @@ var RoomView = View.extend({
var base = this
this.name = name
- this.chatView = new ChatView (socket)
- this.userlist = new UserlistView (socket)
+ this.chat = new ChatView (app.socket)
+ this.userlist = new UserlistView (app.socket)
+ this.settings = new SettingsView (app.socket)
app.socket.emit("join", { nick: user.username })
app.socket.on("welcome", function(room){
+ console.log(room)
room.messages.forEach(base.chat.add)
base.userlist.users = room.users
base.userlist.update()
+ base.settings.update(room.settings)
})
app.socket.on("message", function(msg){
diff --git a/public/js/lib/views/room/settings.js b/public/js/lib/views/room/settings.js
new file mode 100644
index 0000000..e192503
--- /dev/null
+++ b/public/js/lib/views/room/settings.js
@@ -0,0 +1,82 @@
+var SettingsView = View.extend({
+
+ el: "#settings",
+
+ events: {
+ "click": "stopPropagation",
+ "click .open": "open",
+ "blur [name=bg]": "updateBackground",
+ "submit form": "save",
+ },
+
+ initialize: function(socket){
+ this.$bg = this.$("[name=bg]")
+ socket.on("settings", this.update.bind(this))
+ },
+
+ open: function(){
+ if (this.isOpen) {
+ return this.close()
+ }
+ this.isOpen = true
+ this.$el.addClass("active")
+ this._close = this.close.bind(this)
+ $(document.body).on("click", this._close)
+ },
+
+ close: function(){
+ this.isOpen = false
+ this.$el.addClass("active")
+ $(document.body).off("click", this._close)
+ },
+
+ serialize: function(){
+ var fd = {}
+
+ this.$("input[name], select[name], textarea[name]").each( function(){
+ if (this.type == "password") {
+ if (this.value.length > 0) {
+ fd[this.name] = SHA1.hex('lol$' + this.value + '$asdf')
+ }
+ }
+ else {
+ fd[this.name] = sanitize(this.value)
+ }
+ })
+
+ return fd
+ },
+
+ save: function(e){
+ if (this.saving) { return }
+ this.saving = true
+ e.preventDefault()
+ var data = this.serialize()
+ app.socket.emit("settings", data)
+ },
+
+ update: function(data){
+ var base = this
+ if (this.saving) {
+ this.saving = false
+ return
+ }
+ Object.keys(data).forEach(function(key){
+ switch (key) {
+ case 'bg':
+ console.log(data.bg)
+ base.$bg.val(data.bg.url)
+ bg.change(data.bg)
+ break
+ }
+ })
+ },
+
+ updateBackground: function(){
+ if (this.saving) { return }
+ var url = this.$bg.stripHTML()
+ bg.change(url)
+ app.socket.emit("settings", { bg: { url: url, tile: false } })
+ }
+})
+
diff --git a/public/js/lib/views/room/userlist.js b/public/js/lib/views/room/userlist.js
index 600f647..09b911b 100644
--- a/public/js/lib/views/room/userlist.js
+++ b/public/js/lib/views/room/userlist.js
@@ -6,7 +6,7 @@ var UserlistView = View.extend({
},
users: {},
- initialize: function(socket){
+ initialize: function(){
var base = this
app.socket.on("joined", function(data){
base.users[data.nick] = true
@@ -19,7 +19,8 @@ var UserlistView = View.extend({
},
update: function(){
- base.el.empty()
+ var base = this
+ this.$el.empty()
Object.keys(base.users).sort().forEach(function(nick){
var el = document.createElement("div")
base.el.appendChild(el)