From 425aa751651411dcf0f453f11da34d6b4c558409 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Thu, 8 Aug 2013 10:39:58 -0400 Subject: [PATCH] Show popup with breakdown of usercount on hover --- www/assets/js/ui.js | 32 ++++++++++++++++++++++++++++++++ www/assets/js/util.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/www/assets/js/ui.js b/www/assets/js/ui.js index 21d79933..614aad51 100644 --- a/www/assets/js/ui.js +++ b/www/assets/js/ui.js @@ -68,6 +68,38 @@ $("#logout").click(function() { }); /* chatbox */ + +$("#usercountwrap").mouseenter(function (ev) { + var breakdown = calcUserBreakdown(); + // re-using profile-box class for convenience + var popup = $("
") + .addClass("profile-box") + .css("top", (ev.pageY + 5) + "px") + .css("left", (ev.pageX) + "px") + .appendTo($("#usercountwrap")); + + var contents = ""; + for(var key in breakdown) { + contents += "" + key + ": " + breakdown[key]; + contents += "
" + } + + popup.html(contents); +}); + +$("#usercountwrap").mousemove(function (ev) { + var popup = $("#usercountwrap").find(".profile-box"); + if(popup.length == 0) + return; + + popup.css("top", (ev.pageY + 5) + "px"); + popup.css("left", (ev.pageX) + "px"); +}); + +$("#usercountwrap").mouseleave(function () { + $("#usercountwrap").find(".profile-box").remove(); +}); + $("#messagebuffer").mouseenter(function() { SCROLLCHAT = false; }); $("#messagebuffer").mouseleave(function() { SCROLLCHAT = true; }); diff --git a/www/assets/js/util.js b/www/assets/js/util.js index cc4f91a5..0fc77531 100644 --- a/www/assets/js/util.js +++ b/www/assets/js/util.js @@ -243,6 +243,35 @@ function addUserDropdown(entry, data) { }); } +function calcUserBreakdown() { + var breakdown = { + "Site Admins": 0, + "Channel Admins": 0, + "Moderators": 0, + "Regular Users": 0, + "Guests": 0, + "AFK": 0 + }; + $("#userlist .userlist_item").each(function (index, item) { + var data = $(item).data("dropdown-info"); + if(data.rank >= 255) + breakdown["Site Admins"]++; + else if(data.rank >= 3) + breakdown["Channel Admins"]++; + else if(data.rank == 2) + breakdown["Moderators"]++; + else if(data.rank >= 1) + breakdown["Regular Users"]++; + else + breakdown["Guests"]++; + + if($(item).find(".icon-time").length > 0) + breakdown["AFK"]++; + }); + + return breakdown; +} + /* queue stuff */ function scrollQueue() {