Skip to content

Commit

Permalink
fix tweetviewer scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Nov 9, 2022
1 parent 738ed45 commit e5b4436
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion layouts/header/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ input, textarea {
}
.tweet-viewer {
width: 580px;
max-height: 100%;
max-height: unset !important;
}
.new-tweet-avatar {
vertical-align: top
Expand Down
14 changes: 6 additions & 8 deletions scripts/tweetviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TweetViewer {
this.popstateHelper = undefined;
this.scrollHelper = undefined;
this.timelineElement = this.container.getElementsByClassName('timeline')[0];
this.moreBtn = this.container.getElementsByClassName('timeline-more')[0];

let event = new CustomEvent('clearActiveTweet');
document.dispatchEvent(event);
Expand Down Expand Up @@ -1926,12 +1927,9 @@ class TweetViewer {
that.currentLocation = location.pathname;
}
async onScroll(that) {
let tl = that.timelineElement;
let modal = tl.parentElement;
if(modal.scrollTop + 200 > tl.scrollHeight - modal.clientHeight && !that.loadingNewTweets) {
let btn = modal.getElementsByClassName('timeline-more')[0];
if(btn && that.subpage === 'tweet' && !btn.hidden) {
btn.click();
if(this.container.scrollTop + 200 > this.container.scrollHeight - this.container.clientHeight && !that.loadingNewTweets) {
if(this.moreBtn && that.subpage === 'tweet' && !this.moreBtn.hidden) {
this.moreBtn.click();
}
}
}
Expand Down Expand Up @@ -1981,11 +1979,11 @@ class TweetViewer {
this.popstateHelper = () => this.popstateChange(this);
this.scrollHelper = () => this.onScroll(this);
window.addEventListener("popstate", this.popstateHelper);
this.timelineElement.parentElement.addEventListener("scroll", this.scrollHelper, { passive: true });
this.container.addEventListener("scroll", this.scrollHelper, { passive: true });
}
close() {
document.removeEventListener('scroll', this.onscroll);
window.removeEventListener("popstate", this.popstateHelper);
this.timelineElement.parentElement.removeEventListener("scroll", this.scrollHelper);
this.container.removeEventListener("scroll", this.scrollHelper);
}
}

0 comments on commit e5b4436

Please sign in to comment.