Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
khaitruong922 committed Dec 20, 2024
1 parent 6e91424 commit 82bfe58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
18 changes: 8 additions & 10 deletions ext/js/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,6 @@ export class Display extends EventDispatcher {
return this._frameVisible;
}

/** @type {number} */
get scrollY() {
return this._windowScroll.y;
}

/** */
async prepare() {
// Theme
Expand Down Expand Up @@ -387,10 +382,13 @@ export class Display extends EventDispatcher {
}

/**
* @param {number} y
* @param {Element} element
*/
setScrollY(y) {
this._windowScroll.toY(y);
scrollUpToElementTop(element) {
const top = this._getElementTop(element);
if (this._windowScroll.y > top) {
this._windowScroll.toY(top);
}
}

/**
Expand Down Expand Up @@ -1638,7 +1636,7 @@ export class Display extends EventDispatcher {
node = definitionNodes[definitionIndex];
}
}
let target = (index === 0 && definitionIndex <= 0) || node === null ? 0 : this.getElementTop(node);
let target = (index === 0 && definitionIndex <= 0) || node === null ? 0 : this._getElementTop(node);

if (target !== 0) {
if (this._aboveStickyHeader !== null) {
Expand Down Expand Up @@ -1773,7 +1771,7 @@ export class Display extends EventDispatcher {
* @param {Element} element
* @returns {number}
*/
getElementTop(element) {
_getElementTop(element) {
const elementRect = element.getBoundingClientRect();
const documentRect = this._contentScrollBodyElement.getBoundingClientRect();
return elementRect.top - documentRect.top;
Expand Down
5 changes: 2 additions & 3 deletions ext/js/display/element-overflow-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export class ElementOverflowController {
*/
_onToggleButtonClick(e) {
const element = /** @type {Element} */ (e.currentTarget);
const entryTop = this._display.getElementTop(element);

/** @type {(Element | null)[]} */
const collapsedElements = [
Expand All @@ -149,8 +148,8 @@ export class ElementOverflowController {
for (const collapsedElement of collapsedElements) {
if (collapsedElement === null) { continue; }
const collapsed = collapsedElement.classList.toggle('collapsed');
if (collapsed && this._display.scrollY > entryTop) {
this._display.setScrollY(entryTop);
if (collapsed) {
this._display.scrollUpToElementTop(element);
}
}
}
Expand Down

0 comments on commit 82bfe58

Please sign in to comment.