From ac9d60eee7998cda9580ea6c57ccd73031a441d0 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 7 Aug 2013 17:55:39 -0400 Subject: [PATCH] Fix browser compat issue --- www/assets/js/callbacks.js | 21 ++++++++++++++------- www/assets/js/util.js | 12 +++++++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/www/assets/js/callbacks.js b/www/assets/js/callbacks.js index d5d13504..7abc0769 100644 --- a/www/assets/js/callbacks.js +++ b/www/assets/js/callbacks.js @@ -1,4 +1,5 @@ /* +return null; The MIT License (MIT) Copyright (c) 2013 Calvin Montgomery @@ -485,7 +486,7 @@ Callbacks = { setChannelRank: function(data) { var ents = $("#channelranks").data("entries"); - if(typeof ents === undefined) + if(typeof ents === "undefined") return; for(var i = 0; i < ents.length; i++) { if(ents[i].name == data.user) { @@ -621,7 +622,7 @@ Callbacks = { addUser: function(data) { var div = $("
") - .addClass("userlist_item userlist-" + data.name); + .addClass("userlist_item"); var flair = $("").appendTo(div); var nametag = $("").text(data.name).appendTo(div); formatUserlistItem(div, data); @@ -665,13 +666,17 @@ Callbacks = { } } - var user = $(".userlist-" + data.name); - formatUserlistItem(user, data); - addUserDropdown(user, data); + var user = findUserlistItem(data.name); + if(user !== null) { + formatUserlistItem(user, data); + addUserDropdown(user, data); + } }, setAFK: function (data) { - var user = $(".userlist-" + data.name); + var user = findUserlistItem(data.name); + if(user === null) + return; user.find(".icon-time").remove(); $(user[0].children[1]).css("font-style", ""); if(data.afk) { @@ -682,7 +687,9 @@ Callbacks = { }, userLeave: function(data) { - $(".userlist-" + data.name).remove(); + var user = findUserlistItem(data.name); + if(user !== null) + user.remove(); }, drinkCount: function(count) { diff --git a/www/assets/js/util.js b/www/assets/js/util.js index cc4f91a5..e13ebfd2 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -58,6 +58,16 @@ function formatURL(data) { } } +function findUserlistItem(name) { + var children = $("#userlist .userlist_item"); + for(var i in children) { + var child = children[i]; + if(child.children[1].innerHTML === name) + return $(child); + } + return null; +} + function formatUserlistItem(div, data) { var name = $(div.children()[1]); name.removeClass(); @@ -152,7 +162,7 @@ function addUserDropdown(entry, data) { .appendTo(sel); } } - sel.click(function () { + sel.change(function () { socket.emit("setChannelRank", { user: name, rank: parseInt(sel.val())