Skip to content

Commit

Permalink
Fix: Summary page scroll up auto multiple times (#781)
Browse files Browse the repository at this point in the history
* fix summary page scroll up auto multiple times

* clean center tree view code and use it for: 'classes', 'properties', 'schemes', 'collections', 'instances'

* revert adding useVisibility, and extract tree_view_pages to a constant
  • Loading branch information
Bilelkihal authored Oct 25, 2024
1 parent 227f563 commit 817c1f5
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions app/javascript/controllers/simple_tree_controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Controller } from '@hotwired/stimulus'

const TREE_VIEW_PAGES = ['classes', 'properties', 'schemes', 'collections', 'instances']

// Connects to data-controller="simple-tree"
export default class extends Controller {

Expand All @@ -7,17 +10,7 @@ export default class extends Controller {
}

connect () {
setTimeout(() => {
let activeElem = this.element.querySelector('.tree-link.active');
if (activeElem) {
activeElem.scrollIntoView({ block: 'center' });
window.scrollTo({top: 0,});
if (this.autoClickValue) {
activeElem.click();
}
}
this.#onClickTooManyChildrenInit();
}, 0);
this.#centerTreeView()
}

select (event) {
Expand All @@ -33,6 +26,29 @@ export default class extends Controller {
event.target.nextElementSibling.nextElementSibling.classList.toggle('hidden')
}

#centerTreeView() {
setTimeout(() => {
const location = window.location.href;

const isTreeViewPage = TREE_VIEW_PAGES.some(param => location.includes(`p=${param}`));

if (isTreeViewPage) {
const activeElem = this.element.querySelector('.tree-link.active');

if (activeElem) {
activeElem.scrollIntoView({ block: 'center' });
window.scrollTo({ top: 0 });

if (this.autoClickValue) {
activeElem.click();
}
}

this.#onClickTooManyChildrenInit();
}
}, 0);
}

#onClickTooManyChildrenInit () {
jQuery('.too_many_children_override').live('click', (event) => {
event.preventDefault()
Expand Down

0 comments on commit 817c1f5

Please sign in to comment.