Skip to content

Commit

Permalink
fix final scroll positioning issues in search scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-jones committed Jul 4, 2024
1 parent e593b56 commit f0980f4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
25 changes: 20 additions & 5 deletions portality/static/js/doaj.fieldrender.edges.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,16 @@ $.extend(true, doaj, {

this.namespace = "doaj-subject-browser";

this.viewWindowScrollOffset = 0;
this.lastScroll = 0;
this.lastSearch = edges.getParam(params.lastSearch, null);
this.lastClickedEl = edges.getParam(params.lastClickedEl, null);

this.init = function(component) {
edges.newRenderer().init.call(this, component);
component.edge.context.on("edges:pre-reset", edges.eventClosure(this, "reset"));
}

this.draw = function () {
// for convenient short references ...
var st = this.component.syncTree;
Expand Down Expand Up @@ -689,6 +695,13 @@ $.extend(true, doaj, {
edges.on(searchSelector, "keyup", this, "filterSubjects");
};

this.reset = function(edge) {
this.lastSearch = null;
this.viewWindowScrollOffset = 0;
this.lastClickedEl = null;
this.lastScroll = 0;
}

this._renderTree = function (params) {
var st = edges.getParam(params.tree, []);
var selectedPathOnly = edges.getParam(params.selectedPathOnly, true);
Expand Down Expand Up @@ -805,9 +818,10 @@ $.extend(true, doaj, {
var filterSelector = edges.css_id_selector(this.namespace, "filtered", this);
this.lastScroll = this.lastSearch ? this.component.jq(filterSelector).scrollTop() : this.component.jq(mainListSelector).scrollTop();
var el = this.component.jq(element);
// var filter_id = this.component.jq(element).attr("id");
var checked = el.is(":checked");
this.lastClickedEl = el[0].id;
let offset = this.lastSearch ? this.component.jq(filterSelector).offset().top : this.component.jq(mainListSelector).offset().top;
this.viewWindowScrollOffset = el.offset().top - offset;
var value = el.attr("data-value");
if (checked) {
this.component.addFilter({value: value});
Expand Down Expand Up @@ -857,7 +871,7 @@ $.extend(true, doaj, {
var st = this.component.syncTree;
var elemToScroll = this._findRenderedElement(st, this.lastClickedEl);
if (elemToScroll) {
browser.scrollTop = elemToScroll.offsetTop - browser.offsetTop;
browser.scrollTop = elemToScroll.offsetTop - browser.offsetTop - this.viewWindowScrollOffset;
}
}

Expand Down Expand Up @@ -889,9 +903,6 @@ $.extend(true, doaj, {
}
this.lastSearch = term;
term = term.toLowerCase();
if (this.lastClickedEl) {
this.scrollView(filterEl);
}

function entryMatch(entry) {
if (that.hideEmpty && entry.count === 0 && entry.childCount === 0) {
Expand Down Expand Up @@ -944,6 +955,10 @@ $.extend(true, doaj, {
mainEl.hide();
filterEl.show();

if (this.lastClickedEl) {
this.scrollView(filterEl);
}

var checkboxSelector = edges.css_class_selector(this.namespace, "selector", this);
edges.on(checkboxSelector, "change", this, "filterToggle");
} else {
Expand Down
2 changes: 1 addition & 1 deletion portality/static/vendor/edges

0 comments on commit f0980f4

Please sign in to comment.