Skip to content

Commit

Permalink
fix(components): added posterSrc for override
Browse files Browse the repository at this point in the history
  • Loading branch information
ThornWalli committed Jun 30, 2024
1 parent 7553874 commit baddaa1
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 35 deletions.
22 changes: 19 additions & 3 deletions docs/src/components/booster-vimeo.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ Important: For using `BoosterVimeo` do not disable `@nuxt/image` via `disableNux
import BoosterVimeo from '#booster/components/BoosterVimeo';
defineProps({
url: { type: String, default: '<vimeo-url>' },
title: { type: String, default: 'Vimeo Title' },
url: {
type: String,
default: '<vimeo-url>'
},
title: {
type: String,
default: 'Vimeo Title'
},
options: {
type: String,
default() {
Expand All @@ -62,6 +68,10 @@ defineProps({
md: '50vw'
};
}
},
posterSrc: {
type: String,
default: '<poster-override-src>'
}
});
Expand All @@ -79,7 +89,8 @@ const onPlaying = () => console.log('Vimeo Player playing!');
autoplay: false,
mute: false,
posterSizes: { … },
options: { … }
options: { … },
posterSrc: '<poster-override-src>'
}
````

Expand Down Expand Up @@ -133,6 +144,11 @@ Option `playsinline` is always set, `mute` is set automatically for touch device
This is important for autoplay on mobile devices.
:::

### `posterSrc`

- Type: `String`
- default: `undefined`

## Slots

````html
Expand Down
14 changes: 13 additions & 1 deletion docs/src/components/booster-youtube.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ defineProps({
md: '50vw'
};
}
},
posterSrc: {
type: String,
default: '<poster-override-src>'
}
});
Expand All @@ -82,7 +86,8 @@ const onPlaying = () => console.log('Youtube Player playing!');
autoplay: false,
mute: false,
posterSizes: { … },
options: { … }
options: { … },
posterSrc: '<poster-override-src>'
}
````

Expand Down Expand Up @@ -145,6 +150,13 @@ This is important for autoplay on mobile devices.

Sets the host for the player.

### `posterSrc`

- Type: `String`
- default: `undefined`

Overrides the poster source.

::: info
It is recommended to use the default (<https://www.youtube-nocookie.com>).
:::
Expand Down
4 changes: 3 additions & 1 deletion playground/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const imageTextA = {
};
const videoYoutube = {
posterSrc: '/img/image-text-b.jpg',
title: 'Youtube',
url: 'https://www.youtube.com/watch?v=cLKvbhfVBUU',
text: 'Nunc odio nisl dapibus consequat recusandae doloremque nisi natus repudiandae do accusantium corrupti. Harum quisquam, maxime, perspiciatis lobortis earum iure.'
Expand Down Expand Up @@ -123,7 +124,8 @@ const imageTextB = {
const videoVimeoA = {
url: 'https://vimeo.com/288344114',
text: 'Nunc odio nisl dapibus consequat recusandae doloremque nisi natus repudiandae do accusantium corrupti. Harum quisquam, maxime, perspiciatis lobortis earum iure.'
text: 'Nunc odio nisl dapibus consequat recusandae doloremque nisi natus repudiandae do accusantium corrupti. Harum quisquam, maxime, perspiciatis lobortis earum iure.',
posterSrc: '/img/image-text-b.jpg'
};
const textB = {
Expand Down
61 changes: 43 additions & 18 deletions src/runtime/components/BoosterVimeo/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ export default {
posterDensities: {
type: [String, Number],
default: undefined
},
posterOverride: {
type: Object,
default: undefined
},
posterSrc: {
type: String,
default: undefined
}
},
emits: ['playing', 'ready'],
Expand Down Expand Up @@ -175,24 +185,39 @@ export default {
if (!this.videoData) {
return null;
}
return {
formats: this.$booster.targetFormats,
title: this.playerTitle,
sources: [
{
format: 'jpg',
src:
this.videoData &&
this.videoData.thumbnail_url?.replace(
'https://i.vimeocdn.com',
'vimeo'
),
sizes: this.posterSizes,
media: 'all',
densities: this.posterDensities
}
]
};
if (this.posterSrc) {
return {
formats: this.$booster.targetFormats,
title: this.title,
sources: [
{
src: this.posterSrc,
sizes: this.posterSizes,
media: 'all',
densities: this.posterDensities
}
]
};
} else {
return {
formats: this.$booster.targetFormats,
title: this.playerTitle,
sources: [
{
format: 'jpg',
src:
this.videoData &&
this.videoData.thumbnail_url?.replace(
'https://i.vimeocdn.com',
'vimeo'
),
sizes: this.posterSizes,
media: 'all',
densities: this.posterDensities
}
]
};
}
}
},
Expand Down
44 changes: 32 additions & 12 deletions src/runtime/components/BoosterYoutube/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export default {
posterDensities: {
type: [String, Number],
default: undefined
},
posterSrc: {
type: String,
default: undefined
}
},
Expand Down Expand Up @@ -118,18 +123,33 @@ export default {
computed: {
pictureDataset() {
return {
formats: this.$booster.targetFormats,
title: this.title,
sources: [
{
src: `/youtube/vi/${this.videoId}/maxresdefault.jpg`,
sizes: this.posterSizes,
media: 'all',
densities: this.posterDensities
}
]
};
if (this.posterSrc) {
return {
formats: this.$booster.targetFormats,
title: this.title,
sources: [
{
src: this.posterSrc,
sizes: this.posterSizes,
media: 'all',
densities: this.posterDensities
}
]
};
} else {
return {
formats: this.$booster.targetFormats,
title: this.title,
sources: [
{
src: `/youtube/vi/${this.videoId}/maxresdefault.jpg`,
sizes: this.posterSizes,
media: 'all',
densities: this.posterDensities
}
]
};
}
}
},
Expand Down

0 comments on commit baddaa1

Please sign in to comment.