Make scrolling Correct (a la Barnowl) without losing messages

Previously the wedge sometimes got lost when you scroll. Now, on a
scrolling action the selected message is moved in to the middle.

We also now use scroll_to_selected as opposed to scroll_to_zephyr because
there wasn't really a usecase for scrolling to a non-selected zephyr.

(imported from commit 5091b3a715f2253dfe302d4c7ea8a087ff9d508e)
This commit is contained in:
Luke Faraone 2012-08-31 16:20:20 -04:00
parent 2d30c9440d
commit 3223d2e0ba
1 changed files with 12 additions and 24 deletions

View File

@ -93,12 +93,9 @@ function select_zephyr(next_zephyr) {
next_zephyr.children("td:first").html(selected_tag); next_zephyr.children("td:first").html(selected_tag);
$.post("update", {pointer: next_zephyr.attr("id")}); $.post("update", {pointer: next_zephyr.attr("id")});
if ($(next_zephyr).offset().top < $("#main_div").offset().top) { if (($(next_zephyr).offset().top < $("#main_div").offset().top) ||
$("#main_div").scrollTop($("#main_div").scrollTop() - 75); ($(next_zephyr).offset().top + $(next_zephyr).height() > $("#main_div").offset().top + $("#main_div").height())) {
} scroll_to_selected();
if ($(next_zephyr).offset().top + $(next_zephyr).height() > $("#main_div").offset().top + $("#main_div").height()) {
$("#main_div").scrollTop($("#main_div").scrollTop() + 75);
} }
} }
} }
@ -136,6 +133,7 @@ $(document).keydown(function(event) {
next_zephyr = tr.prevAll(":not(:hidden):first"); next_zephyr = tr.prevAll(":not(:hidden):first");
} }
select_zephyr(next_zephyr); select_zephyr(next_zephyr);
event.preventDefault();
} else if (event.keyCode == 82) { // 'r' keypress, for responding to a zephyr } else if (event.keyCode == 82) { // 'r' keypress, for responding to a zephyr
var parent = $("#selected").parents("tr"); var parent = $("#selected").parents("tr");
var zephyr_class = parent.find("span.zephyr_class").text(); var zephyr_class = parent.find("span.zephyr_class").text();
@ -184,17 +182,10 @@ $(document).keydown(function(event) {
} }
}); });
function scroll_to_zephyr(target_zephyr, old_offset) { function scroll_to_selected() {
// target_zephyr is an id. $('#main_div').scrollTop(0);
// old_offset is how far from the top of the scroll area the $('#main_div').scrollTop($("#selected").offset().top - $('#main_div').height()/1.5);
// zephyr was before any narrowing or unnarrowing happened.
var height_above_zephyr = 0;
$("#table tr:lt(" + $("#" + target_zephyr).index() + ")").each(function() {
if (!$(this).is(":hidden")) {
height_above_zephyr += $(this).height();
}
});
$("#main_div").scrollTop(height_above_zephyr + old_offset);
} }
function hide_personals() { function hide_personals() {
@ -213,6 +204,7 @@ function narrow_personals(target_zephyr) {
$(this).parents("tr").show(); $(this).parents("tr").show();
} }
); );
event.preventDefault();
$("span.zephyr_class").each( $("span.zephyr_class").each(
function() { function() {
$(this).parents("tr").hide(); $(this).parents("tr").hide();
@ -246,8 +238,7 @@ function narrow(class_name, target_zephyr) {
$("#" + target_zephyr).children("td:first").html(selected_tag); $("#" + target_zephyr).children("td:first").html(selected_tag);
$.post("update", {pointer: target_zephyr}); $.post("update", {pointer: target_zephyr});
// Try to keep the zephyr in the same place on the screen after narrowing. scroll_to_selected();
scroll_to_zephyr(target_zephyr, old_top);
$("#unhide").removeAttr("disabled"); $("#unhide").removeAttr("disabled");
$("#narrow_indicator").html("Showing <span class='label zephyr_class'>" + class_name + "</span>"); $("#narrow_indicator").html("Showing <span class='label zephyr_class'>" + class_name + "</span>");
@ -268,8 +259,7 @@ function narrow_instance(class_name, instance, target_zephyr) {
$("#" + target_zephyr).children("td:first").html(selected_tag); $("#" + target_zephyr).children("td:first").html(selected_tag);
$.post("update", {pointer: target_zephyr}); $.post("update", {pointer: target_zephyr});
// Try to keep the zephyr in the same place on the screen after narrowing. scroll_to_selected();
scroll_to_zephyr(target_zephyr, old_top);
$("#unhide").removeAttr("disabled"); $("#unhide").removeAttr("disabled");
$("#narrow_indicator").html("Showing <span class='label zephyr_class'>" + class_name $("#narrow_indicator").html("Showing <span class='label zephyr_class'>" + class_name
@ -285,9 +275,7 @@ function prepare_personal(username) {
function unhide() { function unhide() {
$("tr").show(); $("tr").show();
p = $("#selected"); scroll_to_selected();
tr = $(p).closest("tr");
scroll_to_zephyr(tr.attr("id"), 0);
$("#unhide").attr("disabled", "disabled"); $("#unhide").attr("disabled", "disabled");
$("#narrow_indicator").html(""); $("#narrow_indicator").html("");