|
| 1 | +# vue-lazy-youtube-video |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- a11y included |
| 8 | +- `.webp` preview img format for modern browsers that support it, with `.jpg` fallback for browsers that don't |
| 9 | +- reduced initial load size by ~1.1MB per video |
| 10 | + |
| 11 | +## 💿 Installation |
| 12 | + |
| 13 | +### Via NPM |
| 14 | + |
| 15 | +```bash |
| 16 | +$ npm install vue-lazy-youtube-video --save |
| 17 | +``` |
| 18 | + |
| 19 | +### Via Yarn |
| 20 | + |
| 21 | +```bash |
| 22 | +$ yarn add vue-lazy-youtube-video |
| 23 | +``` |
| 24 | + |
| 25 | +## Initialization |
| 26 | + |
| 27 | +### As a global component |
| 28 | + |
| 29 | +> ⚠️ It must be called before `new Vue()`. |
| 30 | +
|
| 31 | +```js |
| 32 | +import Vue from "vue"; |
| 33 | +import LazyYoutubeVideo from "vue-lazy-youtube-video"; |
| 34 | + |
| 35 | +Vue.component("LazyYoutubeVideo", LazyYoutubeVideo); |
| 36 | +``` |
| 37 | + |
| 38 | +### As a local component |
| 39 | + |
| 40 | +```js |
| 41 | +import LazyYoutubeVideo from "vue-lazy-youtube-video"; |
| 42 | + |
| 43 | +export default { |
| 44 | + name: "YourAwesomeComponent", |
| 45 | + components: { |
| 46 | + LazyYoutubeVideo |
| 47 | + } |
| 48 | +}; |
| 49 | +``` |
| 50 | + |
| 51 | +## 🚀 Usage |
| 52 | + |
| 53 | +```vue |
| 54 | +<template> |
| 55 | + <LazyYoutubeVideo url="https://www.youtube.com/watch?v=[VIDEO_ID]" /> |
| 56 | +</template> |
| 57 | +``` |
| 58 | + |
| 59 | +## ⚙️ Properties |
| 60 | + |
| 61 | +| Property | Required | Type | Default | Description | |
| 62 | +| ----------- | -------- | ------ | --------------------------- | ------------------------------------------------------------------------------------------ | |
| 63 | +| url | `true` | String | | Video `URL` in https://www.youtube.com/watch?v=VIDEO_ID format | |
| 64 | +| alt | `false` | String | `"Video alternative image"` | Value of the `alt` attribute of the thumbnail `<img />` element | |
| 65 | +| buttonLabel | `false` | String | `"Play video"` | Value of the `aria-label` attribute of the play `<button></button>` element. Improves a11y | |
| 66 | +| aspectRatio | `false` | String | `"16:9"` | Aspect ratio. It helps to save proportions of the video on different container sizes | |
| 67 | + |
| 68 | +## ⚙️ Events |
| 69 | + |
| 70 | +| Name | Type | Usage | |
| 71 | +| ----------- | ------------ | --------------------------------------------------------------------- | |
| 72 | +| videoLoaded | `() => void` | The event that is triggered when the iframe is inserted into the DOM. | |
| 73 | + |
| 74 | +## 💉 Tests |
| 75 | + |
| 76 | +Jest is used for unit-tests. |
| 77 | + |
| 78 | +You can run tests by typing this command in your console: |
| 79 | + |
| 80 | +```bash |
| 81 | +npm run test |
| 82 | +``` |
| 83 | + |
| 84 | +## Powered by |
| 85 | + |
| 86 | +- Babel |
| 87 | +- Webpack 4 |
| 88 | +- Vue |
| 89 | +- SASS |
| 90 | + |
| 91 | +## Inspiration |
| 92 | + |
| 93 | +Inspired by [Vadim Makeev](https://pepelsbey.net). Vadim created a comprehensive tutorial in which he shows how to lazyload YouTube videos properly. |
| 94 | + |
| 95 | +## 🔒 License |
| 96 | + |
| 97 | +[MIT](http://opensource.org/licenses/MIT) |
0 commit comments