Skip to content

Commit

Permalink
showImages clean-up (honestbleeps#4695)
Browse files Browse the repository at this point in the history
* Convert media elements into classes

* Tweak expando-behavior when collaping / restoring comments

* conserveMemory: Don't run when something is fullscreen

* Clean-up expando initialization

convert .res-expando-box class .res-media-host- to data-host=['']

* Add Media#isAttached

* Add Media#supportsUnload

* Use conserveMemory on paused videos only

mutedVideoManager will usually pause them when they're outside of
viewport

* generateMedia: Return object directly from switch

* Remove some unneeded complexity

- Force move iframes instead of scrolling to it
- Media must remove itself on collapse if not able to pause

* Fix Video time restoration

* Fix generic wrapper
  • Loading branch information
larsjohnsen authored and erikdesjardins committed Mar 17, 2018
1 parent 24edda0 commit 0e78ba8
Show file tree
Hide file tree
Showing 8 changed files with 600 additions and 680 deletions.
2 changes: 1 addition & 1 deletion lib/css/modules/_showImages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ body:not(.res-showImages-displayImageCaptions) {
}

// Extras for certain text expando's
.res-media-host-wikipedia {
.res-expando-box[data-host='wikipedia'] {
.md {
padding: 5px;
max-width: none;
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/betteReddit.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ function hideLink(clickedLink, action = clickedLink.getAttribute('action')) {
if (action === 'hide') {
// Native expandos does not know that the post is being hidden, so collapse them manually
const expando = Expando.getEntryExpandoFrom(thing);
if (expando && expando.getTypes().includes('native')) expando.collapse();
if (expando && expando.types.includes('native')) expando.collapse();

if (timeout === null) $(thing.element).hide();
else hideTimer.set(clickedLink, setTimeout(() => $(thing.element).fadeOut(300), timeout));
Expand Down
8 changes: 4 additions & 4 deletions lib/modules/filteReddit/postCases/Expando.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Expando extends Case {
static parseCriterion(input: string) { return { types: input.split(/[\s|]/).filter(Boolean) }; }
static thingToCriterion(thing: *) {
const expando = thing.isPost() ? E.getEntryExpandoFrom(thing) : E.getTextExpandosFrom(thing)[0];
return expando && expando.getTypes().join(' & ') || '';
return expando && expando.types.join(' & ') || '';
}

static defaultConditions = { types: [] };
Expand All @@ -26,9 +26,9 @@ export class Expando extends Case {
validator() { return ShowImages.matchesTypes(this.value.types); }

_matches(e: ?E) {
// Treat non-loaded expando as non-existing
if (!e || !e.isLoaded()) return false;
return ShowImages.matchesTypes(this.value.types, e.getTypes());
// Treat non-ready expando as non-existing
if (!e || !e.ready) return false;
return ShowImages.matchesTypes(this.value.types, e.types);
}

evaluate(thing: *) {
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/hosts/twitter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */

import _ from 'lodash';
import { $ } from '../../vendor';
import { Host } from '../../core/host';
import { ajax } from '../../environment';
Expand Down Expand Up @@ -28,7 +29,7 @@ export default new Host('twitter', {
muted: true,
expandoClass: 'selftext',
generate: () => $dummy[0],
onAttach: () => { $dummy.replaceWith(html); },
onAttach: _.once(() => { $dummy.replaceWith(html); }),
};
},
});
Loading

0 comments on commit 0e78ba8

Please sign in to comment.