mirror of
https://github.com/discourse/discourse.git
synced 2025-03-13 02:35:20 +08:00
32 lines
704 B
JavaScript
32 lines
704 B
JavaScript
import Component from "@glimmer/component";
|
|
import { tracked } from "@glimmer/tracking";
|
|
import { action } from "@ember/object";
|
|
import { htmlSafe } from "@ember/template";
|
|
|
|
export default class LazyVideo extends Component {
|
|
@tracked isLoaded = false;
|
|
|
|
@action
|
|
loadEmbed() {
|
|
if (!this.isLoaded) {
|
|
this.isLoaded = true;
|
|
this.args.onLoadedVideo?.();
|
|
}
|
|
}
|
|
|
|
@action
|
|
onKeyPress(event) {
|
|
if (event.key === "Enter") {
|
|
event.preventDefault();
|
|
this.loadEmbed();
|
|
}
|
|
}
|
|
|
|
get thumbnailStyle() {
|
|
const color = this.args.videoAttributes.dominantColor;
|
|
if (color?.match(/^[0-9A-Fa-f]+$/)) {
|
|
return htmlSafe(`background-color: #${color};`);
|
|
}
|
|
}
|
|
}
|