From 6369da671b35ee85ec636675939b8d87f2e27462 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 31 Aug 2012 15:48:40 -0400 Subject: [PATCH] Clean up narrowing code to all use the same pattern. (imported from commit 7f213ccdb31522a0fcb63cb69e2ea7677e3b352c) --- zephyr/static/js/zephyr.js | 46 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 9b0d4494e3..53fc0644e5 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -194,32 +194,23 @@ function scroll_to_selected() { } -function hide_personals() { - $("span.zephyr_personal_recipient").each( - function() { - $(this).parents("tr").hide(); - } - ); -} - function narrow_personals(target_zephyr) { var old_top = $("#main_div").offset().top - $("#" + target_zephyr).offset().top; - - $("span.zephyr_personal_recipient").each( + $("tr").each( function() { - $(this).parents("tr").show(); - } - ); - event.preventDefault(); - $("span.zephyr_class").each( - function() { - $(this).parents("tr").hide(); + if ($(this).find("span.zephyr_personal_recipient").length) { + $(this).show(); + } else { + $(this).hide(); + } } ); $("#selected").closest("td").empty(); $("#" + target_zephyr).children("td:first").html(selected_tag); $.post("update", {pointer: target_zephyr}); + + // Try to keep the zephyr in the same place on the screen after narrowing. scroll_to_zephyr(target_zephyr, old_top); $("#unhide").removeAttr("disabled"); @@ -229,17 +220,17 @@ function narrow_personals(target_zephyr) { function narrow_class(class_name, target_zephyr) { // We want the zephyr on which the narrow happened to stay in the same place if possible. var old_top = $("#main_div").offset().top - $("#" + target_zephyr).offset().top; - $("span.zephyr_class").each( + $("tr").each( function() { - if ($(this).text() != class_name) { - $(this).parents("tr").hide(); + if ($(this).find("span.zephyr_class").length && + $(this).find("span.zephyr_class").text() == class_name) { + $(this).show(); } else { - // If you've narrowed on an instance and then click on the class, that should unhide the other instances on that class. - $(this).parents("tr").show(); + $(this).hide(); } } ); - hide_personals(); + $("#selected").closest("td").empty(); $("#" + target_zephyr).children("td:first").html(selected_tag); $.post("update", {pointer: target_zephyr}); @@ -254,13 +245,16 @@ function narrow_instance(class_name, instance, target_zephyr) { var old_top = $("#main_div").offset().top - $("#" + target_zephyr).offset().top; $("tr").each( function() { - if (($(this).find("span.zephyr_class").text() != class_name) || - ($(this).find("span.zephyr_instance").text() != instance)) { + if ($(this).find("span.zephyr_class").length && + $(this).find("span.zephyr_class").text() == class_name && + $(this).find("span.zephyr_instance").text() == instance) { + $(this).show(); + } else { $(this).hide(); } } ); - hide_personals(); + $("#selected").closest("td").empty(); $("#" + target_zephyr).children("td:first").html(selected_tag); $.post("update", {pointer: target_zephyr});