Fix browser compat issue

This commit is contained in:
calzoneman 2013-08-07 17:55:39 -04:00
parent 2e79b01894
commit ac9d60eee7
2 changed files with 25 additions and 8 deletions

View File

@ -1,4 +1,5 @@
/* /*
return null;
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2013 Calvin Montgomery Copyright (c) 2013 Calvin Montgomery
@ -485,7 +486,7 @@ Callbacks = {
setChannelRank: function(data) { setChannelRank: function(data) {
var ents = $("#channelranks").data("entries"); var ents = $("#channelranks").data("entries");
if(typeof ents === undefined) if(typeof ents === "undefined")
return; return;
for(var i = 0; i < ents.length; i++) { for(var i = 0; i < ents.length; i++) {
if(ents[i].name == data.user) { if(ents[i].name == data.user) {
@ -621,7 +622,7 @@ Callbacks = {
addUser: function(data) { addUser: function(data) {
var div = $("<div/>") var div = $("<div/>")
.addClass("userlist_item userlist-" + data.name); .addClass("userlist_item");
var flair = $("<span/>").appendTo(div); var flair = $("<span/>").appendTo(div);
var nametag = $("<span/>").text(data.name).appendTo(div); var nametag = $("<span/>").text(data.name).appendTo(div);
formatUserlistItem(div, data); formatUserlistItem(div, data);
@ -665,13 +666,17 @@ Callbacks = {
} }
} }
var user = $(".userlist-" + data.name); var user = findUserlistItem(data.name);
formatUserlistItem(user, data); if(user !== null) {
addUserDropdown(user, data); formatUserlistItem(user, data);
addUserDropdown(user, data);
}
}, },
setAFK: function (data) { setAFK: function (data) {
var user = $(".userlist-" + data.name); var user = findUserlistItem(data.name);
if(user === null)
return;
user.find(".icon-time").remove(); user.find(".icon-time").remove();
$(user[0].children[1]).css("font-style", ""); $(user[0].children[1]).css("font-style", "");
if(data.afk) { if(data.afk) {
@ -682,7 +687,9 @@ Callbacks = {
}, },
userLeave: function(data) { userLeave: function(data) {
$(".userlist-" + data.name).remove(); var user = findUserlistItem(data.name);
if(user !== null)
user.remove();
}, },
drinkCount: function(count) { drinkCount: function(count) {

View File

@ -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) { function formatUserlistItem(div, data) {
var name = $(div.children()[1]); var name = $(div.children()[1]);
name.removeClass(); name.removeClass();
@ -152,7 +162,7 @@ function addUserDropdown(entry, data) {
.appendTo(sel); .appendTo(sel);
} }
} }
sel.click(function () { sel.change(function () {
socket.emit("setChannelRank", { socket.emit("setChannelRank", {
user: name, user: name,
rank: parseInt(sel.val()) rank: parseInt(sel.val())