Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to specify image size. #3

Merged
merged 3 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default {
| alt | `false` | String | `"Video alternative image"` | Alternative text of the preview image |
| buttonLabel | `false` | String | `"Play video"` | `aria-label` attribute value of the play button. It improves a11y. |
| aspectRatio | `false` | String | `"16:9"` | Aspect ratio. It helps to save proportions of the video on different container sizes. |
| size | `false` | String | `"hqdefault"` | Video size. Available variants 'mqdefault', 'sddefault', 'hqdefault', 'maxresdefault'.|

## ⚙️ Events

Expand Down
1 change: 1 addition & 0 deletions dist/vue-lazy-youtube-video.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/VueLazyYoutubeVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<template v-if="!isVideoLoaded">
<picture>
<source
:srcset="`https://i.ytimg.com/vi_webp/${id}/hqdefault.webp`"
:srcset="`https://i.ytimg.com/vi_webp/${id}/${size}.webp`"
type="image/webp"
>
<img
class="y-video__media"
:src="`https://i.ytimg.com/vi/${id}/hqdefault.jpg`"
:src="`https://i.ytimg.com/vi/${id}/${size}.jpg`"
:alt="alt"
>
</picture>
Expand Down Expand Up @@ -54,6 +54,18 @@ export default {
const pattern = /^\d+:\d+$/;
return pattern.test(value);
}
},
size: {
type: String,
default: "hqdefault",
validator: value =>
[
"default",
"mqdefault",
"sddefault",
"hqdefault",
"maxresdefault"
].indexOf(value) !== -1
}
},
data() {
Expand Down