From c7de3a897d2890c3a4d022e2ee6e0caadf8c21ee Mon Sep 17 00:00:00 2001 From: Mattias Erming Date: Wed, 7 May 2014 16:01:46 +0200 Subject: [PATCH] Use location.hash to remember active window --- client/js/chat.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/client/js/chat.js b/client/js/chat.js index 6c442289..107778ae 100644 --- a/client/js/chat.js +++ b/client/js/chat.js @@ -79,14 +79,24 @@ $(function() { .prev(".show-more") .show(); chat.find(".messages") - .scrollGlue({speed: 400}); + .scrollGlue({speed: 400}) + .end(); - $("#networks") - .html(render("networks", {networks: data.networks})) - .parent() - .find("button") - .first() - .trigger("click"); + var networks = $("#networks") + .html(render("networks", {networks: data.networks})); + + var target = null; + if (location.hash) { + var id = location.hash; + target = sidebar + .find("button[data-target='" + id + "']"); + } else { + target = sidebar + .find("button") + .first() + } + + target.trigger("click"); break; case "part": @@ -107,12 +117,17 @@ $(function() { sidebar.on("click", "button", function() { var button = $(this); var target = button.data("target"); + + location.hash = target; + sidebar.find(".active").removeClass("active"); button.addClass("active") .find(".badge") .removeClass("highlight") .empty(); - $(target).css("z-index", z++) + + var window = $(target) + .css("z-index", z++) .find("input") .focus(); });