Skip to content

Commit

Permalink
Fix videos not pausing when collapsing containing comment (honestblee…
Browse files Browse the repository at this point in the history
…ps#4777)

`Thing#isContentVisible` adds the additional check that the comment itself is not collapsed.

Relevant issue: https://www.reddit.com/r/Enhancement/comments/8kgszp/videos_in_comments_keeps_playing_after_i_close/
Tested in browser: Chrome 66
  • Loading branch information
larsjohnsen authored and erikdesjardins committed May 19, 2018
1 parent ebe5e9e commit 7958e86
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/modules/showImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ export function getLinkExpando(link: HTMLAnchorElement): ?Expando {

function shouldLinkBeDeferred(element) {
const thing = Thing.from(element);
return thing && !thing.isVisible() && // No need to complete building non-visible links
return thing && !thing.isContentVisible() && // No need to complete building non-visible links
// Unless they are hidden because because of the expando filter
!(thing.filter && thing.filter.case.hasType('hasExpando'));
}
Expand Down Expand Up @@ -1019,7 +1019,7 @@ async function completeExpando(expando, thing, mediaInfo) {
$([thing, ...thing.getParents()].map(e => e.entry))
.find('.tagline > .expand, > .buttons .toggleChildren')
.click(() => {
if (thing.isVisible()) {
if (thing.isContentVisible()) {
if (wasOpen && expando.media) expando.expand();
} else {
wasOpen = expando.open;
Expand Down
11 changes: 9 additions & 2 deletions lib/utils/Thing.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,10 @@ export class Thing {

isFiltered(): boolean {
return !document.body.classList.contains('res-filters-disabled') &&
this.element.classList.contains('RESFiltered');
(
this.element.classList.contains('RESFiltered') &&
!this.element.classList.contains('res-thing-has-visible-child')
);
}

isCollapsed(): boolean {
Expand All @@ -561,11 +564,15 @@ export class Thing {

isVisible(): boolean {
return (
!(this.isFiltered() && !this.element.classList.contains('res-thing-has-visible-child')) &&
!this.isFiltered() &&
!this.isInCollapsed()
);
}

isContentVisible(): boolean {
return this.isVisible() && !this.isCollapsed();
}

isSelected() {
return this.element.classList.contains('res-selected');
}
Expand Down

0 comments on commit 7958e86

Please sign in to comment.