summaryrefslogtreecommitdiff
path: root/public/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js')
-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
-rw-r--r--public/js/vendor/sha1.js192
-rw-r--r--public/js/vendor/util.js1
8 files changed, 290 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)
diff --git a/public/js/vendor/sha1.js b/public/js/vendor/sha1.js
new file mode 100644
index 0000000..f1f811c
--- /dev/null
+++ b/public/js/vendor/sha1.js
@@ -0,0 +1,192 @@
+/* SHA1.js (timb: compressed this)
+ * Version 2.2 Copyright Paul Johnston 2000 - 2009.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * Distributed under the BSD License
+ * from http://pajhome.org.uk/crypt/md5/sha1.html
+ */
+var SHA1 = {
+ "hexcase": 0,
+ "b64pad": "",
+ "hex": function(s) { return SHA1.rstr2hex(SHA1.rstr(SHA1.str2rstr_utf8(s))); },
+ "b64": function(s) { return SHA1.rstr2b64(SHA1.rstr(SHA1.str2rstr_utf8(s))); },
+ "any": function(s, e) { return SHA1.rstr2any(SHA1.rstr(SHA1.str2rstr_utf8(s)), e); },
+ "hex_hmac": function(k, d){ return SHA1.rstr2hex(SHA1.rstr_hmac(SHA1.str2rstr_utf8(k), SHA1.str2rstr_utf8(d))); },
+ "b64_hmac": function(k, d){ return SHA1.rstr2b64(SHA1.rstr_hmac(SHA1.str2rstr_utf8(k), SHA1.str2rstr_utf8(d))); },
+ "any_hmac": function(k, d, e){ return SHA1.rstr2any(SHA1.rstr_hmac(SHA1.str2rstr_utf8(k), SHA1.str2rstr_utf8(d)), e); },
+ "rstr": function(s) { return SHA1.binb2rstr(SHA1.binb(SHA1.rstr2binb(s), s.length * 8)); },
+ "rstr_hmac": function(key, data){
+ var bkey = SHA1.rstr2binb(key);
+ if(bkey.length > 16) bkey = SHA1.binb(bkey, key.length * 8);
+ var ipad = Array(16), opad = Array(16);
+ for(var i = 0; i < 16; i++){
+ ipad[i] = bkey[i] ^ 0x36363636;
+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
+ }
+ var hash = SHA1.binb(ipad.concat(SHA1.rstr2binb(data)), 512 + data.length * 8);
+ return SHA1.binb2rstr(SHA1.binb(opad.concat(hash), 512 + 160));
+ },
+ "rstr2hex": function(input){
+ try { SHA1.hexcase } catch(e) { SHA1.hexcase=0; }
+ var hex_tab = SHA1.hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
+ var output = "";
+ var x;
+ for(var i = 0; i < input.length; i++){
+ x = input.charCodeAt(i);
+ output += hex_tab.charAt((x >>> 4) & 0x0F)
+ + hex_tab.charAt( x & 0x0F);
+ }
+ return output;
+ },
+ "rstr2b64": function(input){
+ try { SHA1.b64pad } catch(e) { SHA1.b64pad=''; }
+ var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ var output = "";
+ var len = input.length;
+ for(var i = 0; i < len; i += 3){
+ var triplet = (input.charCodeAt(i) << 16)
+ | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
+ | (i + 2 < len ? input.charCodeAt(i+2) : 0);
+ for(var j = 0; j < 4; j++){
+ if(i * 8 + j * 6 > input.length * 8) output += SHA1.b64pad;
+ else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
+ }
+ }
+ return output;
+ },
+ "rstr2any": function(input, encoding){
+ var divisor = encoding.length;
+ var remainders = Array();
+ var i, q, x, quotient;
+ var dividend = Array(Math.ceil(input.length / 2));
+ for(i = 0; i < dividend.length; i++)
+ dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
+ while(dividend.length > 0){
+ quotient = Array();
+ x = 0;
+ for(i = 0; i < dividend.length; i++){
+ x = (x << 16) + dividend[i];
+ q = Math.floor(x / divisor);
+ x -= q * divisor;
+ if(quotient.length > 0 || q > 0)
+ quotient[quotient.length] = q;
+ }
+ remainders[remainders.length] = x;
+ dividend = quotient;
+ }
+ var output = "";
+ for(i = remainders.length - 1; i >= 0; i--)
+ output += encoding.charAt(remainders[i]);
+ var full_length = Math.ceil(input.length * 8 /
+ (Math.log(encoding.length) / Math.log(2)))
+ for(i = output.length; i < full_length; i++)
+ output = encoding[0] + output;
+
+ return output;
+ },
+ "str2rstr_utf8": function(input){
+ var output = "";
+ var i = -1;
+ var x, y;
+ while(++i < input.length){
+ x = input.charCodeAt(i);
+ y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
+ if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF){
+ x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
+ i++;
+ }
+ if(x <= 0x7F)
+ output += String.fromCharCode(x);
+ else if(x <= 0x7FF)
+ output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
+ 0x80 | ( x & 0x3F));
+ else if(x <= 0xFFFF)
+ output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
+ 0x80 | ((x >>> 6 ) & 0x3F),
+ 0x80 | ( x & 0x3F));
+ else if(x <= 0x1FFFFF)
+ output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
+ 0x80 | ((x >>> 12) & 0x3F),
+ 0x80 | ((x >>> 6 ) & 0x3F),
+ 0x80 | ( x & 0x3F));
+ }
+ return output;
+ },
+ "str2rstr_utf16le": function(input){
+ var output = "";
+ for(var i = 0; i < input.length; i++)
+ output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
+ (input.charCodeAt(i) >>> 8) & 0xFF);
+ return output;
+ },
+ "str2rstr_utf16be": function(input){
+ var output = "";
+ for(var i = 0; i < input.length; i++)
+ output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
+ input.charCodeAt(i) & 0xFF);
+ return output;
+ },
+ "rstr2binb": function(input){
+ var output = Array(input.length >> 2);
+ for(var i = 0; i < output.length; i++)
+ output[i] = 0;
+ for(var i = 0; i < input.length * 8; i += 8)
+ output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
+ return output;
+ },
+ "binb2rstr": function(input){
+ var output = "";
+ for(var i = 0; i < input.length * 32; i += 8)
+ output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
+ return output;
+ },
+ "binb": function(x, len){
+ x[len >> 5] |= 0x80 << (24 - len % 32);
+ x[((len + 64 >> 9) << 4) + 15] = len;
+ var w = Array(80);
+ var a = 1732584193;
+ var b = -271733879;
+ var c = -1732584194;
+ var d = 271733878;
+ var e = -1009589776;
+ for(var i = 0; i < x.length; i += 16){
+ var olda = a;
+ var oldb = b;
+ var oldc = c;
+ var oldd = d;
+ var olde = e;
+ for(var j = 0; j < 80; j++){
+ if(j < 16) w[j] = x[i + j];
+ else w[j] = SHA1.bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
+ var t = SHA1.safe_add(SHA1.safe_add(SHA1.bit_rol(a, 5), SHA1.ft(j, b, c, d)),
+ SHA1.safe_add(SHA1.safe_add(e, w[j]), SHA1.kt(j)));
+ e = d;
+ d = c;
+ c = SHA1.bit_rol(b, 30);
+ b = a;
+ a = t;
+ }
+ a = SHA1.safe_add(a, olda);
+ b = SHA1.safe_add(b, oldb);
+ c = SHA1.safe_add(c, oldc);
+ d = SHA1.safe_add(d, oldd);
+ e = SHA1.safe_add(e, olde);
+ }
+ return Array(a, b, c, d, e);
+ },
+ "ft": function(t, b, c, d){
+ if(t < 20) return (b & c) | ((~b) & d);
+ if(t < 40) return b ^ c ^ d;
+ if(t < 60) return (b & c) | (b & d) | (c & d);
+ return b ^ c ^ d;
+ },
+ "kt": function(t){
+ return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
+ (t < 60) ? -1894007588 : -899497514;
+ },
+ "safe_add": function(x, y){
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF);
+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
+ return (msw << 16) | (lsw & 0xFFFF);
+ },
+ "bit_rol": function(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)) }
+} \ No newline at end of file
diff --git a/public/js/vendor/util.js b/public/js/vendor/util.js
index 3637f49..34ef45f 100644
--- a/public/js/vendor/util.js
+++ b/public/js/vendor/util.js
@@ -5,6 +5,7 @@ if (window.$) {
$.fn.enable = function() { return $(this).attr("disabled",null) }
$.fn.disable = function() { return $(this).attr("disabled","disabled") }
$.fn.sanitize = function(s) { return trim(sanitize($(this).val())) }
+ $.fn.stripHTML = function(s) { return trim(stripHTML($(this).val())) }
$.fn.sanitizeName = function(s) { return trim(sanitizeName($(this).val())) }
$.fn.htmlSafe = function(s) { return $(this).html(sanitize(s)) }
$.fn.toDollars = function(i) { return $(this).html((i/100).toFixed(2)) }