FEATURE: Show a placeholder instead of videos in preview (#10962)

Adding a video in composer and then continuing to type into it will make the
video element flicker and restart playback on every keystroke, as the preview
is rendered. In certain configurations, this can lead to some performance
problems too.

Onebox already does the same for external videos.
This commit is contained in:
Bianca Nenciu 2020-10-20 19:01:32 +03:00 committed by GitHub
parent a65b426b8a
commit 94cbfa92e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -1545,3 +1545,13 @@ test("extractDataAttribute", (assert) => {
assert.notOk(extractDataAttribute("foo?=bar"));
assert.notOk(extractDataAttribute("https://discourse.org/?q=hello"));
});
test("video - display placeholder when previewing", (assert) => {
assert.cookedOptions(
`![baby shark|video](upload://eyPnj7UzkU0AkGkx2dx8G4YM1Jx.mp4)`,
{ previewing: true },
`<p><div class=\"onebox-placeholder-container\">
<span class=\"placeholder-icon video\"></span>
</div></p>`
);
});

View File

@ -174,7 +174,13 @@ function renderImageOrPlayableMedia(tokens, idx, options, env, slf) {
// see https://github.com/markdown-it/markdown-it/blob/master/docs/architecture.md#renderer
// handles |video and |audio alt transformations for image tags
if (split[1] === "video") {
return videoHTML(token);
if (options.discourse.previewing) {
return `<div class="onebox-placeholder-container">
<span class="placeholder-icon video"></span>
</div>`;
} else {
return videoHTML(token);
}
} else if (split[1] === "audio") {
return audioHTML(token);
}

View File

@ -188,6 +188,8 @@ export const DEFAULT_LIST = [
"span.excerpt",
"div.excerpt",
"div.video-container",
"div.onebox-placeholder-container",
"span.placeholder-icon video",
"span.hashtag",
"span.mention",
"strike",