Compare commits
445 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d434c9af16 | |||
| 9ce1dd6808 | |||
| 28347a0d7e | |||
| 5f9d090c13 | |||
| 1d4869beee | |||
| 565b68a5e2 | |||
| 285282f366 | |||
| 02456d6ba3 | |||
| 1d920a2e58 | |||
| ba67920025 | |||
| b7953ff0fc | |||
| 6b8e0f25d6 | |||
| 895299a4b3 | |||
| 2d7638a230 | |||
| ab028ea475 | |||
| 9157ac09ed | |||
| da7524438b | |||
| c64c8ac6c0 | |||
| d700bb9f02 | |||
| 2b6208565f | |||
| 6bc447b916 | |||
| 4632614ced | |||
| 01c5428fc4 | |||
| 591c045c20 | |||
| 1d7ea197f3 | |||
| 1d0d6a3a92 | |||
| 6a92e60a67 | |||
| 40395a1ff5 | |||
| 9ea3a6923d | |||
| 675a853e2e | |||
| 950786b117 | |||
| 626e1dba64 | |||
| cbd1596af4 | |||
| 6ea510c36e | |||
| 0acf228dcd | |||
| 91b19baf44 | |||
| 990d636019 | |||
| b9c792b377 | |||
| 1b835cb657 | |||
| d9f9dc770b | |||
| dca2ff8cfd | |||
| cf8e9341f2 | |||
| 5d1d247491 | |||
| fbf4d27cd4 | |||
| e0b70d53cd | |||
| 9f7725cec1 | |||
| 720cddff21 | |||
| 1c33098c42 | |||
| b256c102e8 | |||
| a3716fc491 | |||
| 14e276a11d | |||
| fc85a63af4 | |||
| f016a367b5 | |||
| d41a90f0dd | |||
| b4f24f90da | |||
| 9d751f4265 | |||
| ff2c224254 | |||
| 1135b1acac | |||
| 30ffb30a97 | |||
| e4a18a5c99 | |||
| d1a10386c0 | |||
| 4d6ac4ade1 | |||
| c2bfe489ea | |||
| 882952bba6 | |||
| 784f36921b | |||
| b7dbdc133e | |||
| 02d06c464c | |||
| cec2474295 | |||
| 6caa2f3fed | |||
| 3a01837561 | |||
| ba4bdb335a | |||
| ba236c4753 | |||
| a204f7c1dd | |||
| bacf9122de | |||
| 2fdc1eac94 | |||
| 5fd4391cd9 | |||
| 6991358428 | |||
| b050fde276 | |||
| 32444c9851 | |||
| b93dcc43ad | |||
| 6ff6ff1673 | |||
| e1ff86820c | |||
| 7d22c361d1 | |||
| 951cccb6b0 | |||
| 438e425838 | |||
| ddb5ad071e | |||
| 38060d986c | |||
| 8c74396459 | |||
| a09d63e8f8 | |||
| d74af9a73d | |||
| 60310693d3 | |||
| 5d08821c9b | |||
| 3316e40e7b | |||
| dfe5985326 | |||
| b27ad17c59 | |||
| 14b8b24e14 | |||
| 711fc5835f | |||
| 028be22dec | |||
| 3b5dc09285 | |||
| 8596e05df3 | |||
| 1aee8f53a7 | |||
| a187d07807 | |||
| 3096dd9513 | |||
| 150b07f3ef | |||
| ad7778e78d | |||
| c8e776bbea | |||
| c66dc8bf95 | |||
| ea87b9c788 | |||
| aa3378fd73 | |||
| 2cebf9b8a3 | |||
| 572aeacf5b | |||
| b5592b0fb5 | |||
| 9adf35a444 | |||
| 39ff31e3e3 | |||
| 7e82ec6d70 | |||
| f4d6a243cd | |||
| 31b5027b1e | |||
| 7750314058 | |||
| 16c134fc1e | |||
| f00e81a976 | |||
| 32a4039f7c | |||
| ba09bc32d3 | |||
| d7195d5276 | |||
| 6a6fb8d41a | |||
| c853adc760 | |||
| ca041f2e0d | |||
| 87078d7a44 | |||
| c300df5742 | |||
| 2ba56fda15 | |||
| b444aa3a98 | |||
| e8d883edba | |||
| 36b53d2cf0 | |||
| 2d4686a5f3 | |||
| 31861bd475 | |||
| c3e163741f | |||
| 1c715bc889 | |||
| 35ef42246b | |||
| cd3962ca32 | |||
| da16c55427 | |||
| bd8bacb6d5 | |||
| 0d393a5c92 | |||
| 136bb525a5 | |||
| e85737d855 | |||
| 8882317080 | |||
| 5c02205a4f | |||
| 45f7e20233 | |||
| b116e62f37 | |||
| fa6282d0e2 | |||
| 80bdf04fde | |||
| 5d2c288721 | |||
| 3caa37fdf2 | |||
| 807efcbc46 | |||
| 03d1e3d3e8 | |||
| 664e2b4893 | |||
| 4cf36bf203 | |||
| 92f3728d80 | |||
| 29d3ae0b67 | |||
| df91f7faac | |||
| 9a69ae2599 | |||
| 02321c35bc | |||
| 7c6316d824 | |||
| 776b0c4036 | |||
| fa653a8859 | |||
| b6b7db7327 | |||
| d4b4303b8e | |||
| 102fb1a32f | |||
| c77ba3ecf0 | |||
| 760f5f9469 | |||
| 0135e9c7f4 | |||
| 2426c256cc | |||
| 93eed08d14 | |||
| 5a164780d8 | |||
| 30989e4dbc | |||
| 967206c695 | |||
| 272d39c1d1 | |||
| 828abc8308 | |||
| 6455a6acc0 | |||
| 51cb03dc32 | |||
| 4d25a33cb0 | |||
| e646207ed6 | |||
| 18b3f23c69 | |||
| 98dbb2e43f | |||
| 11e48b0181 | |||
| 3a07669e30 | |||
| 3e70f32555 | |||
| b3d390076b | |||
| 80fbeeb415 | |||
| 8261ebd502 | |||
| f75820fbd3 | |||
| 8b0d84a9a4 | |||
| d582e43413 | |||
| 75082bc73f | |||
| f7e9ee56d2 | |||
| 22af7f16ea | |||
| 9076d054b9 | |||
| 4eaa1a72b5 | |||
| 6f77e21e51 | |||
| 7910fea011 | |||
| 4c1ae8f3ce | |||
| 0733133510 | |||
| 8e0cde2949 | |||
| 423b7b276f | |||
| cbd4a7cef4 | |||
| 391afe2814 | |||
| 68e3944bb8 | |||
| 2ee6ae16b2 | |||
| 8ce7425f73 | |||
| 1f63806c3f | |||
| 6cb822d56f | |||
| 9dee5acec6 | |||
| ef85cb6195 | |||
| dc8612fcd0 | |||
| 86c3cf648f | |||
| 37be1336fb | |||
| 3d7f80737b | |||
| 58a9321764 | |||
| b600f387f0 | |||
| 2a97adbec6 | |||
| 853753a3da | |||
| 405bf9ce37 | |||
| d5ea881729 | |||
| 391b9acd98 | |||
| dda2d072aa | |||
| 3c1ba2397b | |||
| adb3f35920 | |||
| a58b8bf4bb | |||
| 99a26d65cf | |||
| 4915cf0120 | |||
| 66c5780616 | |||
| e48b1d11ce | |||
| ba91f23c50 | |||
| ad4f303aa0 | |||
| 3b521f73bd | |||
| 27126b20bc | |||
| 68137aa789 | |||
| 2458eaa11b | |||
| a97008aeeb | |||
| a9b24f5e1f | |||
| a9c4e77d1b | |||
| dbe618c644 | |||
| 40f06e0b4c | |||
| 6aa21c1fae | |||
| 8015a961cb | |||
| d2fa69bca6 | |||
| d63182ecd5 | |||
| 145f2ae24f | |||
| 9c7e429b48 | |||
| 6f1366bd19 | |||
| 502d5977d7 | |||
| 353e19e746 | |||
| 12ab1ed144 | |||
| 11214caf77 | |||
| c23b4576df | |||
| a55bf00d0f | |||
| 49ed2cac4e | |||
| 44ef0bbc87 | |||
| 8f5b59c18c | |||
| d06881783d | |||
| da943b384c | |||
| ad63af5096 | |||
| 09598f07bf | |||
| ef7b30c1b8 | |||
| 5516db22c3 | |||
| 155add66bd | |||
| 39558cbabc | |||
| 4935c92b63 | |||
| 66f1f28646 | |||
| 48758bd5f0 | |||
| 2f26c80c88 | |||
| be3ffc1f96 | |||
| 3509995756 | |||
| 88dc981f4b | |||
| a65acbe43f | |||
| 6a1d6f13a2 | |||
| 71928443f3 | |||
| 10f366fe32 | |||
| fcd82088a5 | |||
| c9b6d9685c | |||
| 3069d77b74 | |||
| b7367d8275 | |||
| 99ae4eb3c5 | |||
| c7bf0c5c03 | |||
| fd353225c2 | |||
| ace682abbd | |||
| b212b25a9e | |||
| 3c127afeb9 | |||
| 84eef1d747 | |||
| 8a0086397f | |||
| 75327f2242 | |||
| 81b41be750 | |||
| 6020f95e50 | |||
| bc8a25d0da | |||
| 29e62a1e4f | |||
| b12ec094c5 | |||
| fea5e76b76 | |||
| 0cf5d25a7f | |||
| 977a8393f8 | |||
| 302fd93e86 | |||
| 70470ae8d2 | |||
| 425b39a762 | |||
| 206e3b57d1 | |||
| a34bc3ef29 | |||
| 6350b7b9e4 | |||
| 04d06f2242 | |||
| 924049aa14 | |||
| 442427ebd5 | |||
| 7954c92c0b | |||
| 5afb14283a | |||
| bfc541b880 | |||
| 426280f90c | |||
| 2e2c5ad72a | |||
| ecb091af6b | |||
| ecb882b719 | |||
| cddd9c30db | |||
| f6a4625495 | |||
| 550bd543e3 | |||
| a6ff0274a9 | |||
| 841746210a | |||
| 156abda66a | |||
| 1619510dcf | |||
| ff8dedd4ec | |||
| 637823c8ce | |||
| 01219be817 | |||
| 59e3afba03 | |||
| db05322ba2 | |||
| 74e5c78b3f | |||
| ea350f9d1d | |||
| eda192639d | |||
| 0f16a018ff | |||
| 7ca74f48bc | |||
| 5837c2d5f0 | |||
| e50b35d195 | |||
| 433b729c45 | |||
| bb7f7d5e2a | |||
| 8c44425665 | |||
| 93e3f8946a | |||
| 95431639a0 | |||
| 3e3186cfeb | |||
| 2d13ad3d39 | |||
| d7d0f5fca0 | |||
| 74ba6a96fc | |||
| e1cb2f24f5 | |||
| 59e3ef7248 | |||
| 0b1c480729 | |||
| 90dc985657 | |||
| b5456e1de7 | |||
| 976eebc2a2 | |||
| f00c279366 | |||
| b651d6f027 | |||
| b63b62f6dc | |||
| 0f08c7c13a | |||
| 97f8093a8d | |||
| 9075ea189a | |||
| c33f0995f9 | |||
| e17da7dfd4 | |||
| 299f712cc9 | |||
| f755a3c401 | |||
| 472bb479d4 | |||
| 61a24eab76 | |||
| 8b9521d5a5 | |||
| 818e1efd43 | |||
| 58f5380694 | |||
| 9d51291125 | |||
| fefcca7805 | |||
| 5204f33d45 | |||
| 0041ea3050 | |||
| f8a28b632c | |||
| 9c817cff68 | |||
| 521e8abf88 | |||
| 9fe03c7474 | |||
| c3f10e7df3 | |||
| 1b8c51f45e | |||
| 1bb4c207f1 | |||
| b6da2702a2 | |||
| fb704b945d | |||
| 71d6f59d56 | |||
| 89136bc2e6 | |||
| b6d94e000f | |||
| bfcb7133cb | |||
| 7883792ccc | |||
| def3668030 | |||
| a77d2d56f6 | |||
| 7ee041403f | |||
| 53a400027f | |||
| a2498acf7c | |||
| 28a1098c0f | |||
| 6ffaef35cf | |||
| ff105ee203 | |||
| 56c0d7bd4d | |||
| d00d31961e | |||
| b2d3ef5f38 | |||
| b2ac730572 | |||
| 3424d08d3a | |||
| 5dd9462bed | |||
| 402eb2b761 | |||
| 63d74eee68 | |||
| 166a27d094 | |||
| 4f06e2eb71 | |||
| 0b240ae7d1 | |||
| 6b0e5cd6f1 | |||
| 2463434d27 | |||
| c09b9ac01c | |||
| 15a1cdde89 | |||
| 3a1da5ad36 | |||
| 67cb324aed | |||
| 8736fa8a52 | |||
| cb4dab4250 | |||
| c56916a8e0 | |||
| 93963d3915 | |||
| e7c6f965b4 | |||
| 4f263ebb1a | |||
| c15bdabf0c | |||
| 80a077c50a | |||
| 42d72c5303 | |||
| 74e3990604 | |||
| e6e391ad6a | |||
| 12e5099c92 | |||
| 72afffbc8d | |||
| 627df20b6d | |||
| 640bc99661 | |||
| bb43ef15fe | |||
| 7907652bc9 | |||
| dce665b792 | |||
| 32bf684b17 | |||
| e978bc8690 | |||
| 91503d3698 | |||
| 1721f6e9e2 | |||
| c7b5aa9197 | |||
| 800c8e0a17 | |||
| d771da9abf | |||
| b36b92b247 | |||
| aa51719a55 | |||
| a28685536a | |||
| 400fd77d0a | |||
| a2bf974058 | |||
| 50a7c2fad6 | |||
| 95be6e721b | |||
| dc2e012cc9 | |||
| 12c6282d14 | |||
| 996075decc | |||
| 848e798809 | |||
| 35f7ee9c59 | |||
| bdd513635f | |||
| b7b2e3c0aa | |||
| 3e0a911418 |
+1
-1
@@ -4,7 +4,7 @@ root = true
|
|||||||
[*]
|
[*]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
indent_size = 4
|
indent_size = 2
|
||||||
indent_style = space
|
indent_style = space
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
{
|
{
|
||||||
"parser": "babel-eslint",
|
"parser": "babel-eslint",
|
||||||
"extends": ["airbnb-base", "prettier"],
|
"extends": ["@sampotts/eslint-config/es6"],
|
||||||
"plugins": ["simple-import-sort", "import"],
|
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"es6": true
|
"es6": true
|
||||||
@@ -11,18 +10,7 @@
|
|||||||
"jQuery": false
|
"jQuery": false
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"import/no-cycle": "warn",
|
"import/no-cycle": "warn"
|
||||||
"padding-line-between-statements": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
"blankLine": "never",
|
|
||||||
"prev": ["singleline-const", "singleline-let", "singleline-var"],
|
|
||||||
"next": ["singleline-const", "singleline-let", "singleline-var"]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"sort-imports": "off",
|
|
||||||
"import/order": "off",
|
|
||||||
"simple-import-sort/sort": "error"
|
|
||||||
},
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"sourceType": "module"
|
"sourceType": "module"
|
||||||
|
|||||||
@@ -2,3 +2,4 @@
|
|||||||
|
|
||||||
github: sampotts
|
github: sampotts
|
||||||
patreon: plyr
|
patreon: plyr
|
||||||
|
open_collective: plyr
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
PLEASE USE OUR SPECIFIC ISSUE TEMPLATES for bug reports, features and improvement suggestions.
|
PLEASE USE OUR SPECIFIC ISSUE TEMPLATES for bug reports, features and improvement suggestions.
|
||||||
|
|
||||||
Our issue tracker is not for support questions. If you need help, follow our support instructions: https://github.com/sampotts/plyr/blob/master/contributing.md#support
|
Our issue tracker is not for support questions. If you need help, follow our support instructions: https://github.com/sampotts/plyr/blob/master/CONTRIBUTING.md#support
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
### Link to related issue (if applicable)
|
### Link to related issue (if applicable)
|
||||||
|
|
||||||
### Summary of proposed changes
|
### Summary of proposed changes
|
||||||
|
|
||||||
### Checklist
|
|
||||||
- [ ] Use `develop` as the base branch
|
|
||||||
- [ ] Exclude the gulp build (`/dist` changes) from the PR
|
|
||||||
- [ ] Test on [supported browsers](https://github.com/sampotts/plyr#browser-support)
|
|
||||||
|
|||||||
+1
-1
@@ -2,8 +2,8 @@ node_modules
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
credentials.json
|
credentials.json
|
||||||
*.mp4
|
*.mp4
|
||||||
!dist/blank.mp4
|
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
*.webm
|
*.webm
|
||||||
.idea/
|
.idea/
|
||||||
|
dist/
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
tasks:
|
||||||
|
- before: npm install && npm i gulp -g
|
||||||
|
command: gulp
|
||||||
|
ports:
|
||||||
|
- port: 3000
|
||||||
|
onOpen: open-preview
|
||||||
+1
-1
@@ -7,6 +7,6 @@ credentials.json
|
|||||||
deploy.json
|
deploy.json
|
||||||
yarn.lock
|
yarn.lock
|
||||||
package-lock.json
|
package-lock.json
|
||||||
*.mp4
|
|
||||||
*.webm
|
*.webm
|
||||||
|
*.mp4
|
||||||
!dist/blank.mp4
|
!dist/blank.mp4
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"useTabs": false,
|
"useTabs": false,
|
||||||
"tabWidth": 4,
|
"tabWidth": 2,
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "all",
|
"trailingComma": "all",
|
||||||
"printWidth": 120
|
"printWidth": 120
|
||||||
|
|||||||
+4
-6
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"plugins": ["stylelint-selector-bem-pattern", "stylelint-scss"],
|
"plugins": ["stylelint-selector-bem-pattern"],
|
||||||
"extends": ["stylelint-config-recommended", "stylelint-config-sass-guidelines", "stylelint-config-prettier"],
|
"extends": ["stylelint-config-sass-guidelines", "stylelint-config-prettier"],
|
||||||
|
"customSyntax": "postcss-scss",
|
||||||
"rules": {
|
"rules": {
|
||||||
"selector-class-pattern": null,
|
"selector-class-pattern": null,
|
||||||
"selector-no-qualifying-type": [
|
"selector-no-qualifying-type": [
|
||||||
@@ -9,10 +10,7 @@
|
|||||||
"ignore": ["attribute", "class"]
|
"ignore": ["attribute", "class"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"string-no-newline": null,
|
"max-nesting-depth": 4,
|
||||||
"indentation": 4,
|
|
||||||
"string-quotes": "single",
|
|
||||||
"max-nesting-depth": 2,
|
|
||||||
"plugin/selector-bem-pattern": {
|
"plugin/selector-bem-pattern": {
|
||||||
"preset": "bem",
|
"preset": "bem",
|
||||||
"componentName": "(([a-z0-9]+(?!-$)-?)+)",
|
"componentName": "(([a-z0-9]+(?!-$)-?)+)",
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js: lts/*
|
|
||||||
|
|
||||||
script:
|
|
||||||
- bash .travis/prevent-base-master.sh
|
|
||||||
- bash .travis/omit-dist.sh
|
|
||||||
- npm run lint
|
|
||||||
- npm run build
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ $TRAVIS_BRANCH == "develop" ] && $(git diff --name-only $TRAVIS_COMMIT_RANGE | grep -qE "^(demo/)?dist/"); then
|
|
||||||
echo 'Build output ("dist" and "demo/dist") not permitted in develop' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
if [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ $TRAVIS_BRANCH == "master" ] && $(git diff --name-only $TRAVIS_COMMIT_RANGE | grep -q "^src/"); then
|
|
||||||
echo 'The base branch for pull requests must be "develop"' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
Vendored
+4
-4
@@ -2,11 +2,11 @@
|
|||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
// for the documentation about the extensions.json format
|
// for the documentation about the extensions.json format
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
|
|
||||||
"dbaeumer.vscode-eslint",
|
"dbaeumer.vscode-eslint",
|
||||||
"wix.vscode-import-cost",
|
|
||||||
"esbenp.prettier-vscode",
|
"esbenp.prettier-vscode",
|
||||||
"shinnn.stylelint",
|
"wayou.vscode-todo-highlight",
|
||||||
"wayou.vscode-todo-highlight"
|
"wix.vscode-import-cost",
|
||||||
|
"stylelint.vscode-stylelint",
|
||||||
|
"pflannery.vscode-versionlens"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+1275
File diff suppressed because it is too large
Load Diff
@@ -7,15 +7,17 @@ We welcome bug reports, feature requests and pull requests. If you want to help
|
|||||||
Before asking questions, read our [documentation](https://github.com/sampotts/plyr) and [FAQ](https://github.com/sampotts/plyr/wiki/FAQ).
|
Before asking questions, read our [documentation](https://github.com/sampotts/plyr) and [FAQ](https://github.com/sampotts/plyr/wiki/FAQ).
|
||||||
|
|
||||||
If these doesn't answer your question
|
If these doesn't answer your question
|
||||||
* Use [Stack Overflow](https://stackoverflow.com/) for questions that doesn't directly involve Plyr. This includes for example how to use Javascript, CSS or HTML5 media in general, and how to use other frameworks, libraries and technology.
|
|
||||||
* Use [our Slack](https://bit.ly/plyr-chat) if you need help using Plyr or have questions about Plyr.
|
- Use [Stack Overflow](https://stackoverflow.com/) for questions that doesn't directly involve Plyr. This includes for example how to use Javascript, CSS or HTML5 media in general, and how to use other frameworks, libraries and technology.
|
||||||
|
- Use [our Slack](https://bit.ly/plyr-chat) if you need help using Plyr or have questions about Plyr.
|
||||||
|
|
||||||
## Commenting
|
## Commenting
|
||||||
|
|
||||||
When commenting, keep a civil tone and stay on topic. Don't ask for [support](#support), or post "+1" or "I agree" type of comments. Use the emojis instead.
|
When commenting, keep a civil tone and stay on topic. Don't ask for [support](#support), or post "+1" or "I agree" type of comments. Use the emojis instead.
|
||||||
|
|
||||||
Asking for the status on issues is discouraged. Unless someone has explicitly said in an issue that it's work in progress, most likely that means no one is working on it. We have a lot to do, and it may not be a top priority for us.
|
Asking for the status on issues is discouraged. Unless someone has explicitly said in an issue that it's work in progress, most likely that means no one is working on it. We have a lot to do, and it may not be a top priority for us.
|
||||||
|
|
||||||
We *may* moderate discussions. We do this to avoid threads being "hijacked", to avoid confusion in case the content is misleading or outdated, and to avoid bothering people with github notifications.
|
We _may_ moderate discussions. We do this to avoid threads being "hijacked", to avoid confusion in case the content is misleading or outdated, and to avoid bothering people with github notifications.
|
||||||
|
|
||||||
## Creating issues
|
## Creating issues
|
||||||
|
|
||||||
@@ -23,18 +25,30 @@ Please follow the instructions in our issue templates. Don't use github issues t
|
|||||||
|
|
||||||
## Contributing features and documentation
|
## Contributing features and documentation
|
||||||
|
|
||||||
* If you want to add a feature or make critical changes, you may want to ensure that this is something we also want (so you don't waste your time). Ask us about this in the corresponding issue if there is one, or on [our Slack](https://bit.ly/plyr-chat) otherwise.
|
- If you want to add a feature or make critical changes, you may want to ensure that this is something we also want (so you don't waste your time). Ask us about this in the corresponding issue if there is one, or on [our Slack](https://bit.ly/plyr-chat) otherwise.
|
||||||
|
|
||||||
* Fork Plyr, and create a new branch in your fork, based on the **develop** branch
|
- Fork Plyr, and create a new branch in your fork, based on the **develop** branch
|
||||||
|
|
||||||
* To test locally, you can use the demo. First make sure you have installed the dependencies with `npm install` or `yarn`. Run `gulp` to build while you are working, and run a local server from the repository root directory. If you have Python installed, this command should work: `python -m SimpleHTTPServer 8080`. Then go to `http://localhost:8080/demo/`
|
- To test locally, you can use the demo site. First make sure you have installed the dependencies with `npm install` or `yarn`. Run `gulp` to build and it will run a local web server for development and watch for any changes.
|
||||||
|
|
||||||
* Develop and test your modifications.
|
### Online one-click setup for contributing
|
||||||
|
|
||||||
* Preferably commit your changes as independent logical chunks, with meaningful messages. Make sure you do not commit unnecessary files or changes, such as the build output, or logging and breakpoints you added for testing.
|
You can use Gitpod (a free online VS Code-like IDE) for contributing. With a single click it will launch a workspace and automatically:
|
||||||
|
|
||||||
* If your modifications changes the documented behavior or add new features, document these changes in readme.md.
|
- clone the plyr repo.
|
||||||
|
- install the dependencies with `yarn install` in root directory and "demo" directory.
|
||||||
|
- run `gulp` in root directory to start the dev server.
|
||||||
|
|
||||||
* When finished, push the changes to your GitHub repository and send a pull request to **develop**. Describe what your PR does.
|
So that you can start straight away.
|
||||||
|
|
||||||
* If the Travis build fails, or if you get a code review with change requests, you can fix these by pushing new or rebased commits to the branch.
|
[](https://gitpod.io/from-referrer/)
|
||||||
|
|
||||||
|
- Develop and test your modifications.
|
||||||
|
|
||||||
|
- Preferably commit your changes as independent logical chunks, with meaningful messages. Make sure you do not commit unnecessary files or changes, such as the build output, or logging and breakpoints you added for testing.
|
||||||
|
|
||||||
|
- If your modifications changes the documented behavior or add new features, document these changes in [README.md](README.md).
|
||||||
|
|
||||||
|
- When finished, push the changes to your GitHub repository and send a pull request. Describe what your PR does.
|
||||||
|
|
||||||
|
- If the Travis build fails, or if you get a code review with change requests, you can fix these by pushing new or rebased commits to the branch.
|
||||||
@@ -35,7 +35,7 @@ controls: [
|
|||||||
|
|
||||||
### Internationalization using default controls
|
### Internationalization using default controls
|
||||||
|
|
||||||
You can provide an `i18n` object as one of your options when initialising the plugin which we be used when rendering the controls.
|
You can provide an `i18n` object as one of your options when initializing the plugin which we be used when rendering the controls.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
+176
-39
@@ -1,6 +1,11 @@
|
|||||||
|
| 🎉 | [Plyr is merging into Vidstack](https://github.com/sampotts/plyr/issues/2408) | 🎉 |
|
||||||
|
| :-: | :---------------------------------------------------------------------------: | :-- |
|
||||||
|
|
||||||
Plyr is a simple, lightweight, accessible and customizable HTML5, YouTube and Vimeo media player that supports [_modern_](#browser-support) browsers.
|
Plyr is a simple, lightweight, accessible and customizable HTML5, YouTube and Vimeo media player that supports [_modern_](#browser-support) browsers.
|
||||||
|
|
||||||
[Checkout the demo](https://plyr.io) - [Donate](#donate) - [Slack](https://bit.ly/plyr-chat) - [](https://badge.fury.io/js/plyr)
|
[Checkout the demo](https://plyr.io) - [Donate](#donate) - [Slack](https://bit.ly/plyr--chat)
|
||||||
|
|
||||||
|
[](https://badge.fury.io/js/plyr) [](https://gitpod.io/#https://github.com/sampotts/plyr) [](https://opencollective.com/plyr)
|
||||||
|
|
||||||
[](https://plyr.io)
|
[](https://plyr.io)
|
||||||
|
|
||||||
@@ -8,7 +13,7 @@ Plyr is a simple, lightweight, accessible and customizable HTML5, YouTube and Vi
|
|||||||
|
|
||||||
- 📼 **HTML Video & Audio, YouTube & Vimeo** - support for the major formats
|
- 📼 **HTML Video & Audio, YouTube & Vimeo** - support for the major formats
|
||||||
- 💪 **Accessible** - full support for VTT captions and screen readers
|
- 💪 **Accessible** - full support for VTT captions and screen readers
|
||||||
- 🔧 **[Customisable](#html)** - make the player look how you want with the markup you want
|
- 🔧 **[Customizable](#html)** - make the player look how you want with the markup you want
|
||||||
- 😎 **Clean HTML** - uses the _right_ elements. `<input type="range">` for volume and `<progress>` for progress and well, `<button>`s for buttons. There's no
|
- 😎 **Clean HTML** - uses the _right_ elements. `<input type="range">` for volume and `<progress>` for progress and well, `<button>`s for buttons. There's no
|
||||||
`<span>` or `<a href="#">` button hacks
|
`<span>` or `<a href="#">` button hacks
|
||||||
- 📱 **Responsive** - works with any screen size
|
- 📱 **Responsive** - works with any screen size
|
||||||
@@ -25,11 +30,11 @@ Plyr is a simple, lightweight, accessible and customizable HTML5, YouTube and Vi
|
|||||||
- 🌎 **i18n support** - support for internationalization of controls
|
- 🌎 **i18n support** - support for internationalization of controls
|
||||||
- 👌 **[Preview thumbnails](#preview-thumbnails)** - support for displaying preview thumbnails
|
- 👌 **[Preview thumbnails](#preview-thumbnails)** - support for displaying preview thumbnails
|
||||||
- 🤟 **No frameworks** - written in "vanilla" ES6 JavaScript, no jQuery required
|
- 🤟 **No frameworks** - written in "vanilla" ES6 JavaScript, no jQuery required
|
||||||
- 💁♀️ **SASS** - to include in your build processes
|
- 💁♀️ **Sass** - to include in your build processes
|
||||||
|
|
||||||
### Demos
|
### Demos
|
||||||
|
|
||||||
You can try Plyr in Codepen using our minimal templates: [HTML5 video](https://codepen.io/pen?template=bKeqpr), [HTML5 audio](https://codepen.io/pen?template=rKLywR), [YouTube](https://codepen.io/pen?template=GGqbbJ), [Vimeo](https://codepen.io/pen?template=bKeXNq). For Streaming we also have example integrations with: [Dash.js](https://codepen.io/pen?template=zaBgBy), [Hls.js](https://codepen.io/pen?template=oyLKQb) and [Shaka Player](https://codepen.io/pen?template=ZRpzZO)
|
You can try Plyr in Codepen using our minimal templates: [HTML5 video](https://codepen.io/pen?template=bKeqpr), [HTML5 audio](https://codepen.io/pen?template=rKLywR), [YouTube](https://codepen.io/pen?template=GGqbbJ), [Vimeo](https://codepen.io/pen?template=bKeXNq). For Streaming we also have example integrations with: [Dash.js](https://codepen.io/pen?template=GRoogML), [Hls.js](https://codepen.io/pen?template=oyLKQb) and [Shaka Player](https://codepen.io/pen?template=ZRpzZO)
|
||||||
|
|
||||||
# Quick setup
|
# Quick setup
|
||||||
|
|
||||||
@@ -40,7 +45,7 @@ Plyr extends upon the standard [HTML5 media element](https://developer.mozilla.o
|
|||||||
### HTML5 Video
|
### HTML5 Video
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<video poster="/path/to/poster.jpg" id="player" playsinline controls>
|
<video id="player" playsinline controls data-poster="/path/to/poster.jpg">
|
||||||
<source src="/path/to/video.mp4" type="video/mp4" />
|
<source src="/path/to/video.mp4" type="video/mp4" />
|
||||||
<source src="/path/to/video.webm" type="video/webm" />
|
<source src="/path/to/video.webm" type="video/webm" />
|
||||||
|
|
||||||
@@ -49,6 +54,8 @@ Plyr extends upon the standard [HTML5 media element](https://developer.mozilla.o
|
|||||||
</video>
|
</video>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Note**: The poster image should be specified using `data-poster`. This is to prevent it [being downloaded twice](https://github.com/sampotts/plyr/issues/1531). If you're sure the image will be cached, you can still use the `poster` attribute for true progressive enhancement.
|
||||||
|
|
||||||
### HTML5 Audio
|
### HTML5 Audio
|
||||||
|
|
||||||
```html
|
```html
|
||||||
@@ -116,7 +123,7 @@ import Plyr from 'plyr';
|
|||||||
const player = new Plyr('#player');
|
const player = new Plyr('#player');
|
||||||
```
|
```
|
||||||
|
|
||||||
Alertnatively you can include the `plyr.js` script before the closing `</body>` tag and then in your JS create a new instance of Plyr as below.
|
Alternatively you can include the `plyr.js` script before the closing `</body>` tag and then in your JS create a new instance of Plyr as below.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="path/to/plyr.js"></script>
|
<script src="path/to/plyr.js"></script>
|
||||||
@@ -127,21 +134,21 @@ Alertnatively you can include the `plyr.js` script before the closing `</body>`
|
|||||||
|
|
||||||
See [initialising](#initialising) for more information on advanced setups.
|
See [initialising](#initialising) for more information on advanced setups.
|
||||||
|
|
||||||
You can use our CDN (provided by [Fastly](https://www.fastly.com/)) for the JavaScript. There's 2 versions; one with and one without [polyfills](#polyfills). My recommendation would be to manage polyfills seperately as part of your application but to make life easier you can use the polyfilled build.
|
You can use our CDN (provided by [Fastly](https://www.fastly.com/)) for the JavaScript. There's 2 versions; one with and one without [polyfills](#polyfills). My recommendation would be to manage polyfills separately as part of your application but to make life easier you can use the polyfilled build.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="https://cdn.plyr.io/3.5.6/plyr.js"></script>
|
<script src="https://cdn.plyr.io/3.7.0/plyr.js"></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
...or...
|
...or...
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="https://cdn.plyr.io/3.5.6/plyr.polyfilled.js"></script>
|
<script src="https://cdn.plyr.io/3.7.0/plyr.polyfilled.js"></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
## CSS
|
## CSS
|
||||||
|
|
||||||
Include the `plyr.css` stylsheet into your `<head>`.
|
Include the `plyr.css` stylesheet into your `<head>`.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<link rel="stylesheet" href="path/to/plyr.css" />
|
<link rel="stylesheet" href="path/to/plyr.css" />
|
||||||
@@ -150,13 +157,13 @@ Include the `plyr.css` stylsheet into your `<head>`.
|
|||||||
If you want to use our CDN (provided by [Fastly](https://www.fastly.com/)) for the default CSS, you can use the following:
|
If you want to use our CDN (provided by [Fastly](https://www.fastly.com/)) for the default CSS, you can use the following:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<link rel="stylesheet" href="https://cdn.plyr.io/3.5.6/plyr.css" />
|
<link rel="stylesheet" href="https://cdn.plyr.io/3.7.0/plyr.css" />
|
||||||
```
|
```
|
||||||
|
|
||||||
## SVG Sprite
|
## SVG Sprite
|
||||||
|
|
||||||
The SVG sprite is loaded automatically from our CDN (provided by [Fastly](https://www.fastly.com/)). To change this, see the [options](#options) below. For
|
The SVG sprite is loaded automatically from our CDN (provided by [Fastly](https://www.fastly.com/)). To change this, see the [options](#options) below. For
|
||||||
reference, the CDN hosted SVG sprite can be found at `https://cdn.plyr.io/3.5.6/plyr.svg`.
|
reference, the CDN hosted SVG sprite can be found at `https://cdn.plyr.io/3.7.0/plyr.svg`.
|
||||||
|
|
||||||
# Ads
|
# Ads
|
||||||
|
|
||||||
@@ -168,12 +175,108 @@ Plyr has partnered up with [vi.ai](https://vi.ai/publisher-video-monetization/?a
|
|||||||
|
|
||||||
Any questions regarding the ads can be sent straight to vi.ai and any issues with rendering raised through GitHub issues.
|
Any questions regarding the ads can be sent straight to vi.ai and any issues with rendering raised through GitHub issues.
|
||||||
|
|
||||||
|
If you do not wish to use Vi, you can set your own `ads.tagUrl` [option](#options).
|
||||||
|
|
||||||
# Advanced
|
# Advanced
|
||||||
|
|
||||||
## SASS
|
## Customizing the CSS
|
||||||
|
|
||||||
You can use `bundle.scss` file included in `/src` as part of your build and change variables to suit your design. The SASS require you to
|
If you want to change any design tokens used for the rendering of the player, you can do so using [CSS Custom Properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties).
|
||||||
use the [autoprefixer](https://www.npmjs.com/package/gulp-autoprefixer) plugin (you should be already!) as all declarations use the W3C definitions.
|
|
||||||
|
Here's a list of the properties and what they are used for:
|
||||||
|
|
||||||
|
| Name | Description | Default / Fallback |
|
||||||
|
| ---------------------------------------------- | ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
|
||||||
|
| `--plyr-color-main` | The primary UI color. |  `#00b3ff` |
|
||||||
|
| `--plyr-video-background` | The background color of video and poster wrappers for using alpha channel videos and poster images. | `rgba(0, 0, 0, 1)` |
|
||||||
|
| `--plyr-tab-focus-color` | The color used for the dotted outline when an element is `:focus-visible` (equivalent) keyboard focus. | `--plyr-color-main` |
|
||||||
|
| `--plyr-badge-background` | The background color for badges in the menu. |  `#4a5464` |
|
||||||
|
| `--plyr-badge-text-color` | The text color for badges. |  `#ffffff` |
|
||||||
|
| `--plyr-badge-border-radius` | The border radius used for badges. | `2px` |
|
||||||
|
| `--plyr-tab-focus-color` | The color used to highlight tab (keyboard) focus. | `--plyr-color-main` |
|
||||||
|
| `--plyr-captions-background` | The color for the background of captions. | `rgba(0, 0, 0, 0.8)` |
|
||||||
|
| `--plyr-captions-text-color` | The color used for the captions text. |  `#ffffff` |
|
||||||
|
| `--plyr-control-icon-size` | The size of the icons used in the controls. | `18px` |
|
||||||
|
| `--plyr-control-spacing` | The space between controls (sometimes used in a multiple - e.g. `10px / 2 = 5px`). | `10px` |
|
||||||
|
| `--plyr-control-padding` | The padding inside controls. | `--plyr-control-spacing * 0.7` (`7px`) |
|
||||||
|
| `--plyr-control-radius` | The border radius used on controls. | `3px` |
|
||||||
|
| `--plyr-control-toggle-checked-background` | The background color used for checked menu items. | `--plyr-color-main` |
|
||||||
|
| `--plyr-video-controls-background` | The background for the video controls. | `linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.75))` |
|
||||||
|
| `--plyr-video-control-color` | The text/icon color for video controls. |  `#ffffff` |
|
||||||
|
| `--plyr-video-control-color-hover` | The text/icon color used when video controls are `:hover`, `:focus` and `:focus-visible` (equivalent). |  `#ffffff` |
|
||||||
|
| `--plyr-video-control-background-hover` | The background color used when video controls are `:hover`, `:focus` and `:focus-visible` (equivalent). | `--plyr-color-main` |
|
||||||
|
| `--plyr-audio-controls-background` | The background for the audio controls. |  `#ffffff` |
|
||||||
|
| `--plyr-audio-control-color` | The text/icon color for audio controls. |  `#4a5464` |
|
||||||
|
| `--plyr-audio-control-color-hover` | The text/icon color used when audio controls are `:hover`, `:focus` and `:focus-visible` (equivalent). |  `#ffffff` |
|
||||||
|
| `--plyr-audio-control-background-hover` | The background color used when video controls are `:hover`, `:focus` and `:focus-visible` (equivalent). | `--plyr-color-main` |
|
||||||
|
| `--plyr-menu-background` | The background color for menus. | `rgba(255, 255, 255, 0.9)` |
|
||||||
|
| `--plyr-menu-color` | The text/icon color for menu items. |  `#4a5464` |
|
||||||
|
| `--plyr-menu-shadow` | The shadow used on menus. | `0 1px 2px rgba(0, 0, 0, 0.15)` |
|
||||||
|
| `--plyr-menu-radius` | The border radius on the menu. | `4px` |
|
||||||
|
| `--plyr-menu-arrow-size` | The size of the arrow on the bottom of the menu. | `6px` |
|
||||||
|
| `--plyr-menu-item-arrow-color` | The color of the arrows in the menu. |  `#728197` |
|
||||||
|
| `--plyr-menu-item-arrow-size` | The size of the arrows in the menu. | `4px` |
|
||||||
|
| `--plyr-menu-border-color` | The border color for the bottom of the back button in the top of the sub menu pages. |  `#dcdfe5` |
|
||||||
|
| `--plyr-menu-border-shadow-color` | The shadow below the border of the back button in the top of the sub menu pages. |  `#ffffff` |
|
||||||
|
| `--plyr-progress-loading-size` | The size of the stripes in the loading state in the scrubber. | `25px` |
|
||||||
|
| `--plyr-progress-loading-background` | The background color on the loading state in the scrubber. | `rgba(35, 40, 47, 0.6)` |
|
||||||
|
| `--plyr-video-progress-buffered-background` | The fill color for the buffer indication in the scrubber for video. | `rgba(255, 255, 255, 0.25)` |
|
||||||
|
| `--plyr-audio-progress-buffered-background` | The fill color for the buffer indication in the scrubber for audio. | `rgba(193, 200, 209, 0.6)` |
|
||||||
|
| `--plyr-range-thumb-height` | The height of the scrubber handle/thumb. | `13px` |
|
||||||
|
| `--plyr-range-thumb-background` | The background of the scrubber handle/thumb. |  `#ffffff` |
|
||||||
|
| `--plyr-range-thumb-shadow` | The shadow of the scrubber handle/thumb. | `0 1px 1px rgba(215, 26, 18, 0.15), 0 0 0 1px rgba(215, 26, 18, 0.2)` |
|
||||||
|
| `--plyr-range-thumb-active-shadow-width` | The width of the shadow when the scrubber handle/thumb is `:active` (pressed). | `3px` |
|
||||||
|
| `--plyr-range-track-height` | The height of the scrubber/progress track. | `5px` |
|
||||||
|
| `--plyr-range-fill-background` | The fill color of the scrubber/progress. | `--plyr-color-main` |
|
||||||
|
| `--plyr-video-range-track-background` | The background of the scrubber/progress. | `--plyr-video-progress-buffered-background` |
|
||||||
|
| `--plyr-video-range-thumb-active-shadow-color` | The color of the shadow when the video scrubber handle/thumb is `:active` (pressed). | `rgba(255, 255, 255, 0.5)` |
|
||||||
|
| `--plyr-audio-range-track-background` | The background of the scrubber/progress. | `--plyr-video-progress-buffered-background` |
|
||||||
|
| `--plyr-audio-range-thumb-active-shadow-color` | The color of the shadow when the audio scrubber handle/thumb is `:active` (pressed). | `rgba(215, 26, 18, 0.1)` |
|
||||||
|
| `--plyr-tooltip-background` | The background color for tooltips. | `rgba(255, 255, 255, 0.9)` |
|
||||||
|
| `--plyr-tooltip-color` | The text color for tooltips. |  `#4a5464` |
|
||||||
|
| `--plyr-tooltip-padding` | The padding for tooltips. | `calc(var(--plyr-control-spacing) / 2))` |
|
||||||
|
| `--plyr-tooltip-arrow-size` | The size of the arrow under tooltips. | `4px` |
|
||||||
|
| `--plyr-tooltip-radius` | The border radius on tooltips. | `3px` |
|
||||||
|
| `--plyr-tooltip-shadow` | The shadow on tooltips. | `0 1px 2px rgba(0, 0, 0, 0.15)` |
|
||||||
|
| `--plyr-font-family` | The font family used in the player. | |
|
||||||
|
| `--plyr-font-size-base` | The base font size. Mainly used for captions. | `15px` |
|
||||||
|
| `--plyr-font-size-small` | The smaller font size. Mainly used for captions. | `13px` |
|
||||||
|
| `--plyr-font-size-large` | The larger font size. Mainly used for captions. | `18px` |
|
||||||
|
| `--plyr-font-size-xlarge` | The even larger font size. Mainly used for captions. | `21px` |
|
||||||
|
| `--plyr-font-size-time` | The font size for the time. | `--plyr-font-size-small` |
|
||||||
|
| `--plyr-font-size-menu` | The font size used in the menu. | `--plyr-font-size-small` |
|
||||||
|
| `--plyr-font-size-badge` | The font size used for badges. | `9px` |
|
||||||
|
| `--plyr-font-weight-regular` | The regular font weight. | `400` |
|
||||||
|
| `--plyr-font-weight-bold` | The bold font weight. | `600` |
|
||||||
|
| `--plyr-line-height` | The line height used within the player. | `1.7` |
|
||||||
|
| `--plyr-font-smoothing` | Whether to enable font antialiasing within the player. | `false` |
|
||||||
|
|
||||||
|
You can set them in your CSS for all players:
|
||||||
|
|
||||||
|
```css
|
||||||
|
:root {
|
||||||
|
--plyr-color-main: #1ac266;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
...or for a specific class name:
|
||||||
|
|
||||||
|
```css
|
||||||
|
.player {
|
||||||
|
--plyr-color-main: #1ac266;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
...or in your HTML:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<video class="player" style="--plyr-color-main: #1ac266;">...</video>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sass
|
||||||
|
|
||||||
|
You can use `plyr.scss` file included in `/src/sass` as part of your build and change variables to suit your design. The Sass requires you to
|
||||||
|
use [autoprefixer](https://www.npmjs.com/package/gulp-autoprefixer) (you should be already!) as all declarations use the W3C definitions.
|
||||||
|
|
||||||
The HTML markup uses the BEM methodology with `plyr` as the block, e.g. `.plyr__controls`. You can change the class hooks in the options to match any custom CSS
|
The HTML markup uses the BEM methodology with `plyr` as the block, e.g. `.plyr__controls`. You can change the class hooks in the options to match any custom CSS
|
||||||
you write. Check out the JavaScript source for more on this.
|
you write. Check out the JavaScript source for more on this.
|
||||||
@@ -242,7 +345,7 @@ The HTMLElement or string selector can be the target `<video>`, `<audio>`, or `<
|
|||||||
You have two choices here. You can either use a simple array loop to map the constructor:
|
You have two choices here. You can either use a simple array loop to map the constructor:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const players = Array.from(document.querySelectorAll('.js-player')).map(p => new Plyr(p));
|
const players = Array.from(document.querySelectorAll('.js-player')).map((p) => new Plyr(p));
|
||||||
```
|
```
|
||||||
|
|
||||||
...or use a static method where you can pass a [CSS string selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors), a [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList), an [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) of [HTMLElement](https://developer.mozilla.org/en/docs/Web/API/HTMLElement), or a [JQuery](https://jquery.com) object:
|
...or use a static method where you can pass a [CSS string selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors), a [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList), an [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) of [HTMLElement](https://developer.mozilla.org/en/docs/Web/API/HTMLElement), or a [JQuery](https://jquery.com) object:
|
||||||
@@ -275,8 +378,8 @@ Note the single quotes encapsulating the JSON and double quotes on the object ke
|
|||||||
| -------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| -------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `enabled` | Boolean | `true` | Completely disable Plyr. This would allow you to do a User Agent check or similar to programmatically enable or disable Plyr for a certain UA. Example below. |
|
| `enabled` | Boolean | `true` | Completely disable Plyr. This would allow you to do a User Agent check or similar to programmatically enable or disable Plyr for a certain UA. Example below. |
|
||||||
| `debug` | Boolean | `false` | Display debugging information in the console |
|
| `debug` | Boolean | `false` | Display debugging information in the console |
|
||||||
| `controls` | Array, Function or Element | `['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'captions', 'settings', 'pip', 'airplay', 'fullscreen']` | If a function is passed, it is assumed your method will return either an element or HTML string for the controls. Three arguments will be passed to your function; `id` (the unique id for the player), `seektime` (the seektime step in seconds), and `title` (the media title). See [controls.md](controls.md) for more info on how the html needs to be structured. |
|
| `controls` | Array, Function or Element | `['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'captions', 'settings', 'pip', 'airplay', 'fullscreen']` | If a function is passed, it is assumed your method will return either an element or HTML string for the controls. Three arguments will be passed to your function; `id` (the unique id for the player), `seektime` (the seektime step in seconds), and `title` (the media title). See [CONTROLS.md](CONTROLS.md) for more info on how the html needs to be structured. |
|
||||||
| `settings` | Array | `['captions', 'quality', 'speed', 'loop']` | If you're using the default controls are used then you can specify which settings to show in the menu |
|
| `settings` | Array | `['captions', 'quality', 'speed', 'loop']` | If the default controls are used, you can specify which settings to show in the menu |
|
||||||
| `i18n` | Object | See [defaults.js](/src/js/config/defaults.js) | Used for internationalization (i18n) of the text within the UI. |
|
| `i18n` | Object | See [defaults.js](/src/js/config/defaults.js) | Used for internationalization (i18n) of the text within the UI. |
|
||||||
| `loadSprite` | Boolean | `true` | Load the SVG sprite specified as the `iconUrl` option (if a URL). If `false`, it is assumed you are handling sprite loading yourself. |
|
| `loadSprite` | Boolean | `true` | Load the SVG sprite specified as the `iconUrl` option (if a URL). If `false`, it is assumed you are handling sprite loading yourself. |
|
||||||
| `iconUrl` | String | `null` | Specify a URL or path to the SVG sprite. See the [SVG section](#svg) for more info. |
|
| `iconUrl` | String | `null` | Specify a URL or path to the SVG sprite. See the [SVG section](#svg) for more info. |
|
||||||
@@ -298,18 +401,20 @@ Note the single quotes encapsulating the JSON and double quotes on the object ke
|
|||||||
| `invertTime` | Boolean | `true` | Display the current time as a countdown rather than an incremental counter. |
|
| `invertTime` | Boolean | `true` | Display the current time as a countdown rather than an incremental counter. |
|
||||||
| `toggleInvert` | Boolean | `true` | Allow users to click to toggle the above. |
|
| `toggleInvert` | Boolean | `true` | Allow users to click to toggle the above. |
|
||||||
| `listeners` | Object | `null` | Allows binding of event listeners to the controls before the default handlers. See the `defaults.js` for available listeners. If your handler prevents default on the event (`event.preventDefault()`), the default handler will not fire. |
|
| `listeners` | Object | `null` | Allows binding of event listeners to the controls before the default handlers. See the `defaults.js` for available listeners. If your handler prevents default on the event (`event.preventDefault()`), the default handler will not fire. |
|
||||||
| `captions` | Object | `{ active: false, language: 'auto', update: false }` | `active`: Toggles if captions should be active by default. `language`: Sets the default language to load (if available). 'auto' uses the browser language. `update`: Listen to changes to tracks and update menu. This is needed for some streaming libraries, but can result in unselectable language options). |
|
| `captions` | Object | `{ active: false, language: 'auto', update: false }` | `active`: Toggles if captions should be active by default. `language`: Sets the default language to load (if available). 'auto' uses the browser language. `update`: Listen to changes to tracks and update menu. This is needed for some streaming libraries, but can result in non-selectable language options). |
|
||||||
| `fullscreen` | Object | `{ enabled: true, fallback: true, iosNative: false }` | `enabled`: Toggles whether fullscreen should be enabled. `fallback`: Allow fallback to a full-window solution (`true`/`false`/`'force'`). `iosNative`: whether to use native iOS fullscreen when entering fullscreen (no custom controls) |
|
| `fullscreen` | Object | `{ enabled: true, fallback: true, iosNative: false, container: null }` | `enabled`: Toggles whether fullscreen should be enabled. `fallback`: Allow fallback to a full-window solution (`true`/`false`/`'force'`). `iosNative`: whether to use native iOS fullscreen when entering fullscreen (no custom controls). `container`: A selector for an ancestor of the player element, allows contextual content to remain visual in fullscreen mode. Non-ancestors are ignored. |
|
||||||
| `ratio` | String | `null` | Force an aspect ratio for all videos. The format is `'w:h'` - e.g. `'16:9'` or `'4:3'`. If this is not specified then the default for HTML5 and Vimeo is to use the native resolution of the video. As dimensions are not available from YouTube via SDK, 16:9 is forced as a sensible default. |
|
| `ratio` | String | `null` | Force an aspect ratio for all videos. The format is `'w:h'` - e.g. `'16:9'` or `'4:3'`. If this is not specified then the default for HTML5 and Vimeo is to use the native resolution of the video. As dimensions are not available from YouTube via SDK, 16:9 is forced as a sensible default. |
|
||||||
| `storage` | Object | `{ enabled: true, key: 'plyr' }` | `enabled`: Allow use of local storage to store user settings. `key`: The key name to use. |
|
| `storage` | Object | `{ enabled: true, key: 'plyr' }` | `enabled`: Allow use of local storage to store user settings. `key`: The key name to use. |
|
||||||
| `speed` | Object | `{ selected: 1, options: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2] }` | `selected`: The default speed for playback. `options`: Options to display in the menu. Most browsers will refuse to play slower than 0.5. |
|
| `speed` | Object | `{ selected: 1, options: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 4] }` | `selected`: The default speed for playback. `options`: The speed options to display in the UI. YouTube and Vimeo will ignore any options outside of the 0.5-2 range, so options outside of this range will be hidden automatically. |
|
||||||
| `quality` | Object | `{ default: 576, options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240] }` | `default` is the default quality level (if it exists in your sources). `options` are the options to display. This is used to filter the available sources. |
|
| `quality` | Object | `{ default: 576, options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240] }` | `default` is the default quality level (if it exists in your sources). `options` are the options to display. This is used to filter the available sources. |
|
||||||
| `loop` | Object | `{ active: false }` | `active`: Whether to loop the current video. If the `loop` attribute is present on a `<video>` or `<audio>` element, this will be automatically set to true This is an object to support future functionality. |
|
| `loop` | Object | `{ active: false }` | `active`: Whether to loop the current video. If the `loop` attribute is present on a `<video>` or `<audio>` element, this will be automatically set to true This is an object to support future functionality. |
|
||||||
| `ads` | Object | `{ enabled: false, publisherId: '' }` | `enabled`: Whether to enable advertisements. `publisherId`: Your unique [vi.ai](https://vi.ai/publisher-video-monetization/?aid=plyrio) publisher ID. |
|
| `ads` | Object | `{ enabled: false, publisherId: '', tagUrl: '' }` | `enabled`: Whether to enable advertisements. `publisherId`: Your unique [vi.ai](https://vi.ai/publisher-video-monetization/?aid=plyrio) publisher ID. `tagUrl` is a URL for a custom VAST tag if you're not using Vi. |
|
||||||
| `urls` | Object | See source. | If you wish to override any API URLs then you can do so here. You can also set a custom download URL for the download button. |
|
| `urls` | Object | See source. | If you wish to override any API URLs then you can do so here. You can also set a custom download URL for the download button. |
|
||||||
| `vimeo` | Object | `{ byline: false, portrait: false, title: false, speed: true, transparent: false }` | See [Vimeo embed options](https://github.com/vimeo/player.js/#embed-options). Some are set automatically based on other config options, namely: `loop`, `autoplay`, `muted`, `gesture`, `playsinline` |
|
| `vimeo` | Object | `{ byline: false, portrait: false, title: false, speed: true, transparent: false }` | See [Vimeo embed options](https://github.com/vimeo/player.js/#embed-options). Some are set automatically based on other config options, namely: `loop`, `autoplay`, `muted`, `gesture`, `playsinline` |
|
||||||
| `youtube` | Object | `{ noCookie: false, rel: 0, showinfo: 0, iv_load_policy: 3, modestbranding: 1 }` | See [YouTube embed options](https://developers.google.com/youtube/player_parameters#Parameters). The only custom option is `noCookie` to use an alternative to YouTube that doesn't use cookies (useful for GDPR, etc). Some are set automatically based on other config options, namely: `autoplay`, `hl`, `controls`, `disablekb`, `playsinline`, `cc_load_policy`, `cc_lang_pref`, `widget_referrer` |
|
| `youtube` | Object | `{ noCookie: false, rel: 0, showinfo: 0, iv_load_policy: 3, modestbranding: 1 }` | See [YouTube embed options](https://developers.google.com/youtube/player_parameters#Parameters). The only custom option is `noCookie` to use an alternative to YouTube that doesn't use cookies (useful for GDPR, etc). Some are set automatically based on other config options, namely: `autoplay`, `hl`, `controls`, `disablekb`, `playsinline`, `cc_load_policy`, `cc_lang_pref`, `widget_referrer` |
|
||||||
| `previewThumbnails` | Object | `{ enabled: false, src: '' }` | `enabled`: Whether to enable the preview thumbnails (they must be generated by you). `src` must be either a string or an array of strings representing URLs for the VTT files containing the image URL(s). Learn more about [preview thumbnails](#preview-thumbnails) below. |
|
| `previewThumbnails` | Object | `{ enabled: false, src: '' }` | `enabled`: Whether to enable the preview thumbnails (they must be generated by you). `src` must be either a string or an array of strings representing URLs for the VTT files containing the image URL(s). Learn more about [preview thumbnails](#preview-thumbnails) below. |
|
||||||
|
| `mediaMetadata` | Object | `{ title: '', artist: '', album: '', artwork: [] }` | The [MediaMetadata](https://developer.mozilla.org/en-US/docs/Web/API/MediaMetadata) interface of the Media Session API allows a web page to provide rich media metadata for display in a platform UI. |
|
||||||
|
| `markers` | Object | `{ enabled: false, points: [] }` | `enabled`: Whether to enable markers. `points` is an array of `{ time: number; label: string; }` objects where `time` represents the marker position in seconds and `label` is the HTML string to be displayed. |
|
||||||
|
|
||||||
1. Vimeo only
|
1. Vimeo only
|
||||||
2. Autoplay is generally not recommended as it is seen as a negative user experience. It is also disabled in many browsers. Before raising issues, do your homework. More info can be found here:
|
2. Autoplay is generally not recommended as it is seen as a negative user experience. It is also disabled in many browsers. Before raising issues, do your homework. More info can be found here:
|
||||||
@@ -335,7 +440,7 @@ const player = new Plyr('#player', {
|
|||||||
You can also access the object through any events:
|
You can also access the object through any events:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
element.addEventListener('ready', event => {
|
element.addEventListener('ready', (event) => {
|
||||||
const player = event.detail.plyr;
|
const player = event.detail.plyr;
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@@ -350,10 +455,10 @@ player.fullscreen.enter(); // Enter fullscreen
|
|||||||
```
|
```
|
||||||
|
|
||||||
| Method | Parameters | Description |
|
| Method | Parameters | Description |
|
||||||
| ------------------------ | ---------------- | ---------------------------------------------------------------------------------------------------------- |
|
| -------------------------------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------- |
|
||||||
| `play()`¹ | - | Start playback. |
|
| `play()`¹ | - | Start playback. |
|
||||||
| `pause()` | - | Pause playback. |
|
| `pause()` | - | Pause playback. |
|
||||||
| `togglePlay(toggle)` | Boolean | Toggle playback, if no parameters are passed, it will toggle based on current status. |
|
| `togglePlay(toggle)`¹ | Boolean | Toggle playback, if no parameters are passed, it will toggle based on current status. |
|
||||||
| `stop()` | - | Stop playback and reset to start. |
|
| `stop()` | - | Stop playback and reset to start. |
|
||||||
| `restart()` | - | Restart playback. |
|
| `restart()` | - | Restart playback. |
|
||||||
| `rewind(seekTime)` | Number | Rewind playback by the specified seek time. If no parameter is passed, the default seek time will be used. |
|
| `rewind(seekTime)` | Number | Rewind playback by the specified seek time. If no parameter is passed, the default seek time will be used. |
|
||||||
@@ -365,6 +470,7 @@ player.fullscreen.enter(); // Enter fullscreen
|
|||||||
| `fullscreen.exit()` | - | Exit fullscreen. |
|
| `fullscreen.exit()` | - | Exit fullscreen. |
|
||||||
| `fullscreen.toggle()` | - | Toggle fullscreen. |
|
| `fullscreen.toggle()` | - | Toggle fullscreen. |
|
||||||
| `airplay()` | - | Trigger the airplay dialog on supported devices. |
|
| `airplay()` | - | Trigger the airplay dialog on supported devices. |
|
||||||
|
| `setPreviewThumbnails(source: PreviewThumbnailsOptions)` | - | Sets the preview thumbnails for the current source. |
|
||||||
| `toggleControls(toggle)` | Boolean | Toggle the controls (video only). Takes optional truthy value to force it on/off. |
|
| `toggleControls(toggle)` | Boolean | Toggle the controls (video only). Takes optional truthy value to force it on/off. |
|
||||||
| `on(event, function)` | String, Function | Add an event listener for the specified event. |
|
| `on(event, function)` | String, Function | Add an event listener for the specified event. |
|
||||||
| `once(event, function)` | String, Function | Add an event listener for the specified event once. |
|
| `once(event, function)` | String, Function | Add an event listener for the specified event once. |
|
||||||
@@ -372,7 +478,7 @@ player.fullscreen.enter(); // Enter fullscreen
|
|||||||
| `supports(type)` | String | Check support for a mime type. |
|
| `supports(type)` | String | Check support for a mime type. |
|
||||||
| `destroy()` | - | Destroy the instance and garbage collect any elements. |
|
| `destroy()` | - | Destroy the instance and garbage collect any elements. |
|
||||||
|
|
||||||
1. For HTML5 players, `play()` will return a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) in _some_ browsers - WebKit and Mozilla [according to MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) at time of writing.
|
1. For HTML5 players, `play()` will return a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) for most browsers - e.g. Chrome, Firefox, Opera, Safari and Edge [according to MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) at time of writing.
|
||||||
|
|
||||||
## Getters and Setters
|
## Getters and Setters
|
||||||
|
|
||||||
@@ -411,6 +517,7 @@ player.fullscreen.active; // false;
|
|||||||
| `loop` | ✓ | ✓ | Gets or sets the current loop state of the player. The setter accepts a boolean. |
|
| `loop` | ✓ | ✓ | Gets or sets the current loop state of the player. The setter accepts a boolean. |
|
||||||
| `source` | ✓ | ✓ | Gets or sets the current source for the player. The setter accepts an object. See [source setter](#the-source-setter) below for examples. |
|
| `source` | ✓ | ✓ | Gets or sets the current source for the player. The setter accepts an object. See [source setter](#the-source-setter) below for examples. |
|
||||||
| `poster` | ✓ | ✓ | Gets or sets the current poster image for the player. The setter accepts a string; the URL for the updated poster image. |
|
| `poster` | ✓ | ✓ | Gets or sets the current poster image for the player. The setter accepts a string; the URL for the updated poster image. |
|
||||||
|
| `previewThumbnails` | ✓ | ✓ | Gets or sets the current preview thumbnail source for the player. The setter accepts a string |
|
||||||
| `autoplay` | ✓ | ✓ | Gets or sets the autoplay state of the player. The setter accepts a boolean. |
|
| `autoplay` | ✓ | ✓ | Gets or sets the autoplay state of the player. The setter accepts a boolean. |
|
||||||
| `currentTrack` | ✓ | ✓ | Gets or sets the caption track by index. `-1` means the track is missing or captions is not active |
|
| `currentTrack` | ✓ | ✓ | Gets or sets the caption track by index. `-1` means the track is missing or captions is not active |
|
||||||
| `language` | ✓ | ✓ | Gets or sets the preferred captions language for the player. The setter accepts an ISO two-letter language code. Support for the languages is dependent on the captions you include. If your captions don't have any language data, or if you have multiple tracks with the same language, you may want to use `currentTrack` instead. |
|
| `language` | ✓ | ✓ | Gets or sets the preferred captions language for the player. The setter accepts an ISO two-letter language code. Support for the languages is dependent on the captions you include. If your captions don't have any language data, or if you have multiple tracks with the same language, you may want to use `currentTrack` instead. |
|
||||||
@@ -445,6 +552,9 @@ player.source = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
poster: '/path/to/poster.jpg',
|
poster: '/path/to/poster.jpg',
|
||||||
|
previewThumbnails: {
|
||||||
|
src: '/path/to/thumbnails.vtt',
|
||||||
|
},
|
||||||
tracks: [
|
tracks: [
|
||||||
{
|
{
|
||||||
kind: 'captions',
|
kind: 'captions',
|
||||||
@@ -496,8 +606,6 @@ player.source = {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
_Note_: `src` can be the video ID or URL
|
|
||||||
|
|
||||||
Vimeo example
|
Vimeo example
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@@ -515,12 +623,13 @@ player.source = {
|
|||||||
_Note:_ `src` property for YouTube and Vimeo can either be the video ID or the whole URL.
|
_Note:_ `src` property for YouTube and Vimeo can either be the video ID or the whole URL.
|
||||||
|
|
||||||
| Property | Type | Description |
|
| Property | Type | Description |
|
||||||
| -------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `type` | String | Either `video` or `audio`. _Note:_ YouTube and Vimeo are currently not supported as audio sources. |
|
| `type` | String | Either `video` or `audio`. _Note:_ YouTube and Vimeo are currently not supported as audio sources. |
|
||||||
| `title` | String | _Optional._ Title of the new media. Used for the `aria-label` attribute on the play button, and outer container. YouTube and Vimeo are populated automatically. |
|
| `title` | String | _Optional._ Title of the new media. Used for the `aria-label` attribute on the play button, and outer container. YouTube and Vimeo are populated automatically. |
|
||||||
| `sources` | Array | This is an array of sources. For HTML5 media, the properties of this object are mapped directly to HTML attributes so more can be added to the object if required. |
|
| `sources` | Array | This is an array of sources. For HTML5 media, the properties of this object are mapped directly to HTML attributes so more can be added to the object if required. |
|
||||||
| `poster`¹ | String | The URL for the poster image (HTML5 video only). |
|
| `poster`¹ | String | The URL for the poster image (HTML5 video only). |
|
||||||
| `tracks`¹ | String | An array of track objects. Each element in the array is mapped directly to a track element and any keys mapped directly to HTML attributes so as in the example above, it will render as `<track kind="captions" label="English" srclang="en" src="https://cdn.selz.com/plyr/1.0/example_captions_en.vtt" default>` and similar for the French version. Booleans are converted to HTML5 value-less attributes. |
|
| `tracks`¹ | String | An array of track objects. Each element in the array is mapped directly to a track element and any keys mapped directly to HTML attributes so as in the example above, it will render as `<track kind="captions" label="English" srclang="en" src="https://cdn.selz.com/plyr/1.0/example_captions_en.vtt" default>` and similar for the French version. Booleans are converted to HTML5 value-less attributes. |
|
||||||
|
| `previewThumbnails`¹ | Object | The same object like in the `previewThumbnails` constructor option. This means you can either change the thumbnails vtt via the `src` key or disable the thumbnails plugin for the next video by passing `{ enabled: false }`. |
|
||||||
|
|
||||||
1. HTML5 only
|
1. HTML5 only
|
||||||
|
|
||||||
@@ -531,7 +640,7 @@ reference to the instance, you can use the `on()` API method or `addEventListene
|
|||||||
property. Here's an example:
|
property. Here's an example:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
player.on('ready', event => {
|
player.on('ready', (event) => {
|
||||||
const instance = event.detail.plyr;
|
const instance = event.detail.plyr;
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@@ -630,7 +739,7 @@ Fullscreen in Plyr is supported by all browsers that [currently support it](http
|
|||||||
Plyr supports the last 2 versions of most _modern_ browsers.
|
Plyr supports the last 2 versions of most _modern_ browsers.
|
||||||
|
|
||||||
| Browser | Supported |
|
| Browser | Supported |
|
||||||
| ------------- | ------------- |
|
| ------------- | --------------- |
|
||||||
| Safari | ✓ |
|
| Safari | ✓ |
|
||||||
| Mobile Safari | ✓¹ |
|
| Mobile Safari | ✓¹ |
|
||||||
| Firefox | ✓ |
|
| Firefox | ✓ |
|
||||||
@@ -638,7 +747,7 @@ Plyr supports the last 2 versions of most _modern_ browsers.
|
|||||||
| Opera | ✓ |
|
| Opera | ✓ |
|
||||||
| Edge | ✓ |
|
| Edge | ✓ |
|
||||||
| IE11 | ✓³ |
|
| IE11 | ✓³ |
|
||||||
| IE10 | ✓²³ |
|
| IE10 | ✓<sup>2,3</sup> |
|
||||||
|
|
||||||
1. Mobile Safari on the iPhone forces the native player for `<video>` unless the `playsinline` attribute is present. Volume controls are also disabled as they are handled device wide.
|
1. Mobile Safari on the iPhone forces the native player for `<video>` unless the `playsinline` attribute is present. Volume controls are also disabled as they are handled device wide.
|
||||||
2. Native player used (no support for `<progress>` or `<input type="range">`) but the API is supported. No native fullscreen support, fallback can be used (see [options](#options)).
|
2. Native player used (no support for `<progress>` or `<input type="range">`) but the API is supported. No native fullscreen support, fallback can be used (see [options](#options)).
|
||||||
@@ -668,7 +777,7 @@ The `enabled` option can be used to disable certain User Agents. For example, if
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
{
|
{
|
||||||
enabled: /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
|
enabled: !/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -679,13 +788,15 @@ If a User Agent is disabled but supports `<video>` and `<audio>` natively, it wi
|
|||||||
Some awesome folks have made plugins for CMSs and Components for JavaScript frameworks:
|
Some awesome folks have made plugins for CMSs and Components for JavaScript frameworks:
|
||||||
|
|
||||||
| Type | Maintainer | Link |
|
| Type | Maintainer | Link |
|
||||||
| --------- | -------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
| ----------- | --------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
||||||
| WordPress | Brandon Lavigne ([@drrobotnik](https://github.com/drrobotnik)) | [https://wordpress.org/plugins/plyr/](https://wordpress.org/plugins/plyr/) |
|
| WordPress | Brandon Lavigne ([@drrobotnik](https://github.com/drrobotnik)) | [https://wordpress.org/plugins/plyr/](https://wordpress.org/plugins/plyr/) |
|
||||||
| Angular | Simon Bobrov ([@smnbbrv](https://github.com/smnbbrv)) | [https://github.com/smnbbrv/ngx-plyr](https://github.com/smnbbrv/ngx-plyr) |
|
| Angular | Simon Bobrov ([@smnbbrv](https://github.com/smnbbrv)) | [https://github.com/smnbbrv/ngx-plyr](https://github.com/smnbbrv/ngx-plyr) |
|
||||||
| React | Jose Miguel Bejarano ([@xDae](https://github.com/xDae)) | [https://github.com/xDae/react-plyr](https://github.com/xDae/react-plyr) |
|
| React | Chintan Prajapati ([@chintan9](https://github.com/chintan9)) | [https://github.com/chintan9/plyr-react](https://github.com/chintan9/plyr-react) |
|
||||||
| Vue | Gabe Dunn ([@redxtech](https://github.com/redxtech)) | [https://github.com/redxtech/vue-plyr](https://github.com/redxtech/vue-plyr) |
|
| Vue | Gabe Dunn ([@redxtech](https://github.com/redxtech)) | [https://github.com/redxtech/vue-plyr](https://github.com/redxtech/vue-plyr) |
|
||||||
| Neos | Jon Uhlmann ([@jonnitto](https://github.com/jonnitto)) | [https://packagist.org/packages/jonnitto/plyr](https://packagist.org/packages/jonnitto/plyr) |
|
| Neos | Jon Uhlmann ([@jonnitto](https://github.com/jonnitto)) | [https://packagist.org/packages/jonnitto/plyr](https://packagist.org/packages/jonnitto/plyr) |
|
||||||
| Kirby | Dominik Pschenitschni ([@dpschen](https://github.com/dpschen)) | [https://github.com/dpschen/kirby-plyrtag](https://github.com/dpschen/kirby-plyrtag) |
|
| Kirby | Dominik Pschenitschni ([@dpschen](https://github.com/dpschen)) | [https://github.com/dpschen/kirby-plyrtag](https://github.com/dpschen/kirby-plyrtag) |
|
||||||
|
| REDAXO | FriendsOfRedaxo / skerbis ([@skerbis](https://friendsofredaxo.github.io)) | [https://github.com/FriendsOfREDAXO/plyr](https://github.com/FriendsOfREDAXO/plyr) |
|
||||||
|
| svelte-plyr | Ben Woodward / benwoodward ([@benwoodward](https://github.com/benwoodward)) | [https://github.com/benwoodward/svelte-plyr](https://github.com/benwoodward/svelte-plyr) |
|
||||||
|
|
||||||
# Issues
|
# Issues
|
||||||
|
|
||||||
@@ -729,14 +840,17 @@ Plyr costs money to run, not only my time. I donate my time for free as I enjoy
|
|||||||
- [Oscar Radio](http://oscar-radio.xyz/)
|
- [Oscar Radio](http://oscar-radio.xyz/)
|
||||||
- [Sparkk TV](https://www.sparkktv.com/)
|
- [Sparkk TV](https://www.sparkktv.com/)
|
||||||
- [@halfhalftravel](https://www.halfhalftravel.com/)
|
- [@halfhalftravel](https://www.halfhalftravel.com/)
|
||||||
|
- [BitChute](https://www.bitchute.com)
|
||||||
|
- [Rutheneum-Bote](https://gymnasium-rutheneum.de/content/newspaper/kreativwettbewerb.php)
|
||||||
|
- [pressakey.com | Blog-Magazin für Videospiele](https://pressakey.com)
|
||||||
|
- [STROLLÿN: Work with a View](https://strollyn.com)
|
||||||
|
- [CFDA Runway360](https://runway360.cfda.com/)
|
||||||
|
|
||||||
If you want to be added to the list, open a pull request. It'd be awesome to see how you're using Plyr 😎
|
If you want to be added to the list, open a pull request. It'd be awesome to see how you're using Plyr 😎
|
||||||
|
|
||||||
# Useful links and credits
|
# Useful links and credits
|
||||||
|
|
||||||
Credit to the PayPal HTML5 Video player from which Plyr's caption functionality was originally ported from:
|
- [PayPal's Accessible HTML5 Video Player (which Plyr was originally ported from)](https://github.com/paypal/accessible-html5-video-player)
|
||||||
|
|
||||||
- [PayPal's Accessible HTML5 Video Player](https://github.com/paypal/accessible-html5-video-player)
|
|
||||||
- [An awesome guide for Plyr in Japanese!](http://syncer.jp/how-to-use-plyr-io) by [@arayutw](https://twitter.com/arayutw)
|
- [An awesome guide for Plyr in Japanese!](http://syncer.jp/how-to-use-plyr-io) by [@arayutw](https://twitter.com/arayutw)
|
||||||
|
|
||||||
# Thanks
|
# Thanks
|
||||||
@@ -749,6 +863,29 @@ Massive thanks to [Fastly](https://www.fastly.com/) for providing the CDN servic
|
|||||||
|
|
||||||
Massive thanks to [Sentry](https://sentry.io/) for providing the logging services for the demo site.
|
Massive thanks to [Sentry](https://sentry.io/) for providing the logging services for the demo site.
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
### Code Contributors
|
||||||
|
|
||||||
|
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
||||||
|
|
||||||
|
<a href="https://github.com/sampotts/plyr/graphs/contributors"><img src="https://opencollective.com/plyr/contributors.svg?width=890&button=false" /></a>
|
||||||
|
|
||||||
|
### Financial Contributors
|
||||||
|
|
||||||
|
Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/plyr/contribute)]
|
||||||
|
|
||||||
|
#### Individuals
|
||||||
|
|
||||||
|
<a href="https://opencollective.com/plyr"><img src="https://opencollective.com/plyr/individuals.svg?width=890"></a>
|
||||||
|
|
||||||
|
#### Organizations
|
||||||
|
|
||||||
|
Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/plyr/contribute)]
|
||||||
|
|
||||||
|
<a href="https://opencollective.com/plyr/organization/0/website"><img src="https://opencollective.com/plyr/organization/0/avatar.svg"></a>
|
||||||
|
<a href="https://opencollective.com/plyr/organization/1/website"><img src="https://opencollective.com/plyr/organization/1/avatar.svg"></a><a href="https://opencollective.com/plyr/organization/2/website"><img src="https://opencollective.com/plyr/organization/2/avatar.svg"></a>
|
||||||
|
|
||||||
# Copyright and License
|
# Copyright and License
|
||||||
|
|
||||||
[The MIT license](license.md)
|
[The MIT license](LICENSE.md)
|
||||||
-1104
File diff suppressed because it is too large
Load Diff
+34
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2",
|
||||||
|
"ignorePaths": ["package.json", "dist/*", "demo/node_modules/*"],
|
||||||
|
"dictionaryDefinitions": [],
|
||||||
|
"dictionaries": [],
|
||||||
|
"words": [
|
||||||
|
"autopause",
|
||||||
|
"autoplay",
|
||||||
|
"bote",
|
||||||
|
"cfda",
|
||||||
|
"classname",
|
||||||
|
"digbmx",
|
||||||
|
"fastly",
|
||||||
|
"fullscreen",
|
||||||
|
"gordita",
|
||||||
|
"magazin",
|
||||||
|
"menuitemradio",
|
||||||
|
"noupe",
|
||||||
|
"playsinline",
|
||||||
|
"plyr",
|
||||||
|
"rutheneum",
|
||||||
|
"seektime",
|
||||||
|
"selz",
|
||||||
|
"sparkk",
|
||||||
|
"srclang",
|
||||||
|
"strol",
|
||||||
|
"stylelint",
|
||||||
|
"unmute",
|
||||||
|
"videospiele",
|
||||||
|
"xywh"
|
||||||
|
],
|
||||||
|
"ignoreWords": [],
|
||||||
|
"import": []
|
||||||
|
}
|
||||||
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
-25271
File diff suppressed because it is too large
Load Diff
Vendored
-2
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 5.4 KiB |
Vendored
-1
File diff suppressed because one or more lines are too long
+7
-24
@@ -18,10 +18,7 @@
|
|||||||
<link rel="apple-touch-icon" sizes="180x180" href="https://cdn.plyr.io/static/icons/180x180.png" />
|
<link rel="apple-touch-icon" sizes="180x180" href="https://cdn.plyr.io/static/icons/180x180.png" />
|
||||||
|
|
||||||
<!-- Open Graph -->
|
<!-- Open Graph -->
|
||||||
<meta
|
<meta property="og:title" content="Plyr - A simple, customizable HTML5 Video, Audio, YouTube and Vimeo player" />
|
||||||
property="og:title"
|
|
||||||
content="Plyr - A simple, customizable HTML5 Video, Audio, YouTube and Vimeo player"
|
|
||||||
/>
|
|
||||||
<meta property="og:site_name" content="Plyr" />
|
<meta property="og:site_name" content="Plyr" />
|
||||||
<meta property="og:url" content="https://plyr.io" />
|
<meta property="og:url" content="https://plyr.io" />
|
||||||
<meta property="og:image" content="https://cdn.plyr.io/static/icons/1200x630.png" />
|
<meta property="og:image" content="https://cdn.plyr.io/static/icons/1200x630.png" />
|
||||||
@@ -108,14 +105,6 @@
|
|||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
|
||||||
Premium video monitization from
|
|
||||||
<a href="https://vi.ai/publisher-video-monetization/?aid=plyrio" target="_blank" class="no-border">
|
|
||||||
<img src="https://cdn.plyr.io/static/vi-logo-24x24.svg" alt="ai.vi" />
|
|
||||||
<span class="sr-only">ai.vi</span>
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div class="call-to-action">
|
<div class="call-to-action">
|
||||||
<a href="https://github.com/sampotts/plyr" target="_blank" class="button js-shr">
|
<a href="https://github.com/sampotts/plyr" target="_blank" class="button js-shr">
|
||||||
<svg class="icon" role="presentation">
|
<svg class="icon" role="presentation">
|
||||||
@@ -133,14 +122,13 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<div id="container">
|
<div id="container">
|
||||||
<video
|
<video
|
||||||
controls
|
controls
|
||||||
crossorigin
|
crossorigin
|
||||||
playsinline
|
playsinline
|
||||||
poster="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg"
|
data-poster="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg"
|
||||||
id="player"
|
id="player"
|
||||||
>
|
>
|
||||||
<!-- Video files -->
|
<!-- Video files -->
|
||||||
@@ -176,9 +164,7 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Fallback for browsers that don't support the <video> element -->
|
<!-- Fallback for browsers that don't support the <video> element -->
|
||||||
<a href="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4" download
|
<a href="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4" download>Download</a>
|
||||||
>Download</a
|
|
||||||
>
|
|
||||||
</video>
|
</video>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -191,9 +177,7 @@
|
|||||||
d="M14.738.326C14.548.118 14.28 0 14 0H2c-.28 0-.55.118-.738.326S.98.81 1.004 1.09l1 11c.03.317.208.603.48.767l5 3c.16.095.338.143.516.143s.356-.048.515-.143l5-3c.273-.164.452-.45.48-.767l1-11c.026-.28-.067-.557-.257-.764zM12 4H6v2h6v5.72l-4 1.334-4-1.333V9h2v1.28l2 .666 2-.667V8H4V2h8v2z"
|
d="M14.738.326C14.548.118 14.28 0 14 0H2c-.28 0-.55.118-.738.326S.98.81 1.004 1.09l1 11c.03.317.208.603.48.767l5 3c.16.095.338.143.516.143s.356-.048.515-.143l5-3c.273-.164.452-.45.48-.767l1-11c.026-.28-.067-.557-.257-.764zM12 4H6v2h6v5.72l-4 1.334-4-1.333V9h2v1.28l2 .666 2-.667V8H4V2h8v2z"
|
||||||
></path>
|
></path>
|
||||||
</svg>
|
</svg>
|
||||||
<a
|
<a href="https://itunes.apple.com/au/movie/view-from-a-blue-moon/id1041586323" target="_blank"
|
||||||
href="https://itunes.apple.com/au/movie/view-from-a-blue-moon/id1041586323"
|
|
||||||
target="_blank"
|
|
||||||
>View From A Blue Moon</a
|
>View From A Blue Moon</a
|
||||||
>
|
>
|
||||||
© Brainfarm
|
© Brainfarm
|
||||||
@@ -215,9 +199,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="plyr__cite plyr__cite--youtube" hidden>
|
<li class="plyr__cite plyr__cite--youtube" hidden>
|
||||||
<small>
|
<small>
|
||||||
<a href="https://www.youtube.com/watch?v=bTqVqk7FSmY" target="_blank"
|
<a href="https://www.youtube.com/watch?v=bTqVqk7FSmY" target="_blank">View From A Blue Moon</a>
|
||||||
>View From A Blue Moon</a
|
|
||||||
>
|
|
||||||
on
|
on
|
||||||
<span class="color--youtube">
|
<span class="color--youtube">
|
||||||
<svg class="icon" role="presentation">
|
<svg class="icon" role="presentation">
|
||||||
@@ -233,7 +215,8 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="plyr__cite plyr__cite--vimeo" hidden>
|
<li class="plyr__cite plyr__cite--vimeo" hidden>
|
||||||
<small>
|
<small>
|
||||||
<a href="https://vimeo.com/76979871" target="_blank">The New Vimeo Player</a> on
|
<a href="https://vimeo.com/40648169" target="_blank">Toob “Wavaphon” Music Video</a>
|
||||||
|
on
|
||||||
<span class="color--vimeo">
|
<span class="color--vimeo">
|
||||||
<svg class="icon" role="presentation">
|
<svg class="icon" role="presentation">
|
||||||
<title>Vimeo</title>
|
<title>Vimeo</title>
|
||||||
|
|||||||
+3
-3
@@ -5,10 +5,10 @@
|
|||||||
"homepage": "https://plyr.io",
|
"homepage": "https://plyr.io",
|
||||||
"author": "Sam Potts <sam@potts.es>",
|
"author": "Sam Potts <sam@potts.es>",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"core-js": "^3.1.4",
|
"@sentry/browser": "^5.22.3",
|
||||||
|
"core-js": "^3.6.5",
|
||||||
"custom-event-polyfill": "^1.0.7",
|
"custom-event-polyfill": "^1.0.7",
|
||||||
"raven-js": "^3.27.2",
|
|
||||||
"shr-buttons": "2.0.3",
|
"shr-buttons": "2.0.3",
|
||||||
"url-polyfill": "^1.1.5"
|
"url-polyfill": "^1.1.10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+52
-34
@@ -1,14 +1,14 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// Plyr.io demo
|
// Plyr.io demo
|
||||||
// This code is purely for the https://plyr.io website
|
// This code is purely for the https://plyr.io website
|
||||||
// Please see readme.md in the root or github.com/sampotts/plyr
|
// Please see README.md in the root or github.com/sampotts/plyr
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import './tab-focus';
|
import './tab-focus';
|
||||||
import 'custom-event-polyfill';
|
import 'custom-event-polyfill';
|
||||||
import 'url-polyfill';
|
import 'url-polyfill';
|
||||||
|
|
||||||
import Raven from 'raven-js';
|
import * as Sentry from '@sentry/browser';
|
||||||
import Shr from 'shr-buttons';
|
import Shr from 'shr-buttons';
|
||||||
|
|
||||||
import Plyr from '../../../src/js/plyr';
|
import Plyr from '../../../src/js/plyr';
|
||||||
@@ -16,14 +16,17 @@ import sources from './sources';
|
|||||||
import toggleClass from './toggle-class';
|
import toggleClass from './toggle-class';
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
const { host } = window.location;
|
const production = 'plyr.io';
|
||||||
const env = {
|
|
||||||
prod: host === 'plyr.io',
|
// Sentry for demo site (https://plyr.io) only
|
||||||
dev: host === 'dev.plyr.io',
|
if (window.location.host === production) {
|
||||||
};
|
Sentry.init({
|
||||||
|
dsn: 'https://d4ad9866ad834437a4754e23937071e4@sentry.io/305555',
|
||||||
|
whitelistUrls: [production].map((d) => new RegExp(`https://(([a-z0-9])+(.))*${d}`)),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
Raven.context(() => {
|
|
||||||
const selector = '#player';
|
const selector = '#player';
|
||||||
|
|
||||||
// Setup share buttons
|
// Setup share buttons
|
||||||
@@ -50,18 +53,44 @@ import toggleClass from './toggle-class';
|
|||||||
captions: {
|
captions: {
|
||||||
active: true,
|
active: true,
|
||||||
},
|
},
|
||||||
keys: {
|
|
||||||
google: 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c',
|
|
||||||
},
|
|
||||||
ads: {
|
ads: {
|
||||||
enabled: env.prod || env.dev,
|
enabled: window.location.host.includes(production),
|
||||||
publisherId: '918848828995742',
|
publisherId: '918848828995742',
|
||||||
},
|
},
|
||||||
previewThumbnails: {
|
previewThumbnails: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
src: [
|
src: ['https://cdn.plyr.io/static/demo/thumbs/100p.vtt', 'https://cdn.plyr.io/static/demo/thumbs/240p.vtt'],
|
||||||
'https://cdn.plyr.io/static/demo/thumbs/100p.vtt',
|
},
|
||||||
'https://cdn.plyr.io/static/demo/thumbs/240p.vtt',
|
vimeo: {
|
||||||
|
// Prevent Vimeo blocking plyr.io demo site
|
||||||
|
referrerPolicy: 'no-referrer',
|
||||||
|
},
|
||||||
|
mediaMetadata: {
|
||||||
|
title: 'View From A Blue Moon',
|
||||||
|
album: 'Sports',
|
||||||
|
artist: 'Brainfarm',
|
||||||
|
artwork: [
|
||||||
|
{
|
||||||
|
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg',
|
||||||
|
type: 'image/jpeg',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
markers: {
|
||||||
|
enabled: true,
|
||||||
|
points: [
|
||||||
|
{
|
||||||
|
time: 10,
|
||||||
|
label: 'first marker',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
time: 40,
|
||||||
|
label: 'second marker',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
time: 120,
|
||||||
|
label: '<strong>third</strong> marker',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -74,17 +103,17 @@ import toggleClass from './toggle-class';
|
|||||||
const types = Object.keys(sources);
|
const types = Object.keys(sources);
|
||||||
const historySupport = Boolean(window.history && window.history.pushState);
|
const historySupport = Boolean(window.history && window.history.pushState);
|
||||||
let currentType = window.location.hash.substring(1);
|
let currentType = window.location.hash.substring(1);
|
||||||
const hasCurrentType = !currentType.length;
|
const hasInitialType = currentType.length;
|
||||||
|
|
||||||
function render(type) {
|
function render(type) {
|
||||||
// Remove active classes
|
// Remove active classes
|
||||||
Array.from(buttons).forEach(button => toggleClass(button.parentElement, 'active', false));
|
Array.from(buttons).forEach((button) => toggleClass(button.parentElement, 'active', false));
|
||||||
|
|
||||||
// Set active on parent
|
// Set active on parent
|
||||||
toggleClass(document.querySelector(`[data-source="${type}"]`), 'active', true);
|
toggleClass(document.querySelector(`[data-source="${type}"]`), 'active', true);
|
||||||
|
|
||||||
// Show cite
|
// Show cite
|
||||||
Array.from(document.querySelectorAll('.plyr__cite')).forEach(cite => {
|
Array.from(document.querySelectorAll('.plyr__cite')).forEach((cite) => {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
cite.hidden = true;
|
cite.hidden = true;
|
||||||
});
|
});
|
||||||
@@ -95,11 +124,7 @@ import toggleClass from './toggle-class';
|
|||||||
// Set a new source
|
// Set a new source
|
||||||
function setSource(type, init) {
|
function setSource(type, init) {
|
||||||
// Bail if new type isn't known, it's the current type, or current type is empty (video is default) and new type is video
|
// Bail if new type isn't known, it's the current type, or current type is empty (video is default) and new type is video
|
||||||
if (
|
if (!types.includes(type) || (!init && type === currentType) || (!currentType.length && type === 'video')) {
|
||||||
!types.includes(type) ||
|
|
||||||
(!init && type === currentType) ||
|
|
||||||
(!currentType.length && type === 'video')
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +138,7 @@ import toggleClass from './toggle-class';
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bind to each button
|
// Bind to each button
|
||||||
Array.from(buttons).forEach(button => {
|
Array.from(buttons).forEach((button) => {
|
||||||
button.addEventListener('click', () => {
|
button.addEventListener('click', () => {
|
||||||
const type = button.getAttribute('data-source');
|
const type = button.getAttribute('data-source');
|
||||||
|
|
||||||
@@ -126,20 +151,20 @@ import toggleClass from './toggle-class';
|
|||||||
});
|
});
|
||||||
|
|
||||||
// List for backwards/forwards
|
// List for backwards/forwards
|
||||||
window.addEventListener('popstate', event => {
|
window.addEventListener('popstate', (event) => {
|
||||||
if (event.state && Object.keys(event.state).includes('type')) {
|
if (event.state && Object.keys(event.state).includes('type')) {
|
||||||
setSource(event.state.type);
|
setSource(event.state.type);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// If there's no current type set, assume video
|
// If there's no current type set, assume video
|
||||||
if (hasCurrentType) {
|
if (!hasInitialType) {
|
||||||
currentType = 'video';
|
currentType = 'video';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace current history state
|
// Replace current history state
|
||||||
if (historySupport && types.includes(currentType)) {
|
if (historySupport && types.includes(currentType)) {
|
||||||
window.history.replaceState({ type: currentType }, '', hasCurrentType ? '' : `#${currentType}`);
|
window.history.replaceState({ type: currentType }, '', hasInitialType ? `#${currentType}` : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's not video, load the source
|
// If it's not video, load the source
|
||||||
@@ -149,11 +174,4 @@ import toggleClass from './toggle-class';
|
|||||||
|
|
||||||
render(currentType);
|
render(currentType);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Raven / Sentry
|
|
||||||
// For demo site (https://plyr.io) only
|
|
||||||
if (env.prod) {
|
|
||||||
Raven.config('https://d4ad9866ad834437a4754e23937071e4@sentry.io/305555').install();
|
|
||||||
}
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ const sources = {
|
|||||||
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt',
|
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
previewThumbnails: {
|
||||||
|
src: ['https://cdn.plyr.io/static/demo/thumbs/100p.vtt', 'https://cdn.plyr.io/static/demo/thumbs/240p.vtt'],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
audio: {
|
audio: {
|
||||||
type: 'audio',
|
type: 'audio',
|
||||||
@@ -68,7 +71,7 @@ const sources = {
|
|||||||
type: 'video',
|
type: 'video',
|
||||||
sources: [
|
sources: [
|
||||||
{
|
{
|
||||||
src: 'https://vimeo.com/76979871',
|
src: 'https://vimeo.com/40648169',
|
||||||
provider: 'vimeo',
|
provider: 'vimeo',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const container = document.getElementById('container');
|
|||||||
const tabClassName = 'tab-focus';
|
const tabClassName = 'tab-focus';
|
||||||
|
|
||||||
// Remove class on blur
|
// Remove class on blur
|
||||||
document.addEventListener('focusout', event => {
|
document.addEventListener('focusout', (event) => {
|
||||||
if (!event.target.classList || container.contains(event.target)) {
|
if (!event.target.classList || container.contains(event.target)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ document.addEventListener('focusout', event => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Add classname to tabbed elements
|
// Add classname to tabbed elements
|
||||||
document.addEventListener('keydown', event => {
|
document.addEventListener('keydown', (event) => {
|
||||||
if (event.keyCode !== 9) {
|
if (event.keyCode !== 9) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
// Plyr.io Demo Page
|
// Plyr.io Demo Page
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
@charset 'UTF-8';
|
@charset 'UTF-8';
|
||||||
|
@import '../../../../src/sass/lib/css-vars';
|
||||||
|
|
||||||
|
$css-vars-use-native: true;
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
@import '../settings/breakpoints';
|
@import '../settings/breakpoints';
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.tab-focus {
|
&.tab-focus {
|
||||||
@include tab-focus();
|
@include tab-focus;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
// Count bubble
|
// Count bubble
|
||||||
.button__count {
|
.button__count {
|
||||||
animation: fadein 0.2s ease;
|
animation: fade-in 0.2s ease;
|
||||||
background: $color-button-count-background;
|
background: $color-button-count-background;
|
||||||
color: $color-button-count-text;
|
color: $color-button-count-text;
|
||||||
margin-left: ($spacing-base * 0.75);
|
margin-left: ($spacing-base * 0.75);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ header {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
h1 span {
|
h1 span {
|
||||||
animation: shrinkHide 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) 2s forwards;
|
animation: shrink-hide 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) 2s forwards;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
font-weight: $font-weight-light;
|
font-weight: $font-weight-light;
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// Icons
|
// Icons
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
|
@use 'sass:math';
|
||||||
|
|
||||||
// Base size icon styles
|
// Base size icon styles
|
||||||
.icon {
|
.icon {
|
||||||
fill: currentColor;
|
fill: currentColor;
|
||||||
@@ -19,5 +21,5 @@ label svg {
|
|||||||
|
|
||||||
a .icon,
|
a .icon,
|
||||||
.btn .icon {
|
.btn .icon {
|
||||||
margin-right: ($spacing-base / 2);
|
margin-right: math.div($spacing-base, 4);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
// Make a <button> look like an <a>
|
// Make a <button> look like an <a>
|
||||||
button.faux-link {
|
button.faux-link {
|
||||||
@extend a; // stylelint-disable-line
|
@extend a; // stylelint-disable-line
|
||||||
@include cancel-button-styles();
|
@include cancel-button-styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Links
|
// Links
|
||||||
@@ -39,7 +39,7 @@ a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.tab-focus {
|
&.tab-focus {
|
||||||
@include tab-focus();
|
@include tab-focus;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.no-border::after {
|
&.no-border::after {
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
// Examples
|
// Examples
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
|
@use 'sass:math';
|
||||||
|
|
||||||
// Example players
|
// Example players
|
||||||
.plyr {
|
.plyr {
|
||||||
border-radius: $border-radius-base;
|
border-radius: $border-radius-large;
|
||||||
box-shadow: 0 2px 15px rgba(#000, 0.1);
|
box-shadow: 0 2px 15px rgba(#000, 0.1);
|
||||||
margin: $spacing-base auto;
|
margin: $spacing-base auto;
|
||||||
|
|
||||||
@@ -28,9 +30,9 @@
|
|||||||
|
|
||||||
// Style full supported player
|
// Style full supported player
|
||||||
.plyr__cite {
|
.plyr__cite {
|
||||||
color: $color-gray-5;
|
color: $color-gray-500;
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
margin-right: ceil($spacing-base / 6);
|
margin-right: math.div($spacing-base, 6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// Core
|
// Core
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
|
@use 'sass:math';
|
||||||
|
|
||||||
html,
|
html,
|
||||||
body {
|
body {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -46,7 +48,7 @@ aside {
|
|||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
fill: $color-twitter;
|
fill: $color-twitter;
|
||||||
margin-right: ($spacing-base / 2);
|
margin-right: math.div($spacing-base, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
|
|||||||
@@ -3,23 +3,26 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
// Fade
|
// Fade
|
||||||
@keyframes fadein {
|
@keyframes fade-in {
|
||||||
0% {
|
0% {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
100% {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes shrinkHide {
|
@keyframes shrink-hide {
|
||||||
0% {
|
0% {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
width: 38px;
|
width: 38px;
|
||||||
}
|
}
|
||||||
|
|
||||||
20% {
|
20% {
|
||||||
width: 45px;
|
width: 45px;
|
||||||
}
|
}
|
||||||
|
|
||||||
100% {
|
100% {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
width: 0;
|
width: 0;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
font-family: 'Gordita';
|
font-family: Gordita;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: $font-weight-light;
|
font-weight: $font-weight-light;
|
||||||
src: url('https://cdn.plyr.io/static/fonts/gordita-light.woff2') format('woff2'),
|
src: url('https://cdn.plyr.io/static/fonts/gordita-light.woff2') format('woff2'),
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
font-family: 'Gordita';
|
font-family: Gordita;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: $font-weight-regular;
|
font-weight: $font-weight-regular;
|
||||||
src: url('https://cdn.plyr.io/static/fonts/gordita-regular.woff2') format('woff2'),
|
src: url('https://cdn.plyr.io/static/fonts/gordita-regular.woff2') format('woff2'),
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
font-family: 'Gordita';
|
font-family: Gordita;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: $font-weight-medium;
|
font-weight: $font-weight-medium;
|
||||||
src: url('https://cdn.plyr.io/static/fonts/gordita-medium.woff2') format('woff2'),
|
src: url('https://cdn.plyr.io/static/fonts/gordita-medium.woff2') format('woff2'),
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
font-family: 'Gordita';
|
font-family: Gordita;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: $font-weight-bold;
|
font-weight: $font-weight-bold;
|
||||||
src: url('https://cdn.plyr.io/static/fonts/gordita-bold.woff2') format('woff2'),
|
src: url('https://cdn.plyr.io/static/fonts/gordita-bold.woff2') format('woff2'),
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-display: swap;
|
font-display: swap;
|
||||||
font-family: 'Gordita';
|
font-family: Gordita;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: $font-weight-black;
|
font-weight: $font-weight-black;
|
||||||
src: url('https://cdn.plyr.io/static/fonts/gordita-black.woff2') format('woff2'),
|
src: url('https://cdn.plyr.io/static/fonts/gordita-black.woff2') format('woff2'),
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// Mixins
|
// Mixins
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
|
@use 'sass:math';
|
||||||
|
|
||||||
// Convert a <button> into an <a>
|
// Convert a <button> into an <a>
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
@mixin cancel-button-styles() {
|
@mixin cancel-button-styles() {
|
||||||
@@ -16,7 +18,7 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
text-align: inherit;
|
text-align: inherit;
|
||||||
text-shadow: inherit;
|
text-shadow: inherit;
|
||||||
-moz-user-select: text; // stylelint-disable-line
|
user-select: text;
|
||||||
vertical-align: baseline;
|
vertical-align: baseline;
|
||||||
width: auto;
|
width: auto;
|
||||||
}
|
}
|
||||||
@@ -32,7 +34,7 @@
|
|||||||
// Leave <body> at 100%/16px
|
// Leave <body> at 100%/16px
|
||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
@function calculate-rem($size) {
|
@function calculate-rem($size) {
|
||||||
$rem: $size / 16;
|
$rem: math.div($size, 16);
|
||||||
@return #{$rem}rem;
|
@return #{$rem}rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+8
-9
@@ -11,8 +11,7 @@
|
|||||||
|
|
||||||
html {
|
html {
|
||||||
line-height: 1.15; /* 1 */
|
line-height: 1.15; /* 1 */
|
||||||
-ms-text-size-adjust: 100%; /* 2 */
|
text-size-adjust: 100%; /* 2 */
|
||||||
-webkit-text-size-adjust: 100%; /* 2 */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sections
|
/* Sections
|
||||||
@@ -89,7 +88,7 @@ hr {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
font-family: monospace, monospace; /* 1 */
|
font-family: monospace; /* 1 */
|
||||||
font-size: 1em; /* 2 */
|
font-size: 1em; /* 2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +102,7 @@ pre {
|
|||||||
|
|
||||||
a {
|
a {
|
||||||
background-color: transparent; /* 1 */
|
background-color: transparent; /* 1 */
|
||||||
-webkit-text-decoration-skip: objects; /* 2 */
|
text-decoration-skip: objects; /* 2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,7 +111,7 @@ a {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
abbr[title] {
|
abbr[title] {
|
||||||
border-bottom: none; /* 1 */
|
border-bottom: 0; /* 1 */
|
||||||
text-decoration: underline; /* 2 */
|
text-decoration: underline; /* 2 */
|
||||||
text-decoration: underline dotted; /* 2 */
|
text-decoration: underline dotted; /* 2 */
|
||||||
}
|
}
|
||||||
@@ -281,7 +280,7 @@ button,
|
|||||||
html [type='button'],
|
html [type='button'],
|
||||||
[type='reset'],
|
[type='reset'],
|
||||||
[type='submit'] {
|
[type='submit'] {
|
||||||
-webkit-appearance: button; /* 2 */
|
appearance: button; /* 2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -375,7 +374,7 @@ textarea {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
[type='search'] {
|
[type='search'] {
|
||||||
-webkit-appearance: textfield; /* 1 */
|
appearance: textfield; /* 1 */
|
||||||
outline-offset: -2px; /* 2 */
|
outline-offset: -2px; /* 2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,7 +384,7 @@ textarea {
|
|||||||
|
|
||||||
[type='search']::-webkit-search-cancel-button,
|
[type='search']::-webkit-search-cancel-button,
|
||||||
[type='search']::-webkit-search-decoration {
|
[type='search']::-webkit-search-decoration {
|
||||||
-webkit-appearance: none;
|
appearance: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -394,7 +393,7 @@ textarea {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
::-webkit-file-upload-button {
|
::-webkit-file-upload-button {
|
||||||
-webkit-appearance: button; /* 1 */
|
appearance: button; /* 1 */
|
||||||
font: inherit; /* 2 */
|
font: inherit; /* 2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,22 +3,22 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
// Grayscale
|
// Grayscale
|
||||||
$color-gray-9: hsl(210, 15%, 16%);
|
$color-gray-900: hsl(210deg 15% 16%);
|
||||||
$color-gray-8: lighten($color-gray-9, 9%);
|
$color-gray-800: lighten($color-gray-900, 9%);
|
||||||
$color-gray-7: lighten($color-gray-8, 9%);
|
$color-gray-700: lighten($color-gray-800, 9%);
|
||||||
$color-gray-6: lighten($color-gray-7, 9%);
|
$color-gray-600: lighten($color-gray-700, 9%);
|
||||||
$color-gray-5: lighten($color-gray-6, 9%);
|
$color-gray-500: lighten($color-gray-600, 9%);
|
||||||
$color-gray-4: lighten($color-gray-5, 9%);
|
$color-gray-400: lighten($color-gray-500, 9%);
|
||||||
$color-gray-3: lighten($color-gray-4, 9%);
|
$color-gray-300: lighten($color-gray-400, 9%);
|
||||||
$color-gray-2: lighten($color-gray-3, 9%);
|
$color-gray-200: lighten($color-gray-300, 9%);
|
||||||
$color-gray-1: lighten($color-gray-2, 9%);
|
$color-gray-100: lighten($color-gray-200, 9%);
|
||||||
$color-gray-0: lighten($color-gray-1, 9%);
|
$color-gray-50: lighten($color-gray-100, 9%);
|
||||||
|
|
||||||
// Branding
|
// Branding
|
||||||
$color-brand-primary: hsl(198, 100%, 50%);
|
$color-brand-primary: hsl(198deg 100% 50%);
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
$color-text: $color-gray-7;
|
$color-text: $color-gray-700;
|
||||||
$color-headings: $color-brand-primary;
|
$color-headings: $color-brand-primary;
|
||||||
|
|
||||||
// Brands
|
// Brands
|
||||||
@@ -28,15 +28,15 @@ $color-twitter: #4baaf4;
|
|||||||
$color-link: $color-brand-primary;
|
$color-link: $color-brand-primary;
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
$color-background-from: hsl(198, 100%, 94%);
|
$color-background-from: hsl(198deg 100% 94%);
|
||||||
$color-background-to: hsl(198, 100%, 98%);
|
$color-background-to: hsl(198deg 100% 98%);
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
$color-button-background: $color-brand-primary;
|
$color-button-background: $color-brand-primary;
|
||||||
$color-button-text: #fff;
|
$color-button-text: #fff;
|
||||||
$color-button-background-hover: hsl(198, 100%, 55%);
|
$color-button-background-hover: hsl(198deg 100% 55%);
|
||||||
$color-button-count-background: #fff;
|
$color-button-count-background: #fff;
|
||||||
$color-button-count-text: $color-gray-6;
|
$color-button-count-text: $color-gray-600;
|
||||||
|
|
||||||
// Focus
|
// Focus
|
||||||
$tab-focus-default-color: #fff;
|
$tab-focus-default-color: #fff;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ $arrow-size: 5px;
|
|||||||
|
|
||||||
// Radii
|
// Radii
|
||||||
$border-radius-base: 4px;
|
$border-radius-base: 4px;
|
||||||
|
$border-radius-large: 8px;
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
$page-background: linear-gradient(to left top, $color-background-from, $color-background-to);
|
$page-background: linear-gradient(to left top, $color-background-from, $color-background-to);
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
// Layout
|
// Layout
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
$container-max-width: 1260px;
|
$container-max-width: 1240px;
|
||||||
|
|||||||
@@ -2,24 +2,17 @@
|
|||||||
// Plyr Settings
|
// Plyr Settings
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
// Font
|
@include css-vars(
|
||||||
$plyr-font-family: inherit;
|
(
|
||||||
|
--plyr-color-main: $color-brand-primary,
|
||||||
// Sizes
|
--plyr-font-size-base: 13px,
|
||||||
$plyr-font-size-base: 13px;
|
--plyr-font-size-small: 12px,
|
||||||
$plyr-font-size-small: 12px;
|
--plyr-font-size-time: 11px,
|
||||||
$plyr-font-size-time: 11px;
|
--plyr-font-size-badges: 9px,
|
||||||
$plyr-font-size-badges: 9px;
|
--plyr-font-size-menu: var(--plyr-font-size-base),
|
||||||
|
--plyr-font-weight-regular: 500,
|
||||||
// Other
|
--plyr-font-weight-bold: 600,
|
||||||
$plyr-font-smoothing: true;
|
--plyr-font-size-captions-medium: 18px,
|
||||||
|
--plyr-font-size-captions-large: 21px,
|
||||||
// Colors
|
)
|
||||||
$plyr-color-main: $color-brand-primary;
|
);
|
||||||
|
|
||||||
// Captions
|
|
||||||
$plyr-font-size-captions-base: $plyr-font-size-base;
|
|
||||||
$plyr-font-size-captions-small: $plyr-font-size-small;
|
|
||||||
$plyr-font-size-captions-medium: 18px;
|
|
||||||
$plyr-font-size-captions-large: 21px;
|
|
||||||
$plyr-font-size-menu: $plyr-font-size-base;
|
|
||||||
|
|||||||
@@ -4,18 +4,14 @@
|
|||||||
|
|
||||||
$font-sans-serif: 'Gordita', 'Avenir', 'Helvetica Neue', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
|
$font-sans-serif: 'Gordita', 'Avenir', 'Helvetica Neue', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
|
||||||
'Segoe UI Symbol';
|
'Segoe UI Symbol';
|
||||||
|
|
||||||
$font-size-base: 15;
|
$font-size-base: 15;
|
||||||
$font-size-small: 13;
|
$font-size-small: 13;
|
||||||
$font-size-large: 18;
|
$font-size-large: 18;
|
||||||
$font-size-h1: 64;
|
$font-size-h1: 64;
|
||||||
|
|
||||||
$font-weight-light: 300;
|
$font-weight-light: 300;
|
||||||
$font-weight-regular: 400;
|
$font-weight-regular: 400;
|
||||||
$font-weight-medium: 500;
|
$font-weight-medium: 500;
|
||||||
$font-weight-bold: 600;
|
$font-weight-bold: 600;
|
||||||
$font-weight-black: 900;
|
$font-weight-black: 900;
|
||||||
|
|
||||||
$line-height-base: 1.75;
|
$line-height-base: 1.75;
|
||||||
|
|
||||||
$letter-spacing-headings: -0.025em;
|
$letter-spacing-headings: -0.025em;
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@include font-smoothing();
|
@include font-smoothing;
|
||||||
@include font-size($font-size-base);
|
@include font-size($font-size-base);
|
||||||
|
|
||||||
color: $color-text;
|
color: $color-text;
|
||||||
font-family: $font-sans-serif;
|
font-family: $font-sans-serif;
|
||||||
font-weight: $font-weight-medium;
|
font-weight: $font-weight-medium;
|
||||||
@@ -30,5 +31,6 @@ small {
|
|||||||
|
|
||||||
small {
|
small {
|
||||||
@include font-size($font-size-small);
|
@include font-size($font-size-small);
|
||||||
|
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
@include font-size($font-size-h1);
|
@include font-size($font-size-h1);
|
||||||
|
|
||||||
color: $color-headings;
|
color: $color-headings;
|
||||||
font-weight: $font-weight-bold;
|
font-weight: $font-weight-bold;
|
||||||
letter-spacing: $letter-spacing-headings;
|
letter-spacing: $letter-spacing-headings;
|
||||||
|
|||||||
+65
-13
@@ -2,27 +2,79 @@
|
|||||||
# yarn lockfile v1
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
core-js@^3.1.4:
|
"@sentry/browser@^5.22.3":
|
||||||
version "3.1.4"
|
version "5.22.3"
|
||||||
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.1.4.tgz#3a2837fc48e582e1ae25907afcd6cf03b0cc7a07"
|
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-5.22.3.tgz#7a64bd1cf01bf393741a3e4bf35f82aa927f5b4e"
|
||||||
integrity sha512-YNZN8lt82XIMLnLirj9MhKDFZHalwzzrL9YLt6eb0T5D0EDl4IQ90IGkua8mHbnxNrkj1d8hbdizMc0Qmg1WnQ==
|
integrity sha512-2TzE/CoBa5ZkvxJizDdi1Iz1ldmXSJpFQ1mL07PIXBjCt0Wxf+WOuFSj5IP4L40XHfJE5gU8wEvSH0VDR8nXtA==
|
||||||
|
dependencies:
|
||||||
|
"@sentry/core" "5.22.3"
|
||||||
|
"@sentry/types" "5.22.3"
|
||||||
|
"@sentry/utils" "5.22.3"
|
||||||
|
tslib "^1.9.3"
|
||||||
|
|
||||||
|
"@sentry/core@5.22.3":
|
||||||
|
version "5.22.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.22.3.tgz#030f435f2b518f282ba8bd954dac90cd70888bd7"
|
||||||
|
integrity sha512-eGL5uUarw3o4i9QUb9JoFHnhriPpWCaqeaIBB06HUpdcvhrjoowcKZj1+WPec5lFg5XusE35vez7z/FPzmJUDw==
|
||||||
|
dependencies:
|
||||||
|
"@sentry/hub" "5.22.3"
|
||||||
|
"@sentry/minimal" "5.22.3"
|
||||||
|
"@sentry/types" "5.22.3"
|
||||||
|
"@sentry/utils" "5.22.3"
|
||||||
|
tslib "^1.9.3"
|
||||||
|
|
||||||
|
"@sentry/hub@5.22.3":
|
||||||
|
version "5.22.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-5.22.3.tgz#08309a70d2ea8d5e313d05840c1711f34f2fffe5"
|
||||||
|
integrity sha512-INo47m6N5HFEs/7GMP9cqxOIt7rmRxdERunA3H2L37owjcr77MwHVeeJ9yawRS6FMtbWXplgWTyTIWIYOuqVbw==
|
||||||
|
dependencies:
|
||||||
|
"@sentry/types" "5.22.3"
|
||||||
|
"@sentry/utils" "5.22.3"
|
||||||
|
tslib "^1.9.3"
|
||||||
|
|
||||||
|
"@sentry/minimal@5.22.3":
|
||||||
|
version "5.22.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.22.3.tgz#706e4029ae5494123d3875c658ba8911aa5cc440"
|
||||||
|
integrity sha512-HoINpYnVYCpNjn2XIPIlqH5o4BAITpTljXjtAftOx6Hzj+Opjg8tR8PWliyKDvkXPpc4kXK9D6TpEDw8MO0wZA==
|
||||||
|
dependencies:
|
||||||
|
"@sentry/hub" "5.22.3"
|
||||||
|
"@sentry/types" "5.22.3"
|
||||||
|
tslib "^1.9.3"
|
||||||
|
|
||||||
|
"@sentry/types@5.22.3":
|
||||||
|
version "5.22.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-5.22.3.tgz#d1d547b30ee8bd7771fa893af74c4f3d71f0fd18"
|
||||||
|
integrity sha512-cv+VWK0YFgCVDvD1/HrrBWOWYG3MLuCUJRBTkV/Opdy7nkdNjhCAJQrEyMM9zX0sac8FKWKOHT0sykNh8KgmYw==
|
||||||
|
|
||||||
|
"@sentry/utils@5.22.3":
|
||||||
|
version "5.22.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.22.3.tgz#e3bda3e789239eb16d436f768daa12829f33d18f"
|
||||||
|
integrity sha512-AHNryXMBvIkIE+GQxTlmhBXD0Ksh+5w1SwM5qi6AttH+1qjWLvV6WB4+4pvVvEoS8t5F+WaVUZPQLmCCWp6zKw==
|
||||||
|
dependencies:
|
||||||
|
"@sentry/types" "5.22.3"
|
||||||
|
tslib "^1.9.3"
|
||||||
|
|
||||||
|
core-js@^3.6.5:
|
||||||
|
version "3.6.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.5.tgz#7395dc273af37fb2e50e9bd3d9fe841285231d1a"
|
||||||
|
integrity sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==
|
||||||
|
|
||||||
custom-event-polyfill@^1.0.7:
|
custom-event-polyfill@^1.0.7:
|
||||||
version "1.0.7"
|
version "1.0.7"
|
||||||
resolved "https://registry.yarnpkg.com/custom-event-polyfill/-/custom-event-polyfill-1.0.7.tgz#9bc993ddda937c1a30ccd335614c6c58c4f87aee"
|
resolved "https://registry.yarnpkg.com/custom-event-polyfill/-/custom-event-polyfill-1.0.7.tgz#9bc993ddda937c1a30ccd335614c6c58c4f87aee"
|
||||||
integrity sha512-TDDkd5DkaZxZFM8p+1I3yAlvM3rSr1wbrOliG4yJiwinMZN8z/iGL7BTlDkrJcYTmgUSb4ywVCc3ZaUtOtC76w==
|
integrity sha512-TDDkd5DkaZxZFM8p+1I3yAlvM3rSr1wbrOliG4yJiwinMZN8z/iGL7BTlDkrJcYTmgUSb4ywVCc3ZaUtOtC76w==
|
||||||
|
|
||||||
raven-js@^3.27.2:
|
|
||||||
version "3.27.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/raven-js/-/raven-js-3.27.2.tgz#6c33df952026cd73820aa999122b7b7737a66775"
|
|
||||||
integrity sha512-mFWQcXnhRFEQe5HeFroPaEghlnqy7F5E2J3Fsab189ondqUzcjwSVi7el7F36cr6PvQYXoZ1P2F5CSF2/azeMQ==
|
|
||||||
|
|
||||||
shr-buttons@2.0.3:
|
shr-buttons@2.0.3:
|
||||||
version "2.0.3"
|
version "2.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/shr-buttons/-/shr-buttons-2.0.3.tgz#2ffd021fc3d789e1510ce2736b938bd09ea1da5a"
|
resolved "https://registry.yarnpkg.com/shr-buttons/-/shr-buttons-2.0.3.tgz#2ffd021fc3d789e1510ce2736b938bd09ea1da5a"
|
||||||
integrity sha512-sPAgHiw4uaIt9TnxTfyZEedDChcldSVtnBHE44cpe/mSC7rqm4IEKZRLYqnVlTcGM+FSDNBPUNpSf50Q2ntd+w==
|
integrity sha512-sPAgHiw4uaIt9TnxTfyZEedDChcldSVtnBHE44cpe/mSC7rqm4IEKZRLYqnVlTcGM+FSDNBPUNpSf50Q2ntd+w==
|
||||||
|
|
||||||
url-polyfill@^1.1.5:
|
tslib@^1.9.3:
|
||||||
version "1.1.5"
|
version "1.11.1"
|
||||||
resolved "https://registry.yarnpkg.com/url-polyfill/-/url-polyfill-1.1.5.tgz#bec79b72b5407dba6d8cced2e32e4ab273aa9fb1"
|
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35"
|
||||||
integrity sha512-9XjIJ6nwrU+nGd8t90Ze0Zs7t8A+SU0gqsqPttj6j3zAVe5q0HFcuv37nDBdVSPpi4aTHTfbUF/i+ZVD+o2EbA==
|
integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==
|
||||||
|
|
||||||
|
url-polyfill@^1.1.10:
|
||||||
|
version "1.1.10"
|
||||||
|
resolved "https://registry.yarnpkg.com/url-polyfill/-/url-polyfill-1.1.10.tgz#fd5bbcf66c9491fa682b0cb6d6a855e1643a9281"
|
||||||
|
integrity sha512-vSaPpaRgBrf41+Uky1myiSh6gpcbw8FpwHYnEy0abxndojOBnIs+yh/49gKYFLtUMP9qoNWjn6j9aUVy23Ie2A==
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
-9131
File diff suppressed because it is too large
Load Diff
Vendored
-2
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
-9123
File diff suppressed because it is too large
Load Diff
Vendored
-15039
File diff suppressed because it is too large
Load Diff
Vendored
-2
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
-15031
File diff suppressed because it is too large
Load Diff
Vendored
-1
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 5.4 KiB |
+2
-487
@@ -1,493 +1,8 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// Gulp build script
|
// Gulp build script
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
/* global require, __dirname */
|
|
||||||
/* eslint no-console: "off" */
|
|
||||||
|
|
||||||
const path = require('path');
|
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
// ------------------------------------
|
const HubRegistry = require('gulp-hub');
|
||||||
// JavaScript
|
|
||||||
// ------------------------------------
|
|
||||||
const terser = require('gulp-terser');
|
|
||||||
const rollup = require('gulp-better-rollup');
|
|
||||||
const babel = require('rollup-plugin-babel');
|
|
||||||
const commonjs = require('rollup-plugin-commonjs');
|
|
||||||
const resolve = require('rollup-plugin-node-resolve');
|
|
||||||
// ------------------------------------
|
|
||||||
// CSS
|
|
||||||
// ------------------------------------
|
|
||||||
const sass = require('gulp-sass');
|
|
||||||
const clean = require('gulp-clean-css');
|
|
||||||
const prefix = require('gulp-autoprefixer');
|
|
||||||
// ------------------------------------
|
|
||||||
// Images
|
|
||||||
// ------------------------------------
|
|
||||||
const svgstore = require('gulp-svgstore');
|
|
||||||
const imagemin = require('gulp-imagemin');
|
|
||||||
// ------------------------------------
|
|
||||||
// Utils
|
|
||||||
// ------------------------------------
|
|
||||||
const del = require('del');
|
|
||||||
const filter = require('gulp-filter');
|
|
||||||
const header = require('gulp-header');
|
|
||||||
const gitbranch = require('git-branch');
|
|
||||||
const rename = require('gulp-rename');
|
|
||||||
const replace = require('gulp-replace');
|
|
||||||
const ansi = require('ansi-colors');
|
|
||||||
const log = require('fancy-log');
|
|
||||||
const open = require('gulp-open');
|
|
||||||
const plumber = require('gulp-plumber');
|
|
||||||
const size = require('gulp-size');
|
|
||||||
const sourcemaps = require('gulp-sourcemaps');
|
|
||||||
const through = require('through2');
|
|
||||||
// ------------------------------------
|
|
||||||
// Deployment
|
|
||||||
// ------------------------------------
|
|
||||||
const aws = require('aws-sdk');
|
|
||||||
const publish = require('gulp-awspublish');
|
|
||||||
const FastlyPurge = require('fastly-purge');
|
|
||||||
// ------------------------------------
|
|
||||||
// Configs
|
|
||||||
// ------------------------------------
|
|
||||||
const pkg = require('./package.json');
|
|
||||||
const build = require('./build.json');
|
|
||||||
const deploy = require('./deploy.json');
|
|
||||||
// ------------------------------------
|
|
||||||
// Info from package
|
|
||||||
// ------------------------------------
|
|
||||||
const { browserslist: browsers, version } = pkg;
|
|
||||||
const minSuffix = '.min';
|
|
||||||
|
|
||||||
// Get AWS config
|
gulp.registry(new HubRegistry(['tasks/*.js']));
|
||||||
Object.values(deploy).forEach(target => {
|
|
||||||
Object.assign(target, {
|
|
||||||
publisher: publish.create({
|
|
||||||
region: target.region,
|
|
||||||
params: {
|
|
||||||
Bucket: target.bucket,
|
|
||||||
},
|
|
||||||
credentials: new aws.SharedIniFileCredentials({ profile: 'plyr' }),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Paths
|
|
||||||
const paths = {
|
|
||||||
plyr: {
|
|
||||||
// Source paths
|
|
||||||
src: {
|
|
||||||
sass: path.join(__dirname, 'src/sass/**/*.scss'),
|
|
||||||
js: path.join(__dirname, 'src/js/**/*.js'),
|
|
||||||
sprite: path.join(__dirname, 'src/sprite/*.svg'),
|
|
||||||
},
|
|
||||||
|
|
||||||
// Output paths
|
|
||||||
output: path.join(__dirname, 'dist/'),
|
|
||||||
},
|
|
||||||
demo: {
|
|
||||||
// Source paths
|
|
||||||
src: {
|
|
||||||
sass: path.join(__dirname, 'demo/src/sass/**/*.scss'),
|
|
||||||
js: path.join(__dirname, 'demo/src/js/**/*.js'),
|
|
||||||
},
|
|
||||||
|
|
||||||
// Output paths
|
|
||||||
output: path.join(__dirname, 'demo/dist/'),
|
|
||||||
|
|
||||||
// Demo
|
|
||||||
root: path.join(__dirname, 'demo/'),
|
|
||||||
},
|
|
||||||
upload: [
|
|
||||||
path.join(__dirname, `dist/*${minSuffix}.*`),
|
|
||||||
path.join(__dirname, 'dist/*.css'),
|
|
||||||
path.join(__dirname, 'dist/*.svg'),
|
|
||||||
path.join(__dirname, `demo/dist/*${minSuffix}.*`),
|
|
||||||
path.join(__dirname, 'demo/dist/*.css'),
|
|
||||||
path.join(__dirname, 'demo/dist/*.svg'),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
// Task arrays
|
|
||||||
const tasks = {
|
|
||||||
css: [],
|
|
||||||
js: [],
|
|
||||||
sprite: [],
|
|
||||||
clean: 'clean',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Size plugin
|
|
||||||
const sizeOptions = { showFiles: true, gzip: true };
|
|
||||||
|
|
||||||
// Clean out /dist
|
|
||||||
gulp.task(tasks.clean, done => {
|
|
||||||
const dirs = [paths.plyr.output, paths.demo.output].map(dir => path.join(dir, '**/*'));
|
|
||||||
|
|
||||||
// Don't delete the mp4
|
|
||||||
dirs.push(`!${path.join(paths.plyr.output, '**/*.mp4')}`);
|
|
||||||
|
|
||||||
del(dirs);
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
// JavaScript
|
|
||||||
Object.entries(build.js).forEach(([filename, entry]) => {
|
|
||||||
const { dist, formats, namespace, polyfill, src } = entry;
|
|
||||||
|
|
||||||
formats.forEach(format => {
|
|
||||||
const name = `js:${filename}:${format}`;
|
|
||||||
const extension = format === 'es' ? 'mjs' : 'js';
|
|
||||||
tasks.js.push(name);
|
|
||||||
|
|
||||||
gulp.task(name, () =>
|
|
||||||
gulp
|
|
||||||
.src(src)
|
|
||||||
.pipe(plumber())
|
|
||||||
.pipe(sourcemaps.init())
|
|
||||||
.pipe(
|
|
||||||
rollup(
|
|
||||||
{
|
|
||||||
plugins: [
|
|
||||||
resolve(),
|
|
||||||
commonjs(),
|
|
||||||
babel({
|
|
||||||
presets: [
|
|
||||||
[
|
|
||||||
'@babel/env',
|
|
||||||
{
|
|
||||||
// debug: true,
|
|
||||||
useBuiltIns: polyfill ? 'usage' : false,
|
|
||||||
corejs: polyfill ? 3 : undefined,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
babelrc: false,
|
|
||||||
exclude: [/\/core-js\//],
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: namespace,
|
|
||||||
format,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.pipe(header('typeof navigator === "object" && ')) // "Support" SSR (#935)
|
|
||||||
.pipe(
|
|
||||||
rename({
|
|
||||||
extname: `.${extension}`,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.pipe(gulp.dest(dist))
|
|
||||||
.pipe(filter(`**/*.${extension}`))
|
|
||||||
.pipe(terser())
|
|
||||||
.pipe(rename({ suffix: minSuffix }))
|
|
||||||
.pipe(size(sizeOptions))
|
|
||||||
.pipe(sourcemaps.write(''))
|
|
||||||
.pipe(gulp.dest(dist)),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// CSS
|
|
||||||
Object.entries(build.css).forEach(([filename, entry]) => {
|
|
||||||
const { dist, src } = entry;
|
|
||||||
const name = `css:${filename}`;
|
|
||||||
tasks.css.push(name);
|
|
||||||
|
|
||||||
gulp.task(name, () =>
|
|
||||||
gulp
|
|
||||||
.src(src)
|
|
||||||
.pipe(plumber())
|
|
||||||
.pipe(sass())
|
|
||||||
.pipe(
|
|
||||||
prefix(browsers, {
|
|
||||||
cascade: false,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.pipe(clean())
|
|
||||||
.pipe(size(sizeOptions))
|
|
||||||
.pipe(gulp.dest(dist)),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// SVG Sprites
|
|
||||||
Object.entries(build.sprite).forEach(([filename, entry]) => {
|
|
||||||
const { dist, src } = entry;
|
|
||||||
const name = `sprite:${filename}`;
|
|
||||||
tasks.sprite.push(name);
|
|
||||||
|
|
||||||
gulp.task(name, () =>
|
|
||||||
gulp
|
|
||||||
.src(src)
|
|
||||||
.pipe(plumber())
|
|
||||||
.pipe(imagemin())
|
|
||||||
.pipe(svgstore())
|
|
||||||
.pipe(rename({ basename: path.parse(filename).name }))
|
|
||||||
.pipe(size(sizeOptions))
|
|
||||||
.pipe(gulp.dest(dist)),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Build all JS
|
|
||||||
gulp.task('js', () => gulp.parallel(...tasks.js));
|
|
||||||
|
|
||||||
// Watch for file changes
|
|
||||||
gulp.task('watch', () => {
|
|
||||||
// Plyr core
|
|
||||||
gulp.watch(paths.plyr.src.js, gulp.parallel(...tasks.js));
|
|
||||||
gulp.watch(paths.plyr.src.sass, gulp.parallel(...tasks.css));
|
|
||||||
gulp.watch(paths.plyr.src.sprite, gulp.parallel(...tasks.sprite));
|
|
||||||
|
|
||||||
// Demo
|
|
||||||
gulp.watch(paths.demo.src.js, gulp.parallel(...tasks.js));
|
|
||||||
gulp.watch(paths.demo.src.sass, gulp.parallel(...tasks.css));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Build distribution
|
|
||||||
gulp.task('build', gulp.series(tasks.clean, gulp.parallel(...tasks.js, ...tasks.css, ...tasks.sprite)));
|
|
||||||
|
|
||||||
// Default gulp task
|
|
||||||
gulp.task('default', gulp.series('build', 'watch'));
|
|
||||||
|
|
||||||
// Publish a version to CDN and demo
|
|
||||||
// --------------------------------------------
|
|
||||||
// Get deployment config
|
|
||||||
let credentials = {};
|
|
||||||
try {
|
|
||||||
credentials = require('./credentials.json'); //eslint-disable-line
|
|
||||||
} catch (e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get branch info
|
|
||||||
const branch = {
|
|
||||||
current: gitbranch.sync(),
|
|
||||||
master: 'master',
|
|
||||||
beta: 'beta',
|
|
||||||
};
|
|
||||||
|
|
||||||
const maxAge = 31536000; // 1 year
|
|
||||||
const options = {
|
|
||||||
cdn: {
|
|
||||||
headers: {
|
|
||||||
'Cache-Control': `max-age=${maxAge}`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
demo: {
|
|
||||||
uploadPath: branch.current === branch.beta ? 'beta' : null,
|
|
||||||
headers: {
|
|
||||||
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
symlinks(ver, filename) {
|
|
||||||
return {
|
|
||||||
headers: {
|
|
||||||
// http://stackoverflow.com/questions/2272835/amazon-s3-object-redirect
|
|
||||||
'x-amz-website-redirect-location': `/${ver}/${filename}`,
|
|
||||||
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const regex =
|
|
||||||
'(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*).(?:0|[1-9][0-9]*)(?:-[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?(?:\\+[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?';
|
|
||||||
const semver = new RegExp(`v${regex}`, 'gi');
|
|
||||||
const localPath = new RegExp('(../)?dist', 'gi');
|
|
||||||
const versionPath = `https://${deploy.cdn.domain}/${version}`;
|
|
||||||
const cdnpath = new RegExp(`${deploy.cdn.domain}/${regex}/`, 'gi');
|
|
||||||
|
|
||||||
const renameFile = rename(p => {
|
|
||||||
p.basename = p.basename.replace(minSuffix, ''); // eslint-disable-line
|
|
||||||
p.dirname = p.dirname.replace('.', version); // eslint-disable-line
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check we're on the correct branch to deploy
|
|
||||||
const canDeploy = () => {
|
|
||||||
const allowed = [branch.master, branch.beta];
|
|
||||||
|
|
||||||
if (!allowed.includes(branch.current)) {
|
|
||||||
console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
gulp.task('version', done => {
|
|
||||||
if (!canDeploy()) {
|
|
||||||
done();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { domain } = deploy.cdn;
|
|
||||||
|
|
||||||
log(`Uploading ${ansi.green.bold(version)} to ${ansi.cyan(domain)}...`);
|
|
||||||
|
|
||||||
// Replace versioned URLs in source
|
|
||||||
const files = ['plyr.js', 'plyr.polyfilled.js', 'config/defaults.js'];
|
|
||||||
|
|
||||||
return gulp
|
|
||||||
.src(files.map(file => path.join(__dirname, `src/js/${file}`)), { base: '.' })
|
|
||||||
.pipe(replace(semver, `v${version}`))
|
|
||||||
.pipe(replace(cdnpath, `${domain}/${version}/`))
|
|
||||||
.pipe(gulp.dest('./'));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Publish version to CDN bucket
|
|
||||||
gulp.task('cdn', done => {
|
|
||||||
if (!canDeploy()) {
|
|
||||||
done();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { domain, publisher } = deploy.cdn;
|
|
||||||
|
|
||||||
if (!publisher) {
|
|
||||||
throw new Error('No publisher instance. Check AWS configuration.');
|
|
||||||
}
|
|
||||||
|
|
||||||
log(`Uploading ${ansi.green.bold(pkg.version)} to ${ansi.cyan(domain)}...`);
|
|
||||||
|
|
||||||
// Upload to CDN
|
|
||||||
return (
|
|
||||||
gulp
|
|
||||||
.src(paths.upload)
|
|
||||||
.pipe(renameFile)
|
|
||||||
// Remove min suffix from source map URL
|
|
||||||
.pipe(
|
|
||||||
replace(
|
|
||||||
/sourceMappingURL=([\w-?.]+)/,
|
|
||||||
(match, filename) => `sourceMappingURL=${filename.replace(minSuffix, '')}`,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.pipe(size(sizeOptions))
|
|
||||||
.pipe(replace(localPath, versionPath))
|
|
||||||
.pipe(publisher.publish(options.cdn.headers))
|
|
||||||
.pipe(publish.reporter())
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Purge the fastly cache incase any 403/404 are cached
|
|
||||||
gulp.task('purge', () => {
|
|
||||||
if (!Object.keys(credentials).includes('fastly')) {
|
|
||||||
throw new Error('Fastly credentials required to purge cache.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { fastly } = credentials;
|
|
||||||
const list = [];
|
|
||||||
|
|
||||||
return gulp
|
|
||||||
.src(paths.upload)
|
|
||||||
.pipe(
|
|
||||||
through.obj((file, enc, cb) => {
|
|
||||||
const filename = file.path.split('/').pop();
|
|
||||||
list.push(`${versionPath}/${filename.replace(minSuffix, '')}`);
|
|
||||||
cb(null);
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.on('end', () => {
|
|
||||||
const purge = new FastlyPurge(fastly.token);
|
|
||||||
|
|
||||||
list.forEach(url => {
|
|
||||||
log(`Purging ${ansi.cyan(url)}...`);
|
|
||||||
|
|
||||||
purge.url(url, (error, result) => {
|
|
||||||
if (error) {
|
|
||||||
log.error(error);
|
|
||||||
} else if (result) {
|
|
||||||
log(result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Publish to demo bucket
|
|
||||||
gulp.task('demo', done => {
|
|
||||||
if (!canDeploy()) {
|
|
||||||
done();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { publisher } = deploy.demo;
|
|
||||||
const { domain } = deploy.cdn;
|
|
||||||
|
|
||||||
if (!publisher) {
|
|
||||||
throw new Error('No publisher instance. Check AWS configuration.');
|
|
||||||
}
|
|
||||||
|
|
||||||
log(`Uploading ${ansi.green.bold(pkg.version)} to ${ansi.cyan(domain)}...`);
|
|
||||||
|
|
||||||
// Replace versioned files in readme.md
|
|
||||||
gulp.src([`${__dirname}/readme.md`])
|
|
||||||
.pipe(replace(cdnpath, `${domain}/${version}/`))
|
|
||||||
.pipe(gulp.dest(__dirname));
|
|
||||||
|
|
||||||
// Replace local file paths with remote paths in demo HTML
|
|
||||||
// e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
|
|
||||||
const index = `${paths.demo.root}index.html`;
|
|
||||||
const error = `${paths.demo.root}error.html`;
|
|
||||||
const pages = [index];
|
|
||||||
|
|
||||||
if (branch.current === branch.master) {
|
|
||||||
pages.push(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return gulp
|
|
||||||
.src(pages)
|
|
||||||
.pipe(replace(localPath, versionPath))
|
|
||||||
.pipe(publisher.publish(options.demo.headers))
|
|
||||||
.pipe(publish.reporter());
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('error', done => {
|
|
||||||
// Only update CDN for master (prod)
|
|
||||||
if (!canDeploy() || branch.current !== branch.master) {
|
|
||||||
done();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { publisher } = deploy.cdn;
|
|
||||||
|
|
||||||
if (!publisher) {
|
|
||||||
throw new Error('No publisher instance. Check AWS configuration.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace local file paths with remote paths in demo HTML
|
|
||||||
// e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
|
|
||||||
// Upload error.html to cdn
|
|
||||||
return gulp
|
|
||||||
.src(`${paths.demo.root}error.html`)
|
|
||||||
.pipe(replace(localPath, versionPath))
|
|
||||||
.pipe(publisher.publish(options.demo.headers))
|
|
||||||
.pipe(publish.reporter());
|
|
||||||
});
|
|
||||||
|
|
||||||
// Open the demo site to check it's ok
|
|
||||||
gulp.task('open', () => {
|
|
||||||
const { domain } = deploy.demo;
|
|
||||||
|
|
||||||
return gulp.src(__filename).pipe(
|
|
||||||
open({
|
|
||||||
uri: `https://${domain}/${branch.current === branch.beta ? 'beta' : ''}`,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Do everything
|
|
||||||
gulp.task(
|
|
||||||
'deploy',
|
|
||||||
gulp.series(
|
|
||||||
'version',
|
|
||||||
tasks.clean,
|
|
||||||
gulp.parallel(...tasks.js, ...tasks.css, ...tasks.sprite),
|
|
||||||
'cdn',
|
|
||||||
'demo',
|
|
||||||
'purge',
|
|
||||||
'open',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|||||||
+55
-51
@@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "plyr",
|
"name": "plyr",
|
||||||
"version": "3.5.6",
|
"version": "3.7.0",
|
||||||
"description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player",
|
"description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player",
|
||||||
"homepage": "https://plyr.io",
|
"homepage": "https://plyr.io",
|
||||||
"author": "Sam Potts <sam@potts.es>",
|
"author": "Sam Potts <sam@potts.es>",
|
||||||
"main": "dist/plyr.js",
|
"main": "dist/plyr.js",
|
||||||
|
"types": "src/js/plyr.d.ts",
|
||||||
"module": "dist/plyr.min.mjs",
|
"module": "dist/plyr.min.mjs",
|
||||||
"jsnext:main": "dist/plyr.min.mjs",
|
"jsnext:main": "dist/plyr.min.mjs",
|
||||||
"browser": "dist/plyr.min.js",
|
"browser": "dist/plyr.min.js",
|
||||||
@@ -30,67 +31,70 @@
|
|||||||
"browserslist": "> 1%",
|
"browserslist": "> 1%",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "gulp build",
|
"build": "gulp build",
|
||||||
"lint": "eslint src/js && npm run-script remark",
|
"lint": "eslint src/js && npm run remark && stylelint **/*.scss",
|
||||||
"lint:fix": "eslint --fix src/js",
|
"lint:fix": "eslint --fix src/js && stylelint **/*.scss --fix",
|
||||||
"remark": "remark -f --use 'validate-links=repository:\"sampotts/plyr\"' '{,!(node_modules),.?**/}*.md'",
|
"remark": "remark -f --use 'validate-links=repository:\"sampotts/plyr\"' '{,!(node_modules),.?**/}*.md'",
|
||||||
"deploy": "yarn lint && gulp deploy"
|
"deploy": "yarn lint && gulp version && gulp build && gulp deploy",
|
||||||
|
"format": "prettier --write \"./{src,demo/src}/**/*.{js,scss}\"",
|
||||||
|
"spellcheck": "cspell \"**/*.{js,md,scss,json}\" --no-must-find-files",
|
||||||
|
"start": "gulp"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ansi-colors": "^4.0.1",
|
"@babel/core": "^7.17.9",
|
||||||
"aws-sdk": "^2.478.0",
|
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
||||||
"@babel/core": "^7.4.5",
|
"@babel/preset-env": "^7.16.11",
|
||||||
"@babel/preset-env": "^7.4.5",
|
"@sampotts/eslint-config": "1.1.7",
|
||||||
"babel-eslint": "^10.0.2",
|
"autoprefixer": "^10.4.4",
|
||||||
"del": "^4.1.1",
|
"aws-sdk": "^2.1116.0",
|
||||||
"eslint": "^5.16.0",
|
"babel-eslint": "^10.1.0",
|
||||||
"eslint-config-airbnb-base": "^13.1.0",
|
"browser-sync": "^2.27.9",
|
||||||
"eslint-config-prettier": "^5.0.0",
|
"colorette": "2.0.16",
|
||||||
"eslint-plugin-import": "^2.17.3",
|
"cspell": "^5.19.7",
|
||||||
"eslint-plugin-simple-import-sort": "^4.0.0",
|
"cssnano": "^5.1.7",
|
||||||
"fancy-log": "^1.3.3",
|
"del": "^6.0.0",
|
||||||
"fastly-purge": "^1.0.1",
|
"eslint": "^7.23.0",
|
||||||
|
"fancy-log": "^2.0.0",
|
||||||
"git-branch": "^2.0.1",
|
"git-branch": "^2.0.1",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
"gulp-autoprefixer": "^6.1.0",
|
"gulp-awspublish": "^6.0.2",
|
||||||
"gulp-awspublish": "^4.0.0",
|
|
||||||
"gulp-better-rollup": "^4.0.1",
|
"gulp-better-rollup": "^4.0.1",
|
||||||
"gulp-clean-css": "^4.2.0",
|
"gulp-filter": "^7.0.0",
|
||||||
"gulp-filter": "^6.0.0",
|
"gulp-header": "^2.0.9",
|
||||||
"gulp-header": "^2.0.7",
|
"gulp-hub": "^4.2.0",
|
||||||
"gulp-imagemin": "^6.0.0",
|
"gulp-if": "^3.0.0",
|
||||||
|
"gulp-imagemin": "^7.1.0",
|
||||||
"gulp-open": "^3.0.1",
|
"gulp-open": "^3.0.1",
|
||||||
"gulp-plumber": "^1.2.1",
|
"gulp-plumber": "^1.2.1",
|
||||||
"gulp-postcss": "^8.0.0",
|
"gulp-postcss": "^9.0.1",
|
||||||
"gulp-rename": "^1.4.0",
|
"gulp-rename": "^2.0.0",
|
||||||
"gulp-replace": "^1.0.0",
|
"gulp-replace": "^1.1.3",
|
||||||
"gulp-sass": "^4.0.2",
|
"gulp-sass": "^5.1.0",
|
||||||
"gulp-size": "^3.0.0",
|
"gulp-size": "^4.0.1",
|
||||||
"gulp-sourcemaps": "^2.6.5",
|
"gulp-sourcemaps": "^3.0.0",
|
||||||
"gulp-svgstore": "^7.0.1",
|
"gulp-svgstore": "^9.0.0",
|
||||||
"gulp-terser": "^1.2.0",
|
"gulp-terser": "^2.1.0",
|
||||||
"postcss-custom-properties": "^9.0.1",
|
"postcss": "^8.4.12",
|
||||||
"prettier-eslint": "^9.0.0",
|
"postcss-custom-properties": "^12.1.7",
|
||||||
|
"postcss-scss": "^4.0.3",
|
||||||
|
"prettier-eslint": "^12.0.0",
|
||||||
"prettier-stylelint": "^0.4.2",
|
"prettier-stylelint": "^0.4.2",
|
||||||
"remark-cli": "^6.0.1",
|
"remark-cli": "^10.0.1",
|
||||||
"remark-validate-links": "^8.0.3",
|
"remark-validate-links": "^11.0.2",
|
||||||
"rollup": "^1.15.6",
|
"rollup": "^2.70.2",
|
||||||
"rollup-plugin-babel": "^4.3.2",
|
"rollup-plugin-babel": "^4.4.0",
|
||||||
"rollup-plugin-commonjs": "^10.0.0",
|
"rollup-plugin-commonjs": "^10.1.0",
|
||||||
"rollup-plugin-node-resolve": "^5.0.3",
|
"rollup-plugin-node-resolve": "^5.2.0",
|
||||||
"stylelint": "^10.1.0",
|
"sass": "^1.50.0",
|
||||||
"stylelint-config-prettier": "^5.2.0",
|
"stylelint": "^14.7.1",
|
||||||
"stylelint-config-recommended": "^2.2.0",
|
"stylelint-config-prettier": "^9.0.3",
|
||||||
"stylelint-config-sass-guidelines": "^6.0.0",
|
"stylelint-config-sass-guidelines": "^9.0.1",
|
||||||
"stylelint-order": "^3.0.0",
|
"stylelint-selector-bem-pattern": "^2.1.1"
|
||||||
"stylelint-scss": "^3.8.0",
|
|
||||||
"stylelint-selector-bem-pattern": "^2.1.0",
|
|
||||||
"through2": "^3.0.1"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"core-js": "^3.1.4",
|
"core-js": "^3.22.0",
|
||||||
"custom-event-polyfill": "^1.0.7",
|
"custom-event-polyfill": "^1.0.7",
|
||||||
"loadjs": "^3.6.1",
|
"loadjs": "^4.2.0",
|
||||||
"rangetouch": "^2.0.0",
|
"rangetouch": "^2.0.1",
|
||||||
"url-polyfill": "^1.1.5"
|
"url-polyfill": "^1.1.12"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-6
@@ -9,22 +9,31 @@
|
|||||||
"**/node_modules": true,
|
"**/node_modules": true,
|
||||||
"**/dist": true
|
"**/dist": true
|
||||||
},
|
},
|
||||||
|
|
||||||
// Linting
|
// Linting
|
||||||
"stylelint.enable": true,
|
"stylelint.enable": true,
|
||||||
|
"stylelint.validate": ["css", "scss"],
|
||||||
"css.validate": false,
|
"css.validate": false,
|
||||||
|
"less.validate": false,
|
||||||
"scss.validate": false,
|
"scss.validate": false,
|
||||||
"javascript.validate.enable": false,
|
"javascript.validate.enable": false,
|
||||||
|
|
||||||
// Prettier
|
|
||||||
"prettier.eslintIntegration": true,
|
|
||||||
"prettier.stylelintIntegration": true,
|
|
||||||
|
|
||||||
// Formatting
|
// Formatting
|
||||||
"editor.tabSize": 4,
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"editor.tabSize": 2,
|
||||||
"editor.insertSpaces": true,
|
"editor.insertSpaces": true,
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
|
|
||||||
// Trim on save
|
// Trim on save
|
||||||
"files.trimTrailingWhitespace": true
|
"files.trimTrailingWhitespace": true,
|
||||||
|
|
||||||
|
// Special file associations
|
||||||
|
"files.associations": {
|
||||||
|
".eslintrc": "jsonc"
|
||||||
|
},
|
||||||
|
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.fixAll": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-14
@@ -56,7 +56,7 @@ const captions = {
|
|||||||
if (browser.isIE && window.URL) {
|
if (browser.isIE && window.URL) {
|
||||||
const elements = this.media.querySelectorAll('track');
|
const elements = this.media.querySelectorAll('track');
|
||||||
|
|
||||||
Array.from(elements).forEach(track => {
|
Array.from(elements).forEach((track) => {
|
||||||
const src = track.getAttribute('src');
|
const src = track.getAttribute('src');
|
||||||
const url = parseUrl(src);
|
const url = parseUrl(src);
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ const captions = {
|
|||||||
['http:', 'https:'].includes(url.protocol)
|
['http:', 'https:'].includes(url.protocol)
|
||||||
) {
|
) {
|
||||||
fetch(src, 'blob')
|
fetch(src, 'blob')
|
||||||
.then(blob => {
|
.then((blob) => {
|
||||||
track.setAttribute('src', window.URL.createObjectURL(blob));
|
track.setAttribute('src', window.URL.createObjectURL(blob));
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
@@ -84,7 +84,7 @@ const captions = {
|
|||||||
// * toggled: The real captions state
|
// * toggled: The real captions state
|
||||||
|
|
||||||
const browserLanguages = navigator.languages || [navigator.language || navigator.userLanguage || 'en'];
|
const browserLanguages = navigator.languages || [navigator.language || navigator.userLanguage || 'en'];
|
||||||
const languages = dedupe(browserLanguages.map(language => language.split('-')[0]));
|
const languages = dedupe(browserLanguages.map((language) => language.split('-')[0]));
|
||||||
let language = (this.storage.get('language') || this.config.captions.language || 'auto').toLowerCase();
|
let language = (this.storage.get('language') || this.config.captions.language || 'auto').toLowerCase();
|
||||||
|
|
||||||
// Use first browser language when language is 'auto'
|
// Use first browser language when language is 'auto'
|
||||||
@@ -119,22 +119,28 @@ const captions = {
|
|||||||
const tracks = captions.getTracks.call(this, true);
|
const tracks = captions.getTracks.call(this, true);
|
||||||
// Get the wanted language
|
// Get the wanted language
|
||||||
const { active, language, meta, currentTrackNode } = this.captions;
|
const { active, language, meta, currentTrackNode } = this.captions;
|
||||||
const languageExists = Boolean(tracks.find(track => track.language === language));
|
const languageExists = Boolean(tracks.find((track) => track.language === language));
|
||||||
|
|
||||||
// Handle tracks (add event listener and "pseudo"-default)
|
// Handle tracks (add event listener and "pseudo"-default)
|
||||||
if (this.isHTML5 && this.isVideo) {
|
if (this.isHTML5 && this.isVideo) {
|
||||||
tracks
|
tracks
|
||||||
.filter(track => !meta.get(track))
|
.filter((track) => !meta.get(track))
|
||||||
.forEach(track => {
|
.forEach((track) => {
|
||||||
this.debug.log('Track added', track);
|
this.debug.log('Track added', track);
|
||||||
|
|
||||||
// Attempt to store if the original dom element was "default"
|
// Attempt to store if the original dom element was "default"
|
||||||
meta.set(track, {
|
meta.set(track, {
|
||||||
default: track.mode === 'showing',
|
default: track.mode === 'showing',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Turn off native caption rendering to avoid double captions
|
// Turn off native caption rendering to avoid double captions
|
||||||
|
// Note: mode='hidden' forces a track to download. To ensure every track
|
||||||
|
// isn't downloaded at once, only 'showing' tracks should be reassigned
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
if (track.mode === 'showing') {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
track.mode = 'hidden';
|
track.mode = 'hidden';
|
||||||
|
}
|
||||||
|
|
||||||
// Add event listener for cue changes
|
// Add event listener for cue changes
|
||||||
on.call(this, track, 'cuechange', () => captions.updateCues.call(this));
|
on.call(this, track, 'cuechange', () => captions.updateCues.call(this));
|
||||||
@@ -148,10 +154,16 @@ const captions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Enable or disable captions based on track length
|
// Enable or disable captions based on track length
|
||||||
|
if (this.elements) {
|
||||||
toggleClass(this.elements.container, this.config.classNames.captions.enabled, !is.empty(tracks));
|
toggleClass(this.elements.container, this.config.classNames.captions.enabled, !is.empty(tracks));
|
||||||
|
}
|
||||||
|
|
||||||
// Update available languages in list
|
// Update available languages in list
|
||||||
if ((this.config.controls || []).includes('settings') && this.config.settings.includes('captions')) {
|
if (
|
||||||
|
is.array(this.config.controls) &&
|
||||||
|
this.config.controls.includes('settings') &&
|
||||||
|
this.config.settings.includes('captions')
|
||||||
|
) {
|
||||||
controls.setCaptionsMenu.call(this);
|
controls.setCaptionsMenu.call(this);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -207,6 +219,14 @@ const captions = {
|
|||||||
// Trigger event (not used internally)
|
// Trigger event (not used internally)
|
||||||
triggerEvent.call(this, this.media, active ? 'captionsenabled' : 'captionsdisabled');
|
triggerEvent.call(this, this.media, active ? 'captionsenabled' : 'captionsdisabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for the call stack to clear before setting mode='hidden'
|
||||||
|
// on the active track - forcing the browser to download it
|
||||||
|
setTimeout(() => {
|
||||||
|
if (active && this.captions.toggled) {
|
||||||
|
this.captions.currentTrackNode.mode = 'hidden';
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set captions by track index
|
// Set captions by track index
|
||||||
@@ -291,19 +311,19 @@ const captions = {
|
|||||||
// For HTML5, use cache instead of current tracks when it exists (if captions.update is false)
|
// For HTML5, use cache instead of current tracks when it exists (if captions.update is false)
|
||||||
// Filter out removed tracks and tracks that aren't captions/subtitles (for example metadata)
|
// Filter out removed tracks and tracks that aren't captions/subtitles (for example metadata)
|
||||||
return tracks
|
return tracks
|
||||||
.filter(track => !this.isHTML5 || update || this.captions.meta.has(track))
|
.filter((track) => !this.isHTML5 || update || this.captions.meta.has(track))
|
||||||
.filter(track => ['captions', 'subtitles'].includes(track.kind));
|
.filter((track) => ['captions', 'subtitles'].includes(track.kind));
|
||||||
},
|
},
|
||||||
|
|
||||||
// Match tracks based on languages and get the first
|
// Match tracks based on languages and get the first
|
||||||
findTrack(languages, force = false) {
|
findTrack(languages, force = false) {
|
||||||
const tracks = captions.getTracks.call(this);
|
const tracks = captions.getTracks.call(this);
|
||||||
const sortIsDefault = track => Number((this.captions.meta.get(track) || {}).default);
|
const sortIsDefault = (track) => Number((this.captions.meta.get(track) || {}).default);
|
||||||
const sorted = Array.from(tracks).sort((a, b) => sortIsDefault(b) - sortIsDefault(a));
|
const sorted = Array.from(tracks).sort((a, b) => sortIsDefault(b) - sortIsDefault(a));
|
||||||
let track;
|
let track;
|
||||||
|
|
||||||
languages.every(language => {
|
languages.every((language) => {
|
||||||
track = sorted.find(t => t.language === language);
|
track = sorted.find((t) => t.language === language);
|
||||||
return !track; // Break iteration if there is a match
|
return !track; // Break iteration if there is a match
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -365,12 +385,12 @@ const captions = {
|
|||||||
const track = captions.getCurrentTrack.call(this);
|
const track = captions.getCurrentTrack.call(this);
|
||||||
|
|
||||||
cues = Array.from((track || {}).activeCues || [])
|
cues = Array.from((track || {}).activeCues || [])
|
||||||
.map(cue => cue.getCueAsHTML())
|
.map((cue) => cue.getCueAsHTML())
|
||||||
.map(getHTML);
|
.map(getHTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set new caption text
|
// Set new caption text
|
||||||
const content = cues.map(cueText => cueText.trim()).join('\n');
|
const content = cues.map((cueText) => cueText.trim()).join('\n');
|
||||||
const changed = content !== this.elements.captions.innerHTML;
|
const changed = content !== this.elements.captions.innerHTML;
|
||||||
|
|
||||||
if (changed) {
|
if (changed) {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ const defaults = {
|
|||||||
// Sprite (for icons)
|
// Sprite (for icons)
|
||||||
loadSprite: true,
|
loadSprite: true,
|
||||||
iconPrefix: 'plyr',
|
iconPrefix: 'plyr',
|
||||||
iconUrl: 'https://cdn.plyr.io/3.5.6/plyr.svg',
|
iconUrl: 'https://cdn.plyr.io/3.7.0/plyr.svg',
|
||||||
|
|
||||||
// Blank video (used to prevent errors on source change)
|
// Blank video (used to prevent errors on source change)
|
||||||
blankVideo: 'https://cdn.plyr.io/static/blank.mp4',
|
blankVideo: 'https://cdn.plyr.io/static/blank.mp4',
|
||||||
@@ -69,7 +69,10 @@ const defaults = {
|
|||||||
// Quality default
|
// Quality default
|
||||||
quality: {
|
quality: {
|
||||||
default: 576,
|
default: 576,
|
||||||
|
// The options to display in the UI, if available for the source media
|
||||||
options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240],
|
options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240],
|
||||||
|
forced: false,
|
||||||
|
onChange: null,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set loops
|
// Set loops
|
||||||
@@ -82,7 +85,8 @@ const defaults = {
|
|||||||
// Speed default and options to display
|
// Speed default and options to display
|
||||||
speed: {
|
speed: {
|
||||||
selected: 1,
|
selected: 1,
|
||||||
options: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2],
|
// The options to display in the UI, if available for the source media (e.g. Vimeo and YouTube only support 0.5x-4x)
|
||||||
|
options: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 4],
|
||||||
},
|
},
|
||||||
|
|
||||||
// Keyboard shortcut settings
|
// Keyboard shortcut settings
|
||||||
@@ -111,6 +115,9 @@ const defaults = {
|
|||||||
enabled: true, // Allow fullscreen?
|
enabled: true, // Allow fullscreen?
|
||||||
fallback: true, // Fallback using full viewport/window
|
fallback: true, // Fallback using full viewport/window
|
||||||
iosNative: false, // Use the native fullscreen in iOS (disables custom controls)
|
iosNative: false, // Use the native fullscreen in iOS (disables custom controls)
|
||||||
|
// Selector for the fullscreen container so contextual / non-player content can remain visible in fullscreen mode
|
||||||
|
// Non-ancestors of the player element will be ignored
|
||||||
|
// container: null, // defaults to the player element
|
||||||
},
|
},
|
||||||
|
|
||||||
// Local storage
|
// Local storage
|
||||||
@@ -164,6 +171,7 @@ const defaults = {
|
|||||||
frameTitle: 'Player for {title}',
|
frameTitle: 'Player for {title}',
|
||||||
captions: 'Captions',
|
captions: 'Captions',
|
||||||
settings: 'Settings',
|
settings: 'Settings',
|
||||||
|
pip: 'PIP',
|
||||||
menuBack: 'Go back to previous menu',
|
menuBack: 'Go back to previous menu',
|
||||||
speed: 'Speed',
|
speed: 'Speed',
|
||||||
normal: 'Normal',
|
normal: 'Normal',
|
||||||
@@ -192,7 +200,7 @@ const defaults = {
|
|||||||
vimeo: {
|
vimeo: {
|
||||||
sdk: 'https://player.vimeo.com/api/player.js',
|
sdk: 'https://player.vimeo.com/api/player.js',
|
||||||
iframe: 'https://player.vimeo.com/video/{0}?{1}',
|
iframe: 'https://player.vimeo.com/video/{0}?{1}',
|
||||||
api: 'https://vimeo.com/api/v2/video/{0}.json',
|
api: 'https://vimeo.com/api/oembed.json?url={0}',
|
||||||
},
|
},
|
||||||
youtube: {
|
youtube: {
|
||||||
sdk: 'https://www.youtube.com/iframe_api',
|
sdk: 'https://www.youtube.com/iframe_api',
|
||||||
@@ -342,6 +350,7 @@ const defaults = {
|
|||||||
hover: 'plyr--hover',
|
hover: 'plyr--hover',
|
||||||
tooltip: 'plyr__tooltip',
|
tooltip: 'plyr__tooltip',
|
||||||
cues: 'plyr__cues',
|
cues: 'plyr__cues',
|
||||||
|
marker: 'plyr__progress__marker',
|
||||||
hidden: 'plyr__sr-only',
|
hidden: 'plyr__sr-only',
|
||||||
hideControls: 'plyr--hide-controls',
|
hideControls: 'plyr--hide-controls',
|
||||||
isIos: 'plyr--is-ios',
|
isIos: 'plyr--is-ios',
|
||||||
@@ -390,6 +399,7 @@ const defaults = {
|
|||||||
embed: {
|
embed: {
|
||||||
provider: 'data-plyr-provider',
|
provider: 'data-plyr-provider',
|
||||||
id: 'data-plyr-embed-id',
|
id: 'data-plyr-embed-id',
|
||||||
|
hash: 'data-plyr-embed-hash',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -414,15 +424,37 @@ const defaults = {
|
|||||||
title: false,
|
title: false,
|
||||||
speed: true,
|
speed: true,
|
||||||
transparent: false,
|
transparent: false,
|
||||||
|
// Custom settings from Plyr
|
||||||
|
customControls: true,
|
||||||
|
referrerPolicy: null, // https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/referrerPolicy
|
||||||
|
// Whether the owner of the video has a Pro or Business account
|
||||||
|
// (which allows us to properly hide controls without CSS hacks, etc)
|
||||||
|
premium: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
// YouTube plugin
|
// YouTube plugin
|
||||||
youtube: {
|
youtube: {
|
||||||
noCookie: false, // Whether to use an alternative version of YouTube without cookies
|
|
||||||
rel: 0, // No related vids
|
rel: 0, // No related vids
|
||||||
showinfo: 0, // Hide info
|
showinfo: 0, // Hide info
|
||||||
iv_load_policy: 3, // Hide annotations
|
iv_load_policy: 3, // Hide annotations
|
||||||
modestbranding: 1, // Hide logos as much as possible (they still show one in the corner when paused)
|
modestbranding: 1, // Hide logos as much as possible (they still show one in the corner when paused)
|
||||||
|
// Custom settings from Plyr
|
||||||
|
customControls: true,
|
||||||
|
noCookie: false, // Whether to use an alternative version of YouTube without cookies
|
||||||
|
},
|
||||||
|
|
||||||
|
// Media Metadata
|
||||||
|
mediaMetadata: {
|
||||||
|
title: '',
|
||||||
|
artist: '',
|
||||||
|
album: '',
|
||||||
|
artwork: [],
|
||||||
|
},
|
||||||
|
|
||||||
|
// Markers
|
||||||
|
markers: {
|
||||||
|
enabled: false,
|
||||||
|
points: [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Vendored
+155
-58
@@ -38,7 +38,8 @@ const controls = {
|
|||||||
// Get icon URL
|
// Get icon URL
|
||||||
getIconUrl() {
|
getIconUrl() {
|
||||||
const url = new URL(this.config.iconUrl, window.location);
|
const url = new URL(this.config.iconUrl, window.location);
|
||||||
const cors = url.host !== window.location.host || (browser.isIE && !window.svg4everybody);
|
const host = window.location.host ? window.location.host : window.top.location.host;
|
||||||
|
const cors = url.host !== host || (browser.isIE && !window.svg4everybody);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: this.config.iconUrl,
|
url: this.config.iconUrl,
|
||||||
@@ -84,9 +85,7 @@ const controls = {
|
|||||||
|
|
||||||
// Seek tooltip
|
// Seek tooltip
|
||||||
if (is.element(this.elements.progress)) {
|
if (is.element(this.elements.progress)) {
|
||||||
this.elements.display.seekTooltip = this.elements.progress.querySelector(
|
this.elements.display.seekTooltip = this.elements.progress.querySelector(`.${this.config.classNames.tooltip}`);
|
||||||
`.${this.config.classNames.tooltip}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -111,7 +110,7 @@ const controls = {
|
|||||||
setAttributes(
|
setAttributes(
|
||||||
icon,
|
icon,
|
||||||
extend(attributes, {
|
extend(attributes, {
|
||||||
role: 'presentation',
|
'aria-hidden': 'true',
|
||||||
focusable: 'false',
|
focusable: 'false',
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -139,10 +138,7 @@ const controls = {
|
|||||||
// Create hidden text label
|
// Create hidden text label
|
||||||
createLabel(key, attr = {}) {
|
createLabel(key, attr = {}) {
|
||||||
const text = i18n.get(key, this.config);
|
const text = i18n.get(key, this.config);
|
||||||
|
const attributes = { ...attr, class: [attr.class, this.config.classNames.hidden].filter(Boolean).join(' ') };
|
||||||
const attributes = Object.assign({}, attr, {
|
|
||||||
class: [attr.class, this.config.classNames.hidden].filter(Boolean).join(' '),
|
|
||||||
});
|
|
||||||
|
|
||||||
return createElement('span', attributes, text);
|
return createElement('span', attributes, text);
|
||||||
},
|
},
|
||||||
@@ -184,7 +180,7 @@ const controls = {
|
|||||||
iconPressed: null,
|
iconPressed: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
['element', 'icon', 'label'].forEach(key => {
|
['element', 'icon', 'label'].forEach((key) => {
|
||||||
if (Object.keys(attributes).includes(key)) {
|
if (Object.keys(attributes).includes(key)) {
|
||||||
props[key] = attributes[key];
|
props[key] = attributes[key];
|
||||||
delete attributes[key];
|
delete attributes[key];
|
||||||
@@ -198,7 +194,7 @@ const controls = {
|
|||||||
|
|
||||||
// Set class name
|
// Set class name
|
||||||
if (Object.keys(attributes).includes('class')) {
|
if (Object.keys(attributes).includes('class')) {
|
||||||
if (!attributes.class.split(' ').some(c => c === this.config.classNames.control)) {
|
if (!attributes.class.split(' ').some((c) => c === this.config.classNames.control)) {
|
||||||
extend(attributes, {
|
extend(attributes, {
|
||||||
class: `${attributes.class} ${this.config.classNames.control}`,
|
class: `${attributes.class} ${this.config.classNames.control}`,
|
||||||
});
|
});
|
||||||
@@ -402,10 +398,11 @@ const controls = {
|
|||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1220143
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1220143
|
||||||
bindMenuItemShortcuts(menuItem, type) {
|
bindMenuItemShortcuts(menuItem, type) {
|
||||||
// Navigate through menus via arrow keys and space
|
// Navigate through menus via arrow keys and space
|
||||||
on(
|
on.call(
|
||||||
|
this,
|
||||||
menuItem,
|
menuItem,
|
||||||
'keydown keyup',
|
'keydown keyup',
|
||||||
event => {
|
(event) => {
|
||||||
// We only care about space and ⬆️ ⬇️️ ➡️
|
// We only care about space and ⬆️ ⬇️️ ➡️
|
||||||
if (![32, 38, 39, 40].includes(event.which)) {
|
if (![32, 38, 39, 40].includes(event.which)) {
|
||||||
return;
|
return;
|
||||||
@@ -452,7 +449,7 @@ const controls = {
|
|||||||
|
|
||||||
// Enter will fire a `click` event but we still need to manage focus
|
// Enter will fire a `click` event but we still need to manage focus
|
||||||
// So we bind to keyup which fires after and set focus here
|
// So we bind to keyup which fires after and set focus here
|
||||||
on(menuItem, 'keyup', event => {
|
on.call(this, menuItem, 'keyup', (event) => {
|
||||||
if (event.which !== 13) {
|
if (event.which !== 13) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -487,7 +484,7 @@ const controls = {
|
|||||||
|
|
||||||
menuItem.appendChild(flex);
|
menuItem.appendChild(flex);
|
||||||
|
|
||||||
// Replicate radio button behaviour
|
// Replicate radio button behavior
|
||||||
Object.defineProperty(menuItem, 'checked', {
|
Object.defineProperty(menuItem, 'checked', {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
get() {
|
get() {
|
||||||
@@ -497,8 +494,8 @@ const controls = {
|
|||||||
// Ensure exclusivity
|
// Ensure exclusivity
|
||||||
if (check) {
|
if (check) {
|
||||||
Array.from(menuItem.parentNode.children)
|
Array.from(menuItem.parentNode.children)
|
||||||
.filter(node => matches(node, '[role="menuitemradio"]'))
|
.filter((node) => matches(node, '[role="menuitemradio"]'))
|
||||||
.forEach(node => node.setAttribute('aria-checked', 'false'));
|
.forEach((node) => node.setAttribute('aria-checked', 'false'));
|
||||||
}
|
}
|
||||||
|
|
||||||
menuItem.setAttribute('aria-checked', check ? 'true' : 'false');
|
menuItem.setAttribute('aria-checked', check ? 'true' : 'false');
|
||||||
@@ -508,7 +505,7 @@ const controls = {
|
|||||||
this.listeners.bind(
|
this.listeners.bind(
|
||||||
menuItem,
|
menuItem,
|
||||||
'click keyup',
|
'click keyup',
|
||||||
event => {
|
(event) => {
|
||||||
if (is.keyboardEvent(event) && event.which !== 32) {
|
if (is.keyboardEvent(event) && event.which !== 32) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -701,8 +698,9 @@ const controls = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tipElement = this.elements.display.seekTooltip;
|
||||||
const visible = `${this.config.classNames.tooltip}--visible`;
|
const visible = `${this.config.classNames.tooltip}--visible`;
|
||||||
const toggle = show => toggleClass(this.elements.display.seekTooltip, visible, show);
|
const toggle = (show) => toggleClass(tipElement, visible, show);
|
||||||
|
|
||||||
// Hide on touch
|
// Hide on touch
|
||||||
if (this.touch) {
|
if (this.touch) {
|
||||||
@@ -716,8 +714,8 @@ const controls = {
|
|||||||
|
|
||||||
if (is.event(event)) {
|
if (is.event(event)) {
|
||||||
percent = (100 / clientRect.width) * (event.pageX - clientRect.left);
|
percent = (100 / clientRect.width) * (event.pageX - clientRect.left);
|
||||||
} else if (hasClass(this.elements.display.seekTooltip, visible)) {
|
} else if (hasClass(tipElement, visible)) {
|
||||||
percent = parseFloat(this.elements.display.seekTooltip.style.left, 10);
|
percent = parseFloat(tipElement.style.left, 10);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -729,11 +727,21 @@ const controls = {
|
|||||||
percent = 100;
|
percent = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const time = (this.duration / 100) * percent;
|
||||||
|
|
||||||
// Display the time a click would seek to
|
// Display the time a click would seek to
|
||||||
controls.updateTimeDisplay.call(this, this.elements.display.seekTooltip, (this.duration / 100) * percent);
|
tipElement.innerText = controls.formatTime(time);
|
||||||
|
|
||||||
|
// Get marker point for time
|
||||||
|
const point = this.config.markers?.points?.find(({ time: t }) => t === Math.round(time));
|
||||||
|
|
||||||
|
// Append the point label to the tooltip
|
||||||
|
if (point) {
|
||||||
|
tipElement.insertAdjacentHTML('afterbegin', `${point.label}<br>`);
|
||||||
|
}
|
||||||
|
|
||||||
// Set position
|
// Set position
|
||||||
this.elements.display.seekTooltip.style.left = `${percent}%`;
|
tipElement.style.left = `${percent}%`;
|
||||||
|
|
||||||
// Show/hide the tooltip
|
// Show/hide the tooltip
|
||||||
// If the event is a moues in/out and percentage is inside bounds
|
// If the event is a moues in/out and percentage is inside bounds
|
||||||
@@ -799,6 +807,10 @@ const controls = {
|
|||||||
controls.updateTimeDisplay.call(this, this.elements.display.duration, this.duration);
|
controls.updateTimeDisplay.call(this, this.elements.display.duration, this.duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.config.markers.enabled) {
|
||||||
|
controls.setMarkers.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
// Update the tooltip (if visible)
|
// Update the tooltip (if visible)
|
||||||
controls.updateSeekTooltip.call(this);
|
controls.updateSeekTooltip.call(this);
|
||||||
},
|
},
|
||||||
@@ -898,7 +910,7 @@ const controls = {
|
|||||||
|
|
||||||
// Set options if passed and filter based on uniqueness and config
|
// Set options if passed and filter based on uniqueness and config
|
||||||
if (is.array(options)) {
|
if (is.array(options)) {
|
||||||
this.options.quality = dedupe(options).filter(quality => this.config.quality.options.includes(quality));
|
this.options.quality = dedupe(options).filter((quality) => this.config.quality.options.includes(quality));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle the pane and tab
|
// Toggle the pane and tab
|
||||||
@@ -917,7 +929,7 @@ const controls = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the badge HTML for HD, 4K etc
|
// Get the badge HTML for HD, 4K etc
|
||||||
const getBadge = quality => {
|
const getBadge = (quality) => {
|
||||||
const label = i18n.get(`qualityBadge.${quality}`, this.config);
|
const label = i18n.get(`qualityBadge.${quality}`, this.config);
|
||||||
|
|
||||||
if (!label.length) {
|
if (!label.length) {
|
||||||
@@ -933,7 +945,7 @@ const controls = {
|
|||||||
const sorting = this.config.quality.options;
|
const sorting = this.config.quality.options;
|
||||||
return sorting.indexOf(a) > sorting.indexOf(b) ? 1 : -1;
|
return sorting.indexOf(a) > sorting.indexOf(b) ? 1 : -1;
|
||||||
})
|
})
|
||||||
.forEach(quality => {
|
.forEach((quality) => {
|
||||||
controls.createMenuItem.call(this, {
|
controls.createMenuItem.call(this, {
|
||||||
value: quality,
|
value: quality,
|
||||||
list,
|
list,
|
||||||
@@ -1046,7 +1058,7 @@ const controls = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Set a list of available captions languages
|
// Set a list of available captions languages
|
||||||
setSpeedMenu(options) {
|
setSpeedMenu() {
|
||||||
// Menu required
|
// Menu required
|
||||||
if (!is.element(this.elements.settings.panels.speed)) {
|
if (!is.element(this.elements.settings.panels.speed)) {
|
||||||
return;
|
return;
|
||||||
@@ -1055,15 +1067,8 @@ const controls = {
|
|||||||
const type = 'speed';
|
const type = 'speed';
|
||||||
const list = this.elements.settings.panels.speed.querySelector('[role="menu"]');
|
const list = this.elements.settings.panels.speed.querySelector('[role="menu"]');
|
||||||
|
|
||||||
// Set the speed options
|
// Filter out invalid speeds
|
||||||
if (is.array(options)) {
|
this.options.speed = this.options.speed.filter((o) => o >= this.minimumSpeed && o <= this.maximumSpeed);
|
||||||
this.options.speed = options;
|
|
||||||
} else if (this.isHTML5 || this.isVimeo) {
|
|
||||||
this.options.speed = [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set options if passed and filter based on config
|
|
||||||
this.options.speed = this.options.speed.filter(speed => this.config.speed.options.includes(speed));
|
|
||||||
|
|
||||||
// Toggle the pane and tab
|
// Toggle the pane and tab
|
||||||
const toggle = !is.empty(this.options.speed) && this.options.speed.length > 1;
|
const toggle = !is.empty(this.options.speed) && this.options.speed.length > 1;
|
||||||
@@ -1081,7 +1086,7 @@ const controls = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create items
|
// Create items
|
||||||
this.options.speed.forEach(speed => {
|
this.options.speed.forEach((speed) => {
|
||||||
controls.createMenuItem.call(this, {
|
controls.createMenuItem.call(this, {
|
||||||
value: speed,
|
value: speed,
|
||||||
list,
|
list,
|
||||||
@@ -1096,7 +1101,7 @@ const controls = {
|
|||||||
// Check if we need to hide/show the settings menu
|
// Check if we need to hide/show the settings menu
|
||||||
checkMenu() {
|
checkMenu() {
|
||||||
const { buttons } = this.elements.settings;
|
const { buttons } = this.elements.settings;
|
||||||
const visible = !is.empty(buttons) && Object.values(buttons).some(button => !button.hidden);
|
const visible = !is.empty(buttons) && Object.values(buttons).some((button) => !button.hidden);
|
||||||
|
|
||||||
toggleHidden(this.elements.settings.menu, !visible);
|
toggleHidden(this.elements.settings.menu, !visible);
|
||||||
},
|
},
|
||||||
@@ -1110,7 +1115,7 @@ const controls = {
|
|||||||
let target = pane;
|
let target = pane;
|
||||||
|
|
||||||
if (!is.element(target)) {
|
if (!is.element(target)) {
|
||||||
target = Object.values(this.elements.settings.panels).find(p => !p.hidden);
|
target = Object.values(this.elements.settings.panels).find((p) => !p.hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
const firstItem = target.querySelector('[role^="menuitem"]');
|
const firstItem = target.querySelector('[role^="menuitem"]');
|
||||||
@@ -1202,7 +1207,7 @@ const controls = {
|
|||||||
|
|
||||||
// Hide all other panels
|
// Hide all other panels
|
||||||
const container = target.parentNode;
|
const container = target.parentNode;
|
||||||
const current = Array.from(container.children).find(node => !node.hidden);
|
const current = Array.from(container.children).find((node) => !node.hidden);
|
||||||
|
|
||||||
// If we can do fancy animations, we'll animate the height/width
|
// If we can do fancy animations, we'll animate the height/width
|
||||||
if (support.transitions && !support.reducedMotion) {
|
if (support.transitions && !support.reducedMotion) {
|
||||||
@@ -1214,7 +1219,7 @@ const controls = {
|
|||||||
const size = controls.getMenuSize.call(this, target);
|
const size = controls.getMenuSize.call(this, target);
|
||||||
|
|
||||||
// Restore auto height/width
|
// Restore auto height/width
|
||||||
const restore = event => {
|
const restore = (event) => {
|
||||||
// We're only bothered about height and width on the container
|
// We're only bothered about height and width on the container
|
||||||
if (event.target !== container || !['width', 'height'].includes(event.propertyName)) {
|
if (event.target !== container || !['width', 'height'].includes(event.propertyName)) {
|
||||||
return;
|
return;
|
||||||
@@ -1274,7 +1279,7 @@ const controls = {
|
|||||||
this.elements.controls = null;
|
this.elements.controls = null;
|
||||||
|
|
||||||
// Larger overlaid play button
|
// Larger overlaid play button
|
||||||
if (this.config.controls.includes('play-large')) {
|
if (is.array(this.config.controls) && this.config.controls.includes('play-large')) {
|
||||||
this.elements.container.appendChild(createButton.call(this, 'play-large'));
|
this.elements.container.appendChild(createButton.call(this, 'play-large'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1286,7 +1291,7 @@ const controls = {
|
|||||||
const defaultAttributes = { class: 'plyr__controls__item' };
|
const defaultAttributes = { class: 'plyr__controls__item' };
|
||||||
|
|
||||||
// Loop through controls in order
|
// Loop through controls in order
|
||||||
dedupe(this.config.controls).forEach(control => {
|
dedupe(is.array(this.config.controls) ? this.config.controls : []).forEach((control) => {
|
||||||
// Restart button
|
// Restart button
|
||||||
if (control === 'restart') {
|
if (control === 'restart') {
|
||||||
container.appendChild(createButton.call(this, 'restart', defaultAttributes));
|
container.appendChild(createButton.call(this, 'restart', defaultAttributes));
|
||||||
@@ -1380,7 +1385,9 @@ const controls = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Volume range control
|
// Volume range control
|
||||||
if (control === 'volume') {
|
// Ignored on iOS as it's handled globally
|
||||||
|
// https://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html
|
||||||
|
if (control === 'volume' && !browser.isIos) {
|
||||||
// Set the attributes
|
// Set the attributes
|
||||||
const attributes = {
|
const attributes = {
|
||||||
max: 1,
|
max: 1,
|
||||||
@@ -1446,7 +1453,7 @@ const controls = {
|
|||||||
this.elements.settings.panels.home = home;
|
this.elements.settings.panels.home = home;
|
||||||
|
|
||||||
// Build the menu items
|
// Build the menu items
|
||||||
this.config.settings.forEach(type => {
|
this.config.settings.forEach((type) => {
|
||||||
// TODO: bundle this with the createMenuItem helper and bindings
|
// TODO: bundle this with the createMenuItem helper and bindings
|
||||||
const menuItem = createElement(
|
const menuItem = createElement(
|
||||||
'button',
|
'button',
|
||||||
@@ -1463,7 +1470,7 @@ const controls = {
|
|||||||
bindMenuItemShortcuts.call(this, menuItem, type);
|
bindMenuItemShortcuts.call(this, menuItem, type);
|
||||||
|
|
||||||
// Show menu on click
|
// Show menu on click
|
||||||
on(menuItem, 'click', () => {
|
on.call(this, menuItem, 'click', () => {
|
||||||
showMenuPanel.call(this, type, false);
|
showMenuPanel.call(this, type, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1515,10 +1522,11 @@ const controls = {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Go back via keyboard
|
// Go back via keyboard
|
||||||
on(
|
on.call(
|
||||||
|
this,
|
||||||
pane,
|
pane,
|
||||||
'keydown',
|
'keydown',
|
||||||
event => {
|
(event) => {
|
||||||
// We only care about <-
|
// We only care about <-
|
||||||
if (event.which !== 37) {
|
if (event.which !== 37) {
|
||||||
return;
|
return;
|
||||||
@@ -1535,7 +1543,7 @@ const controls = {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Go back via button click
|
// Go back via button click
|
||||||
on(backButton, 'click', () => {
|
on.call(this, backButton, 'click', () => {
|
||||||
showMenuPanel.call(this, 'home', false);
|
showMenuPanel.call(this, 'home', false);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1581,6 +1589,11 @@ const controls = {
|
|||||||
target: '_blank',
|
target: '_blank',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Set download attribute for HTML5 only
|
||||||
|
if (this.isHTML5) {
|
||||||
|
attributes.download = '';
|
||||||
|
}
|
||||||
|
|
||||||
const { download } = this.config.urls;
|
const { download } = this.config.urls;
|
||||||
|
|
||||||
if (!is.url(download) && this.isEmbed) {
|
if (!is.url(download) && this.isEmbed) {
|
||||||
@@ -1664,7 +1677,7 @@ const controls = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Replace props with their value
|
// Replace props with their value
|
||||||
const replace = input => {
|
const replace = (input) => {
|
||||||
let result = input;
|
let result = input;
|
||||||
|
|
||||||
Object.entries(props).forEach(([key, value]) => {
|
Object.entries(props).forEach(([key, value]) => {
|
||||||
@@ -1678,8 +1691,6 @@ const controls = {
|
|||||||
if (update) {
|
if (update) {
|
||||||
if (is.string(this.config.controls)) {
|
if (is.string(this.config.controls)) {
|
||||||
container = replace(container);
|
container = replace(container);
|
||||||
} else if (is.element(container)) {
|
|
||||||
container.innerHTML = replace(container.innerHTML);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1707,7 +1718,7 @@ const controls = {
|
|||||||
|
|
||||||
// Add pressed property to buttons
|
// Add pressed property to buttons
|
||||||
if (!is.empty(this.elements.buttons)) {
|
if (!is.empty(this.elements.buttons)) {
|
||||||
const addProperty = button => {
|
const addProperty = (button) => {
|
||||||
const className = this.config.classNames.controlPressed;
|
const className = this.config.classNames.controlPressed;
|
||||||
Object.defineProperty(button, 'pressed', {
|
Object.defineProperty(button, 'pressed', {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
@@ -1723,11 +1734,9 @@ const controls = {
|
|||||||
// Toggle classname when pressed property is set
|
// Toggle classname when pressed property is set
|
||||||
Object.values(this.elements.buttons)
|
Object.values(this.elements.buttons)
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.forEach(button => {
|
.forEach((button) => {
|
||||||
if (is.array(button) || is.nodeList(button)) {
|
if (is.array(button) || is.nodeList(button)) {
|
||||||
Array.from(button)
|
Array.from(button).filter(Boolean).forEach(addProperty);
|
||||||
.filter(Boolean)
|
|
||||||
.forEach(addProperty);
|
|
||||||
} else {
|
} else {
|
||||||
addProperty(button);
|
addProperty(button);
|
||||||
}
|
}
|
||||||
@@ -1745,12 +1754,100 @@ const controls = {
|
|||||||
const selector = `${selectors.controls.wrapper} ${selectors.labels} .${classNames.hidden}`;
|
const selector = `${selectors.controls.wrapper} ${selectors.labels} .${classNames.hidden}`;
|
||||||
const labels = getElements.call(this, selector);
|
const labels = getElements.call(this, selector);
|
||||||
|
|
||||||
Array.from(labels).forEach(label => {
|
Array.from(labels).forEach((label) => {
|
||||||
toggleClass(label, this.config.classNames.hidden, false);
|
toggleClass(label, this.config.classNames.hidden, false);
|
||||||
toggleClass(label, this.config.classNames.tooltip, true);
|
toggleClass(label, this.config.classNames.tooltip, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Set media metadata
|
||||||
|
setMediaMetadata() {
|
||||||
|
try {
|
||||||
|
if ('mediaSession' in navigator) {
|
||||||
|
navigator.mediaSession.metadata = new window.MediaMetadata({
|
||||||
|
title: this.config.mediaMetadata.title,
|
||||||
|
artist: this.config.mediaMetadata.artist,
|
||||||
|
album: this.config.mediaMetadata.album,
|
||||||
|
artwork: this.config.mediaMetadata.artwork,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Add markers
|
||||||
|
setMarkers() {
|
||||||
|
if (!this.duration || this.elements.markers) return;
|
||||||
|
|
||||||
|
// Get valid points
|
||||||
|
const points = this.config.markers?.points?.filter(({ time }) => time > 0 && time < this.duration);
|
||||||
|
if (!points?.length) return;
|
||||||
|
|
||||||
|
const containerFragment = document.createDocumentFragment();
|
||||||
|
const pointsFragment = document.createDocumentFragment();
|
||||||
|
let tipElement = null;
|
||||||
|
const tipVisible = `${this.config.classNames.tooltip}--visible`;
|
||||||
|
const toggleTip = (show) => toggleClass(tipElement, tipVisible, show);
|
||||||
|
|
||||||
|
// Inject markers to progress container
|
||||||
|
points.forEach((point) => {
|
||||||
|
const markerElement = createElement(
|
||||||
|
'span',
|
||||||
|
{
|
||||||
|
class: this.config.classNames.marker,
|
||||||
|
},
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
|
||||||
|
const left = `${(point.time / this.duration) * 100}%`;
|
||||||
|
|
||||||
|
if (tipElement) {
|
||||||
|
// Show on hover
|
||||||
|
markerElement.addEventListener('mouseenter', () => {
|
||||||
|
if (point.label) return;
|
||||||
|
tipElement.style.left = left;
|
||||||
|
tipElement.innerHTML = point.label;
|
||||||
|
toggleTip(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Hide on leave
|
||||||
|
markerElement.addEventListener('mouseleave', () => {
|
||||||
|
toggleTip(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
markerElement.addEventListener('click', () => {
|
||||||
|
this.currentTime = point.time;
|
||||||
|
});
|
||||||
|
|
||||||
|
markerElement.style.left = left;
|
||||||
|
pointsFragment.appendChild(markerElement);
|
||||||
|
});
|
||||||
|
|
||||||
|
containerFragment.appendChild(pointsFragment);
|
||||||
|
|
||||||
|
// Inject a tooltip if needed
|
||||||
|
if (!this.config.tooltips.seek) {
|
||||||
|
tipElement = createElement(
|
||||||
|
'span',
|
||||||
|
{
|
||||||
|
class: this.config.classNames.tooltip,
|
||||||
|
},
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
|
||||||
|
containerFragment.appendChild(tipElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.elements.markers = {
|
||||||
|
points: pointsFragment,
|
||||||
|
tip: tipElement,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.elements.progress.appendChild(containerFragment);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default controls;
|
export default controls;
|
||||||
|
|||||||
+173
-135
@@ -5,11 +5,140 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import browser from './utils/browser';
|
import browser from './utils/browser';
|
||||||
import { hasClass, toggleClass, trapFocus } from './utils/elements';
|
import { closest, getElements, hasClass, toggleClass } from './utils/elements';
|
||||||
import { on, triggerEvent } from './utils/events';
|
import { on, triggerEvent } from './utils/events';
|
||||||
import is from './utils/is';
|
import is from './utils/is';
|
||||||
|
import { silencePromise } from './utils/promise';
|
||||||
|
|
||||||
function onChange() {
|
class Fullscreen {
|
||||||
|
constructor(player) {
|
||||||
|
// Keep reference to parent
|
||||||
|
this.player = player;
|
||||||
|
|
||||||
|
// Get prefix
|
||||||
|
this.prefix = Fullscreen.prefix;
|
||||||
|
this.property = Fullscreen.property;
|
||||||
|
|
||||||
|
// Scroll position
|
||||||
|
this.scrollPosition = { x: 0, y: 0 };
|
||||||
|
|
||||||
|
// Force the use of 'full window/browser' rather than fullscreen
|
||||||
|
this.forceFallback = player.config.fullscreen.fallback === 'force';
|
||||||
|
|
||||||
|
// Get the fullscreen element
|
||||||
|
// Checks container is an ancestor, defaults to null
|
||||||
|
this.player.elements.fullscreen =
|
||||||
|
player.config.fullscreen.container && closest(this.player.elements.container, player.config.fullscreen.container);
|
||||||
|
|
||||||
|
// Register event listeners
|
||||||
|
// Handle event (incase user presses escape etc)
|
||||||
|
on.call(
|
||||||
|
this.player,
|
||||||
|
document,
|
||||||
|
this.prefix === 'ms' ? 'MSFullscreenChange' : `${this.prefix}fullscreenchange`,
|
||||||
|
() => {
|
||||||
|
// TODO: Filter for target??
|
||||||
|
this.onChange();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Fullscreen toggle on double click
|
||||||
|
on.call(this.player, this.player.elements.container, 'dblclick', (event) => {
|
||||||
|
// Ignore double click in controls
|
||||||
|
if (is.element(this.player.elements.controls) && this.player.elements.controls.contains(event.target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.player.listeners.proxy(event, this.toggle, 'fullscreen');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Tap focus when in fullscreen
|
||||||
|
on.call(this, this.player.elements.container, 'keydown', (event) => this.trapFocus(event));
|
||||||
|
|
||||||
|
// Update the UI
|
||||||
|
this.update();
|
||||||
|
|
||||||
|
// this.toggle = this.toggle.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if native supported
|
||||||
|
static get native() {
|
||||||
|
return !!(
|
||||||
|
document.fullscreenEnabled ||
|
||||||
|
document.webkitFullscreenEnabled ||
|
||||||
|
document.mozFullScreenEnabled ||
|
||||||
|
document.msFullscreenEnabled
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're actually using native
|
||||||
|
get usingNative() {
|
||||||
|
return Fullscreen.native && !this.forceFallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the prefix for handlers
|
||||||
|
static get prefix() {
|
||||||
|
// No prefix
|
||||||
|
if (is.function(document.exitFullscreen)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for fullscreen support by vendor prefix
|
||||||
|
let value = '';
|
||||||
|
const prefixes = ['webkit', 'moz', 'ms'];
|
||||||
|
|
||||||
|
prefixes.some((pre) => {
|
||||||
|
if (is.function(document[`${pre}ExitFullscreen`]) || is.function(document[`${pre}CancelFullScreen`])) {
|
||||||
|
value = pre;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get property() {
|
||||||
|
return this.prefix === 'moz' ? 'FullScreen' : 'Fullscreen';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if fullscreen is enabled
|
||||||
|
get enabled() {
|
||||||
|
return (
|
||||||
|
(Fullscreen.native || this.player.config.fullscreen.fallback) &&
|
||||||
|
this.player.config.fullscreen.enabled &&
|
||||||
|
this.player.supported.ui &&
|
||||||
|
this.player.isVideo
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get active state
|
||||||
|
get active() {
|
||||||
|
if (!this.enabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback using classname
|
||||||
|
if (!Fullscreen.native || this.forceFallback) {
|
||||||
|
return hasClass(this.target, this.player.config.classNames.fullscreen.fallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
const element = !this.prefix
|
||||||
|
? this.target.getRootNode().fullscreenElement
|
||||||
|
: this.target.getRootNode()[`${this.prefix}${this.property}Element`];
|
||||||
|
|
||||||
|
return element && element.shadowRoot ? element === this.target.getRootNode().host : element === this.target;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get target element
|
||||||
|
get target() {
|
||||||
|
return browser.isIos && this.player.config.fullscreen.iosNative
|
||||||
|
? this.player.media
|
||||||
|
: this.player.elements.fullscreen || this.player.elements.container;
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange = () => {
|
||||||
if (!this.enabled) {
|
if (!this.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -20,16 +149,13 @@ function onChange() {
|
|||||||
button.pressed = this.active;
|
button.pressed = this.active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always trigger events on the plyr / media element (not a fullscreen container) and let them bubble up
|
||||||
|
const target = this.target === this.player.media ? this.target : this.player.elements.container;
|
||||||
// Trigger an event
|
// Trigger an event
|
||||||
triggerEvent.call(this.player, this.target, this.active ? 'enterfullscreen' : 'exitfullscreen', true);
|
triggerEvent.call(this.player, target, this.active ? 'enterfullscreen' : 'exitfullscreen', true);
|
||||||
|
};
|
||||||
|
|
||||||
// Trap focus in container
|
toggleFallback = (toggle = false) => {
|
||||||
if (!browser.isIos) {
|
|
||||||
trapFocus.call(this.player, this.target, this.active);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleFallback(toggle = false) {
|
|
||||||
// Store or restore scroll position
|
// Store or restore scroll position
|
||||||
if (toggle) {
|
if (toggle) {
|
||||||
this.scrollPosition = {
|
this.scrollPosition = {
|
||||||
@@ -69,133 +195,41 @@ function toggleFallback(toggle = false) {
|
|||||||
} else if (this.cleanupViewport) {
|
} else if (this.cleanupViewport) {
|
||||||
viewport.content = viewport.content
|
viewport.content = viewport.content
|
||||||
.split(',')
|
.split(',')
|
||||||
.filter(part => part.trim() !== property)
|
.filter((part) => part.trim() !== property)
|
||||||
.join(',');
|
.join(',');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle button and fire events
|
// Toggle button and fire events
|
||||||
onChange.call(this);
|
this.onChange();
|
||||||
}
|
};
|
||||||
|
|
||||||
class Fullscreen {
|
// Trap focus inside container
|
||||||
constructor(player) {
|
trapFocus = (event) => {
|
||||||
// Keep reference to parent
|
// Bail if iOS, not active, not the tab key
|
||||||
this.player = player;
|
if (browser.isIos || !this.active || event.key !== 'Tab' || event.keyCode !== 9) {
|
||||||
|
|
||||||
// Get prefix
|
|
||||||
this.prefix = Fullscreen.prefix;
|
|
||||||
this.property = Fullscreen.property;
|
|
||||||
|
|
||||||
// Scroll position
|
|
||||||
this.scrollPosition = { x: 0, y: 0 };
|
|
||||||
|
|
||||||
// Force the use of 'full window/browser' rather than fullscreen
|
|
||||||
this.forceFallback = player.config.fullscreen.fallback === 'force';
|
|
||||||
|
|
||||||
// Register event listeners
|
|
||||||
// Handle event (incase user presses escape etc)
|
|
||||||
on.call(
|
|
||||||
this.player,
|
|
||||||
document,
|
|
||||||
this.prefix === 'ms' ? 'MSFullscreenChange' : `${this.prefix}fullscreenchange`,
|
|
||||||
() => {
|
|
||||||
// TODO: Filter for target??
|
|
||||||
onChange.call(this);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Fullscreen toggle on double click
|
|
||||||
on.call(this.player, this.player.elements.container, 'dblclick', event => {
|
|
||||||
// Ignore double click in controls
|
|
||||||
if (is.element(this.player.elements.controls) && this.player.elements.controls.contains(event.target)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.toggle();
|
// Get the current focused element
|
||||||
});
|
const focused = document.activeElement;
|
||||||
|
const focusable = getElements.call(this.player, 'a[href], button:not(:disabled), input:not(:disabled), [tabindex]');
|
||||||
|
const [first] = focusable;
|
||||||
|
const last = focusable[focusable.length - 1];
|
||||||
|
|
||||||
// Update the UI
|
if (focused === last && !event.shiftKey) {
|
||||||
this.update();
|
// Move focus to first element that can be tabbed if Shift isn't used
|
||||||
}
|
first.focus();
|
||||||
|
event.preventDefault();
|
||||||
// Determine if native supported
|
} else if (focused === first && event.shiftKey) {
|
||||||
static get native() {
|
// Move focus to last element that can be tabbed if Shift is used
|
||||||
return !!(
|
last.focus();
|
||||||
document.fullscreenEnabled ||
|
event.preventDefault();
|
||||||
document.webkitFullscreenEnabled ||
|
|
||||||
document.mozFullScreenEnabled ||
|
|
||||||
document.msFullscreenEnabled
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're actually using native
|
|
||||||
get usingNative() {
|
|
||||||
return Fullscreen.native && !this.forceFallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the prefix for handlers
|
|
||||||
static get prefix() {
|
|
||||||
// No prefix
|
|
||||||
if (is.function(document.exitFullscreen)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for fullscreen support by vendor prefix
|
|
||||||
let value = '';
|
|
||||||
const prefixes = ['webkit', 'moz', 'ms'];
|
|
||||||
|
|
||||||
prefixes.some(pre => {
|
|
||||||
if (is.function(document[`${pre}ExitFullscreen`]) || is.function(document[`${pre}CancelFullScreen`])) {
|
|
||||||
value = pre;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static get property() {
|
|
||||||
return this.prefix === 'moz' ? 'FullScreen' : 'Fullscreen';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine if fullscreen is enabled
|
|
||||||
get enabled() {
|
|
||||||
return (
|
|
||||||
(Fullscreen.native || this.player.config.fullscreen.fallback) &&
|
|
||||||
this.player.config.fullscreen.enabled &&
|
|
||||||
this.player.supported.ui &&
|
|
||||||
this.player.isVideo
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get active state
|
|
||||||
get active() {
|
|
||||||
if (!this.enabled) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback using classname
|
|
||||||
if (!Fullscreen.native || this.forceFallback) {
|
|
||||||
return hasClass(this.target, this.player.config.classNames.fullscreen.fallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
const element = !this.prefix ? document.fullscreenElement : document[`${this.prefix}${this.property}Element`];
|
|
||||||
|
|
||||||
return element === this.target;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get target element
|
|
||||||
get target() {
|
|
||||||
return browser.isIos && this.player.config.fullscreen.iosNative
|
|
||||||
? this.player.media
|
|
||||||
: this.player.elements.container;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Update UI
|
// Update UI
|
||||||
update() {
|
update = () => {
|
||||||
if (this.enabled) {
|
if (this.enabled) {
|
||||||
let mode;
|
let mode;
|
||||||
|
|
||||||
@@ -214,28 +248,32 @@ class Fullscreen {
|
|||||||
|
|
||||||
// Add styling hook to show button
|
// Add styling hook to show button
|
||||||
toggleClass(this.player.elements.container, this.player.config.classNames.fullscreen.enabled, this.enabled);
|
toggleClass(this.player.elements.container, this.player.config.classNames.fullscreen.enabled, this.enabled);
|
||||||
}
|
};
|
||||||
|
|
||||||
// Make an element fullscreen
|
// Make an element fullscreen
|
||||||
enter() {
|
enter = () => {
|
||||||
if (!this.enabled) {
|
if (!this.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// iOS native fullscreen doesn't need the request step
|
// iOS native fullscreen doesn't need the request step
|
||||||
if (browser.isIos && this.player.config.fullscreen.iosNative) {
|
if (browser.isIos && this.player.config.fullscreen.iosNative) {
|
||||||
|
if (this.player.isVimeo) {
|
||||||
|
this.player.embed.requestFullscreen();
|
||||||
|
} else {
|
||||||
this.target.webkitEnterFullscreen();
|
this.target.webkitEnterFullscreen();
|
||||||
|
}
|
||||||
} else if (!Fullscreen.native || this.forceFallback) {
|
} else if (!Fullscreen.native || this.forceFallback) {
|
||||||
toggleFallback.call(this, true);
|
this.toggleFallback(true);
|
||||||
} else if (!this.prefix) {
|
} else if (!this.prefix) {
|
||||||
this.target.requestFullscreen();
|
this.target.requestFullscreen({ navigationUI: 'hide' });
|
||||||
} else if (!is.empty(this.prefix)) {
|
} else if (!is.empty(this.prefix)) {
|
||||||
this.target[`${this.prefix}Request${this.property}`]();
|
this.target[`${this.prefix}Request${this.property}`]();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// Bail from fullscreen
|
// Bail from fullscreen
|
||||||
exit() {
|
exit = () => {
|
||||||
if (!this.enabled) {
|
if (!this.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -243,25 +281,25 @@ class Fullscreen {
|
|||||||
// iOS native fullscreen
|
// iOS native fullscreen
|
||||||
if (browser.isIos && this.player.config.fullscreen.iosNative) {
|
if (browser.isIos && this.player.config.fullscreen.iosNative) {
|
||||||
this.target.webkitExitFullscreen();
|
this.target.webkitExitFullscreen();
|
||||||
this.player.play();
|
silencePromise(this.player.play());
|
||||||
} else if (!Fullscreen.native || this.forceFallback) {
|
} else if (!Fullscreen.native || this.forceFallback) {
|
||||||
toggleFallback.call(this, false);
|
this.toggleFallback(false);
|
||||||
} else if (!this.prefix) {
|
} else if (!this.prefix) {
|
||||||
(document.cancelFullScreen || document.exitFullscreen).call(document);
|
(document.cancelFullScreen || document.exitFullscreen).call(document);
|
||||||
} else if (!is.empty(this.prefix)) {
|
} else if (!is.empty(this.prefix)) {
|
||||||
const action = this.prefix === 'moz' ? 'Cancel' : 'Exit';
|
const action = this.prefix === 'moz' ? 'Cancel' : 'Exit';
|
||||||
document[`${this.prefix}${action}${this.property}`]();
|
document[`${this.prefix}${action}${this.property}`]();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// Toggle state
|
// Toggle state
|
||||||
toggle() {
|
toggle = () => {
|
||||||
if (!this.active) {
|
if (!this.active) {
|
||||||
this.enter();
|
this.enter();
|
||||||
} else {
|
} else {
|
||||||
this.exit();
|
this.exit();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Fullscreen;
|
export default Fullscreen;
|
||||||
|
|||||||
+26
-7
@@ -6,6 +6,7 @@ import support from './support';
|
|||||||
import { removeElement } from './utils/elements';
|
import { removeElement } from './utils/elements';
|
||||||
import { triggerEvent } from './utils/events';
|
import { triggerEvent } from './utils/events';
|
||||||
import is from './utils/is';
|
import is from './utils/is';
|
||||||
|
import { silencePromise } from './utils/promise';
|
||||||
import { setAspectRatio } from './utils/style';
|
import { setAspectRatio } from './utils/style';
|
||||||
|
|
||||||
const html5 = {
|
const html5 = {
|
||||||
@@ -17,7 +18,7 @@ const html5 = {
|
|||||||
const sources = Array.from(this.media.querySelectorAll('source'));
|
const sources = Array.from(this.media.querySelectorAll('source'));
|
||||||
|
|
||||||
// Filter out unsupported sources (if type is specified)
|
// Filter out unsupported sources (if type is specified)
|
||||||
return sources.filter(source => {
|
return sources.filter((source) => {
|
||||||
const type = source.getAttribute('type');
|
const type = source.getAttribute('type');
|
||||||
|
|
||||||
if (is.empty(type)) {
|
if (is.empty(type)) {
|
||||||
@@ -30,20 +31,28 @@ const html5 = {
|
|||||||
|
|
||||||
// Get quality levels
|
// Get quality levels
|
||||||
getQualityOptions() {
|
getQualityOptions() {
|
||||||
|
// Whether we're forcing all options (e.g. for streaming)
|
||||||
|
if (this.config.quality.forced) {
|
||||||
|
return this.config.quality.options;
|
||||||
|
}
|
||||||
|
|
||||||
// Get sizes from <source> elements
|
// Get sizes from <source> elements
|
||||||
return html5.getSources
|
return html5.getSources
|
||||||
.call(this)
|
.call(this)
|
||||||
.map(source => Number(source.getAttribute('size')))
|
.map((source) => Number(source.getAttribute('size')))
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
},
|
},
|
||||||
|
|
||||||
extend() {
|
setup() {
|
||||||
if (!this.isHTML5) {
|
if (!this.isHTML5) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const player = this;
|
const player = this;
|
||||||
|
|
||||||
|
// Set speed options from config
|
||||||
|
player.options.speed = player.config.speed.options;
|
||||||
|
|
||||||
// Set aspect ratio if fixed
|
// Set aspect ratio if fixed
|
||||||
if (!is.empty(this.config.ratio)) {
|
if (!is.empty(this.config.ratio)) {
|
||||||
setAspectRatio.call(player);
|
setAspectRatio.call(player);
|
||||||
@@ -54,16 +63,24 @@ const html5 = {
|
|||||||
get() {
|
get() {
|
||||||
// Get sources
|
// Get sources
|
||||||
const sources = html5.getSources.call(player);
|
const sources = html5.getSources.call(player);
|
||||||
const source = sources.find(s => s.getAttribute('src') === player.source);
|
const source = sources.find((s) => s.getAttribute('src') === player.source);
|
||||||
|
|
||||||
// Return size, if match is found
|
// Return size, if match is found
|
||||||
return source && Number(source.getAttribute('size'));
|
return source && Number(source.getAttribute('size'));
|
||||||
},
|
},
|
||||||
set(input) {
|
set(input) {
|
||||||
|
if (player.quality === input) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're using an external handler...
|
||||||
|
if (player.config.quality.forced && is.function(player.config.quality.onChange)) {
|
||||||
|
player.config.quality.onChange(input);
|
||||||
|
} else {
|
||||||
// Get sources
|
// Get sources
|
||||||
const sources = html5.getSources.call(player);
|
const sources = html5.getSources.call(player);
|
||||||
// Get first match for requested size
|
// Get first match for requested size
|
||||||
const source = sources.find(s => Number(s.getAttribute('size')) === input);
|
const source = sources.find((s) => Number(s.getAttribute('size')) === input);
|
||||||
|
|
||||||
// No matching source found
|
// No matching source found
|
||||||
if (!source) {
|
if (!source) {
|
||||||
@@ -71,7 +88,7 @@ const html5 = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get current state
|
// Get current state
|
||||||
const { currentTime, paused, preload, readyState } = player.media;
|
const { currentTime, paused, preload, readyState, playbackRate } = player.media;
|
||||||
|
|
||||||
// Set new source
|
// Set new source
|
||||||
player.media.src = source.getAttribute('src');
|
player.media.src = source.getAttribute('src');
|
||||||
@@ -80,17 +97,19 @@ const html5 = {
|
|||||||
if (preload !== 'none' || readyState) {
|
if (preload !== 'none' || readyState) {
|
||||||
// Restore time
|
// Restore time
|
||||||
player.once('loadedmetadata', () => {
|
player.once('loadedmetadata', () => {
|
||||||
|
player.speed = playbackRate;
|
||||||
player.currentTime = currentTime;
|
player.currentTime = currentTime;
|
||||||
|
|
||||||
// Resume playing
|
// Resume playing
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
player.play();
|
silencePromise(player.play());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load new source
|
// Load new source
|
||||||
player.media.load();
|
player.media.load();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Trigger change event
|
// Trigger change event
|
||||||
triggerEvent.call(player, player.media, 'qualitychange', false, {
|
triggerEvent.call(player, player.media, 'qualitychange', false, {
|
||||||
|
|||||||
+157
-100
@@ -6,10 +6,11 @@ import controls from './controls';
|
|||||||
import ui from './ui';
|
import ui from './ui';
|
||||||
import { repaint } from './utils/animation';
|
import { repaint } from './utils/animation';
|
||||||
import browser from './utils/browser';
|
import browser from './utils/browser';
|
||||||
import { getElement, getElements, matches, toggleClass, toggleHidden } from './utils/elements';
|
import { getElement, getElements, matches, toggleClass } from './utils/elements';
|
||||||
import { off, on, once, toggleListener, triggerEvent } from './utils/events';
|
import { off, on, once, toggleListener, triggerEvent } from './utils/events';
|
||||||
import is from './utils/is';
|
import is from './utils/is';
|
||||||
import { getAspectRatio, setAspectRatio } from './utils/style';
|
import { silencePromise } from './utils/promise';
|
||||||
|
import { getAspectRatio, getViewportSize, supportsCSS } from './utils/style';
|
||||||
|
|
||||||
class Listeners {
|
class Listeners {
|
||||||
constructor(player) {
|
constructor(player) {
|
||||||
@@ -99,7 +100,7 @@ class Listeners {
|
|||||||
case 75:
|
case 75:
|
||||||
// Space and K key
|
// Space and K key
|
||||||
if (!repeat) {
|
if (!repeat) {
|
||||||
player.togglePlay();
|
silencePromise(player.togglePlay());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -182,7 +183,7 @@ class Listeners {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Device is touch enabled
|
// Device is touch enabled
|
||||||
firstTouch() {
|
firstTouch = () => {
|
||||||
const { player } = this;
|
const { player } = this;
|
||||||
const { elements } = player;
|
const { elements } = player;
|
||||||
|
|
||||||
@@ -190,9 +191,9 @@ class Listeners {
|
|||||||
|
|
||||||
// Add touch class
|
// Add touch class
|
||||||
toggleClass(elements.container, player.config.classNames.isTouch, true);
|
toggleClass(elements.container, player.config.classNames.isTouch, true);
|
||||||
}
|
};
|
||||||
|
|
||||||
setTabFocus(event) {
|
setTabFocus = (event) => {
|
||||||
const { player } = this;
|
const { player } = this;
|
||||||
const { elements } = player;
|
const { elements } = player;
|
||||||
|
|
||||||
@@ -228,6 +229,7 @@ class Listeners {
|
|||||||
|
|
||||||
// Delay the adding of classname until the focus has changed
|
// Delay the adding of classname until the focus has changed
|
||||||
// This event fires before the focusin event
|
// This event fires before the focusin event
|
||||||
|
if (event.type !== 'focusout') {
|
||||||
this.focusTimer = setTimeout(() => {
|
this.focusTimer = setTimeout(() => {
|
||||||
const focused = document.activeElement;
|
const focused = document.activeElement;
|
||||||
|
|
||||||
@@ -239,9 +241,10 @@ class Listeners {
|
|||||||
toggleClass(document.activeElement, player.config.classNames.tabFocus, true);
|
toggleClass(document.activeElement, player.config.classNames.tabFocus, true);
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Global window & document listeners
|
// Global window & document listeners
|
||||||
global(toggle = true) {
|
global = (toggle = true) => {
|
||||||
const { player } = this;
|
const { player } = this;
|
||||||
|
|
||||||
// Keyboard shortcuts
|
// Keyboard shortcuts
|
||||||
@@ -256,11 +259,11 @@ class Listeners {
|
|||||||
once.call(player, document.body, 'touchstart', this.firstTouch);
|
once.call(player, document.body, 'touchstart', this.firstTouch);
|
||||||
|
|
||||||
// Tab focus detection
|
// Tab focus detection
|
||||||
toggleListener.call(player, document.body, 'keydown focus blur', this.setTabFocus, toggle, false, true);
|
toggleListener.call(player, document.body, 'keydown focus blur focusout', this.setTabFocus, toggle, false, true);
|
||||||
}
|
};
|
||||||
|
|
||||||
// Container listeners
|
// Container listeners
|
||||||
container() {
|
container = () => {
|
||||||
const { player } = this;
|
const { player } = this;
|
||||||
const { config, elements, timers } = player;
|
const { config, elements, timers } = player;
|
||||||
|
|
||||||
@@ -274,7 +277,7 @@ class Listeners {
|
|||||||
player,
|
player,
|
||||||
elements.container,
|
elements.container,
|
||||||
'mousemove mouseleave touchstart touchmove enterfullscreen exitfullscreen',
|
'mousemove mouseleave touchstart touchmove enterfullscreen exitfullscreen',
|
||||||
event => {
|
(event) => {
|
||||||
const { controls: controlsElement } = elements;
|
const { controls: controlsElement } = elements;
|
||||||
|
|
||||||
// Remove button states for fullscreen
|
// Remove button states for fullscreen
|
||||||
@@ -302,39 +305,49 @@ class Listeners {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Set a gutter for Vimeo
|
// Set a gutter for Vimeo
|
||||||
const setGutter = (ratio, padding, toggle) => {
|
const setGutter = () => {
|
||||||
if (!player.isVimeo) {
|
if (!player.isVimeo || player.config.vimeo.premium) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const target = player.elements.wrapper.firstChild;
|
const target = elements.wrapper;
|
||||||
const [, y] = ratio;
|
const { active } = player.fullscreen;
|
||||||
const [videoX, videoY] = getAspectRatio.call(player);
|
const [videoWidth, videoHeight] = getAspectRatio.call(player);
|
||||||
|
const useNativeAspectRatio = supportsCSS(`aspect-ratio: ${videoWidth} / ${videoHeight}`);
|
||||||
|
|
||||||
target.style.maxWidth = toggle ? `${(y / videoY) * videoX}px` : null;
|
// If not active, remove styles
|
||||||
target.style.margin = toggle ? '0 auto' : null;
|
if (!active) {
|
||||||
};
|
if (useNativeAspectRatio) {
|
||||||
|
target.style.width = null;
|
||||||
// Resize on fullscreen change
|
target.style.height = null;
|
||||||
const setPlayerSize = measure => {
|
} else {
|
||||||
// If we don't need to measure the viewport
|
target.style.maxWidth = null;
|
||||||
if (!measure) {
|
target.style.margin = null;
|
||||||
return setAspectRatio.call(player);
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rect = elements.container.getBoundingClientRect();
|
// Determine which dimension will overflow and constrain view
|
||||||
const { width, height } = rect;
|
const [viewportWidth, viewportHeight] = getViewportSize();
|
||||||
|
const overflow = viewportWidth / viewportHeight > videoWidth / videoHeight;
|
||||||
|
|
||||||
return setAspectRatio.call(player, `${width}:${height}`);
|
if (useNativeAspectRatio) {
|
||||||
|
target.style.width = overflow ? 'auto' : '100%';
|
||||||
|
target.style.height = overflow ? '100%' : 'auto';
|
||||||
|
} else {
|
||||||
|
target.style.maxWidth = overflow ? `${(viewportHeight / videoHeight) * videoWidth}px` : null;
|
||||||
|
target.style.margin = overflow ? '0 auto' : null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle resizing
|
||||||
const resized = () => {
|
const resized = () => {
|
||||||
clearTimeout(timers.resized);
|
clearTimeout(timers.resized);
|
||||||
timers.resized = setTimeout(setPlayerSize, 50);
|
timers.resized = setTimeout(setGutter, 50);
|
||||||
};
|
};
|
||||||
|
|
||||||
on.call(player, elements.container, 'enterfullscreen exitfullscreen', event => {
|
on.call(player, elements.container, 'enterfullscreen exitfullscreen', (event) => {
|
||||||
const { target, usingNative } = player.fullscreen;
|
const { target } = player.fullscreen;
|
||||||
|
|
||||||
// Ignore events not from target
|
// Ignore events not from target
|
||||||
if (target !== elements.container) {
|
if (target !== elements.container) {
|
||||||
@@ -346,68 +359,55 @@ class Listeners {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isEnter = event.type === 'enterfullscreen';
|
|
||||||
// Set the player size when entering fullscreen to viewport size
|
|
||||||
const { padding, ratio } = setPlayerSize(isEnter);
|
|
||||||
|
|
||||||
// Set Vimeo gutter
|
// Set Vimeo gutter
|
||||||
setGutter(ratio, padding, isEnter);
|
setGutter();
|
||||||
|
|
||||||
// If not using native fullscreen, we need to check for resizes of viewport
|
// Watch for resizes
|
||||||
if (!usingNative) {
|
const method = event.type === 'enterfullscreen' ? on : off;
|
||||||
if (isEnter) {
|
method.call(player, window, 'resize', resized);
|
||||||
on.call(player, window, 'resize', resized);
|
|
||||||
} else {
|
|
||||||
off.call(player, window, 'resize', resized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// Listen for media events
|
// Listen for media events
|
||||||
media() {
|
media = () => {
|
||||||
const { player } = this;
|
const { player } = this;
|
||||||
const { elements } = player;
|
const { elements } = player;
|
||||||
|
|
||||||
// Time change on media
|
// Time change on media
|
||||||
on.call(player, player.media, 'timeupdate seeking seeked', event => controls.timeUpdate.call(player, event));
|
on.call(player, player.media, 'timeupdate seeking seeked', (event) => controls.timeUpdate.call(player, event));
|
||||||
|
|
||||||
// Display duration
|
// Display duration
|
||||||
on.call(player, player.media, 'durationchange loadeddata loadedmetadata', event =>
|
on.call(player, player.media, 'durationchange loadeddata loadedmetadata', (event) =>
|
||||||
controls.durationUpdate.call(player, event),
|
controls.durationUpdate.call(player, event),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check for audio tracks on load
|
|
||||||
// We can't use `loadedmetadata` as it doesn't seem to have audio tracks at that point
|
|
||||||
on.call(player, player.media, 'canplay loadeddata', () => {
|
|
||||||
toggleHidden(elements.volume, !player.hasAudio);
|
|
||||||
toggleHidden(elements.buttons.mute, !player.hasAudio);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle the media finishing
|
// Handle the media finishing
|
||||||
on.call(player, player.media, 'ended', () => {
|
on.call(player, player.media, 'ended', () => {
|
||||||
// Show poster on end
|
// Show poster on end
|
||||||
if (player.isHTML5 && player.isVideo && player.config.resetOnEnd) {
|
if (player.isHTML5 && player.isVideo && player.config.resetOnEnd) {
|
||||||
// Restart
|
// Restart
|
||||||
player.restart();
|
player.restart();
|
||||||
|
|
||||||
|
// Call pause otherwise IE11 will start playing the video again
|
||||||
|
player.pause();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check for buffer progress
|
// Check for buffer progress
|
||||||
on.call(player, player.media, 'progress playing seeking seeked', event =>
|
on.call(player, player.media, 'progress playing seeking seeked', (event) =>
|
||||||
controls.updateProgress.call(player, event),
|
controls.updateProgress.call(player, event),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle volume changes
|
// Handle volume changes
|
||||||
on.call(player, player.media, 'volumechange', event => controls.updateVolume.call(player, event));
|
on.call(player, player.media, 'volumechange', (event) => controls.updateVolume.call(player, event));
|
||||||
|
|
||||||
// Handle play/pause
|
// Handle play/pause
|
||||||
on.call(player, player.media, 'playing play pause ended emptied timeupdate', event =>
|
on.call(player, player.media, 'playing play pause ended emptied timeupdate', (event) =>
|
||||||
ui.checkPlaying.call(player, event),
|
ui.checkPlaying.call(player, event),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Loading state
|
// Loading state
|
||||||
on.call(player, player.media, 'waiting canplay seeked playing', event => ui.checkLoading.call(player, event));
|
on.call(player, player.media, 'waiting canplay seeked playing', (event) => ui.checkLoading.call(player, event));
|
||||||
|
|
||||||
// Click video
|
// Click video
|
||||||
if (player.supported.ui && player.config.clickToPlay && !player.isAudio) {
|
if (player.supported.ui && player.config.clickToPlay && !player.isAudio) {
|
||||||
@@ -420,7 +420,7 @@ class Listeners {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// On click play, pause or restart
|
// On click play, pause or restart
|
||||||
on.call(player, elements.container, 'click', event => {
|
on.call(player, elements.container, 'click', (event) => {
|
||||||
const targets = [elements.container, wrapper];
|
const targets = [elements.container, wrapper];
|
||||||
|
|
||||||
// Ignore if click if not container or in video wrapper
|
// Ignore if click if not container or in video wrapper
|
||||||
@@ -435,9 +435,21 @@ class Listeners {
|
|||||||
|
|
||||||
if (player.ended) {
|
if (player.ended) {
|
||||||
this.proxy(event, player.restart, 'restart');
|
this.proxy(event, player.restart, 'restart');
|
||||||
this.proxy(event, player.play, 'play');
|
this.proxy(
|
||||||
|
event,
|
||||||
|
() => {
|
||||||
|
silencePromise(player.play());
|
||||||
|
},
|
||||||
|
'play',
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
this.proxy(event, player.togglePlay, 'play');
|
this.proxy(
|
||||||
|
event,
|
||||||
|
() => {
|
||||||
|
silencePromise(player.togglePlay());
|
||||||
|
},
|
||||||
|
'play',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -448,7 +460,7 @@ class Listeners {
|
|||||||
player,
|
player,
|
||||||
elements.wrapper,
|
elements.wrapper,
|
||||||
'contextmenu',
|
'contextmenu',
|
||||||
event => {
|
(event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
@@ -474,7 +486,7 @@ class Listeners {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Quality change
|
// Quality change
|
||||||
on.call(player, player.media, 'qualitychange', event => {
|
on.call(player, player.media, 'qualitychange', (event) => {
|
||||||
// Update UI
|
// Update UI
|
||||||
controls.updateSetting.call(player, 'quality', null, event.detail.quality);
|
controls.updateSetting.call(player, 'quality', null, event.detail.quality);
|
||||||
});
|
});
|
||||||
@@ -488,7 +500,7 @@ class Listeners {
|
|||||||
// Bubble up key events for Edge
|
// Bubble up key events for Edge
|
||||||
const proxyEvents = player.config.events.concat(['keyup', 'keydown']).join(' ');
|
const proxyEvents = player.config.events.concat(['keyup', 'keydown']).join(' ');
|
||||||
|
|
||||||
on.call(player, player.media, proxyEvents, event => {
|
on.call(player, player.media, proxyEvents, (event) => {
|
||||||
let { detail = {} } = event;
|
let { detail = {} } = event;
|
||||||
|
|
||||||
// Get error details from media
|
// Get error details from media
|
||||||
@@ -498,10 +510,10 @@ class Listeners {
|
|||||||
|
|
||||||
triggerEvent.call(player, elements.container, event.type, true, detail);
|
triggerEvent.call(player, elements.container, event.type, true, detail);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// Run default and custom handlers
|
// Run default and custom handlers
|
||||||
proxy(event, defaultHandler, customHandlerKey) {
|
proxy = (event, defaultHandler, customHandlerKey) => {
|
||||||
const { player } = this;
|
const { player } = this;
|
||||||
const customHandler = player.config.listeners[customHandlerKey];
|
const customHandler = player.config.listeners[customHandlerKey];
|
||||||
const hasCustomHandler = is.function(customHandler);
|
const hasCustomHandler = is.function(customHandler);
|
||||||
@@ -513,13 +525,13 @@ class Listeners {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only call default handler if not prevented in custom handler
|
// Only call default handler if not prevented in custom handler
|
||||||
if (returned && is.function(defaultHandler)) {
|
if (returned !== false && is.function(defaultHandler)) {
|
||||||
defaultHandler.call(player, event);
|
defaultHandler.call(player, event);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// Trigger custom and default handlers
|
// Trigger custom and default handlers
|
||||||
bind(element, type, defaultHandler, customHandlerKey, passive = true) {
|
bind = (element, type, defaultHandler, customHandlerKey, passive = true) => {
|
||||||
const { player } = this;
|
const { player } = this;
|
||||||
const customHandler = player.config.listeners[customHandlerKey];
|
const customHandler = player.config.listeners[customHandlerKey];
|
||||||
const hasCustomHandler = is.function(customHandler);
|
const hasCustomHandler = is.function(customHandler);
|
||||||
@@ -528,13 +540,13 @@ class Listeners {
|
|||||||
player,
|
player,
|
||||||
element,
|
element,
|
||||||
type,
|
type,
|
||||||
event => this.proxy(event, defaultHandler, customHandlerKey),
|
(event) => this.proxy(event, defaultHandler, customHandlerKey),
|
||||||
passive && !hasCustomHandler,
|
passive && !hasCustomHandler,
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
// Listen for control events
|
// Listen for control events
|
||||||
controls() {
|
controls = () => {
|
||||||
const { player } = this;
|
const { player } = this;
|
||||||
const { elements } = player;
|
const { elements } = player;
|
||||||
// IE doesn't support input event, so we fallback to change
|
// IE doesn't support input event, so we fallback to change
|
||||||
@@ -542,8 +554,15 @@ class Listeners {
|
|||||||
|
|
||||||
// Play/pause toggle
|
// Play/pause toggle
|
||||||
if (elements.buttons.play) {
|
if (elements.buttons.play) {
|
||||||
Array.from(elements.buttons.play).forEach(button => {
|
Array.from(elements.buttons.play).forEach((button) => {
|
||||||
this.bind(button, 'click', player.togglePlay, 'play');
|
this.bind(
|
||||||
|
button,
|
||||||
|
'click',
|
||||||
|
() => {
|
||||||
|
silencePromise(player.togglePlay());
|
||||||
|
},
|
||||||
|
'play',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,10 +570,28 @@ class Listeners {
|
|||||||
this.bind(elements.buttons.restart, 'click', player.restart, 'restart');
|
this.bind(elements.buttons.restart, 'click', player.restart, 'restart');
|
||||||
|
|
||||||
// Rewind
|
// Rewind
|
||||||
this.bind(elements.buttons.rewind, 'click', player.rewind, 'rewind');
|
this.bind(
|
||||||
|
elements.buttons.rewind,
|
||||||
|
'click',
|
||||||
|
() => {
|
||||||
|
// Record seek time so we can prevent hiding controls for a few seconds after rewind
|
||||||
|
player.lastSeekTime = Date.now();
|
||||||
|
player.rewind();
|
||||||
|
},
|
||||||
|
'rewind',
|
||||||
|
);
|
||||||
|
|
||||||
// Rewind
|
// Rewind
|
||||||
this.bind(elements.buttons.fastForward, 'click', player.forward, 'fastForward');
|
this.bind(
|
||||||
|
elements.buttons.fastForward,
|
||||||
|
'click',
|
||||||
|
() => {
|
||||||
|
// Record seek time so we can prevent hiding controls for a few seconds after fast forward
|
||||||
|
player.lastSeekTime = Date.now();
|
||||||
|
player.forward();
|
||||||
|
},
|
||||||
|
'fastForward',
|
||||||
|
);
|
||||||
|
|
||||||
// Mute toggle
|
// Mute toggle
|
||||||
this.bind(
|
this.bind(
|
||||||
@@ -603,12 +640,19 @@ class Listeners {
|
|||||||
this.bind(elements.buttons.airplay, 'click', player.airplay, 'airplay');
|
this.bind(elements.buttons.airplay, 'click', player.airplay, 'airplay');
|
||||||
|
|
||||||
// Settings menu - click toggle
|
// Settings menu - click toggle
|
||||||
this.bind(elements.buttons.settings, 'click', event => {
|
this.bind(
|
||||||
|
elements.buttons.settings,
|
||||||
|
'click',
|
||||||
|
(event) => {
|
||||||
// Prevent the document click listener closing the menu
|
// Prevent the document click listener closing the menu
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
controls.toggleMenu.call(player, event);
|
controls.toggleMenu.call(player, event);
|
||||||
});
|
},
|
||||||
|
null,
|
||||||
|
false,
|
||||||
|
); // Can't be passive as we're preventing default
|
||||||
|
|
||||||
// Settings menu - keyboard toggle
|
// Settings menu - keyboard toggle
|
||||||
// We have to bind to keyup otherwise Firefox triggers a click when a keydown event handler shifts focus
|
// We have to bind to keyup otherwise Firefox triggers a click when a keydown event handler shifts focus
|
||||||
@@ -616,7 +660,7 @@ class Listeners {
|
|||||||
this.bind(
|
this.bind(
|
||||||
elements.buttons.settings,
|
elements.buttons.settings,
|
||||||
'keyup',
|
'keyup',
|
||||||
event => {
|
(event) => {
|
||||||
const code = event.which;
|
const code = event.which;
|
||||||
|
|
||||||
// We only care about space and return
|
// We only care about space and return
|
||||||
@@ -644,26 +688,26 @@ class Listeners {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Escape closes menu
|
// Escape closes menu
|
||||||
this.bind(elements.settings.menu, 'keydown', event => {
|
this.bind(elements.settings.menu, 'keydown', (event) => {
|
||||||
if (event.which === 27) {
|
if (event.which === 27) {
|
||||||
controls.toggleMenu.call(player, event);
|
controls.toggleMenu.call(player, event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set range input alternative "value", which matches the tooltip time (#954)
|
// Set range input alternative "value", which matches the tooltip time (#954)
|
||||||
this.bind(elements.inputs.seek, 'mousedown mousemove', event => {
|
this.bind(elements.inputs.seek, 'mousedown mousemove', (event) => {
|
||||||
const rect = elements.progress.getBoundingClientRect();
|
const rect = elements.progress.getBoundingClientRect();
|
||||||
const percent = (100 / rect.width) * (event.pageX - rect.left);
|
const percent = (100 / rect.width) * (event.pageX - rect.left);
|
||||||
event.currentTarget.setAttribute('seek-value', percent);
|
event.currentTarget.setAttribute('seek-value', percent);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pause while seeking
|
// Pause while seeking
|
||||||
this.bind(elements.inputs.seek, 'mousedown mouseup keydown keyup touchstart touchend', event => {
|
this.bind(elements.inputs.seek, 'mousedown mouseup keydown keyup touchstart touchend', (event) => {
|
||||||
const seek = event.currentTarget;
|
const seek = event.currentTarget;
|
||||||
const code = event.keyCode ? event.keyCode : event.which;
|
const code = event.keyCode ? event.keyCode : event.which;
|
||||||
const attribute = 'play-on-seeked';
|
const attribute = 'play-on-seeked';
|
||||||
|
|
||||||
if (is.keyboardEvent(event) && (code !== 39 && code !== 37)) {
|
if (is.keyboardEvent(event) && code !== 39 && code !== 37) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,7 +722,7 @@ class Listeners {
|
|||||||
// If we're done seeking and it was playing, resume playback
|
// If we're done seeking and it was playing, resume playback
|
||||||
if (play && done) {
|
if (play && done) {
|
||||||
seek.removeAttribute(attribute);
|
seek.removeAttribute(attribute);
|
||||||
player.play();
|
silencePromise(player.play());
|
||||||
} else if (!done && player.playing) {
|
} else if (!done && player.playing) {
|
||||||
seek.setAttribute(attribute, '');
|
seek.setAttribute(attribute, '');
|
||||||
player.pause();
|
player.pause();
|
||||||
@@ -690,14 +734,14 @@ class Listeners {
|
|||||||
// it takes over further interactions on the page. This is a hack
|
// it takes over further interactions on the page. This is a hack
|
||||||
if (browser.isIos) {
|
if (browser.isIos) {
|
||||||
const inputs = getElements.call(player, 'input[type="range"]');
|
const inputs = getElements.call(player, 'input[type="range"]');
|
||||||
Array.from(inputs).forEach(input => this.bind(input, inputEvent, event => repaint(event.target)));
|
Array.from(inputs).forEach((input) => this.bind(input, inputEvent, (event) => repaint(event.target)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seek
|
// Seek
|
||||||
this.bind(
|
this.bind(
|
||||||
elements.inputs.seek,
|
elements.inputs.seek,
|
||||||
inputEvent,
|
inputEvent,
|
||||||
event => {
|
(event) => {
|
||||||
const seek = event.currentTarget;
|
const seek = event.currentTarget;
|
||||||
// If it exists, use seek-value instead of "value" for consistency with tooltip time (#954)
|
// If it exists, use seek-value instead of "value" for consistency with tooltip time (#954)
|
||||||
let seekTo = seek.getAttribute('seek-value');
|
let seekTo = seek.getAttribute('seek-value');
|
||||||
@@ -714,13 +758,13 @@ class Listeners {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Seek tooltip
|
// Seek tooltip
|
||||||
this.bind(elements.progress, 'mouseenter mouseleave mousemove', event =>
|
this.bind(elements.progress, 'mouseenter mouseleave mousemove', (event) =>
|
||||||
controls.updateSeekTooltip.call(player, event),
|
controls.updateSeekTooltip.call(player, event),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Preview thumbnails plugin
|
// Preview thumbnails plugin
|
||||||
// TODO: Really need to work on some sort of plug-in wide event bus or pub-sub for this
|
// TODO: Really need to work on some sort of plug-in wide event bus or pub-sub for this
|
||||||
this.bind(elements.progress, 'mousemove touchmove', event => {
|
this.bind(elements.progress, 'mousemove touchmove', (event) => {
|
||||||
const { previewThumbnails } = player;
|
const { previewThumbnails } = player;
|
||||||
|
|
||||||
if (previewThumbnails && previewThumbnails.loaded) {
|
if (previewThumbnails && previewThumbnails.loaded) {
|
||||||
@@ -729,7 +773,7 @@ class Listeners {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Hide thumbnail preview - on mouse click, mouse leave, and video play/seek. All four are required, e.g., for buffering
|
// Hide thumbnail preview - on mouse click, mouse leave, and video play/seek. All four are required, e.g., for buffering
|
||||||
this.bind(elements.progress, 'mouseleave click', () => {
|
this.bind(elements.progress, 'mouseleave touchend click', () => {
|
||||||
const { previewThumbnails } = player;
|
const { previewThumbnails } = player;
|
||||||
|
|
||||||
if (previewThumbnails && previewThumbnails.loaded) {
|
if (previewThumbnails && previewThumbnails.loaded) {
|
||||||
@@ -738,7 +782,7 @@ class Listeners {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Show scrubbing preview
|
// Show scrubbing preview
|
||||||
this.bind(elements.progress, 'mousedown touchstart', event => {
|
this.bind(elements.progress, 'mousedown touchstart', (event) => {
|
||||||
const { previewThumbnails } = player;
|
const { previewThumbnails } = player;
|
||||||
|
|
||||||
if (previewThumbnails && previewThumbnails.loaded) {
|
if (previewThumbnails && previewThumbnails.loaded) {
|
||||||
@@ -746,7 +790,7 @@ class Listeners {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.bind(elements.progress, 'mouseup touchend', event => {
|
this.bind(elements.progress, 'mouseup touchend', (event) => {
|
||||||
const { previewThumbnails } = player;
|
const { previewThumbnails } = player;
|
||||||
|
|
||||||
if (previewThumbnails && previewThumbnails.loaded) {
|
if (previewThumbnails && previewThumbnails.loaded) {
|
||||||
@@ -756,8 +800,8 @@ class Listeners {
|
|||||||
|
|
||||||
// Polyfill for lower fill in <input type="range"> for webkit
|
// Polyfill for lower fill in <input type="range"> for webkit
|
||||||
if (browser.isWebkit) {
|
if (browser.isWebkit) {
|
||||||
Array.from(getElements.call(player, 'input[type="range"]')).forEach(element => {
|
Array.from(getElements.call(player, 'input[type="range"]')).forEach((element) => {
|
||||||
this.bind(element, 'input', event => controls.updateRangeFill.call(player, event.target));
|
this.bind(element, 'input', (event) => controls.updateRangeFill.call(player, event.target));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -780,19 +824,32 @@ class Listeners {
|
|||||||
this.bind(
|
this.bind(
|
||||||
elements.inputs.volume,
|
elements.inputs.volume,
|
||||||
inputEvent,
|
inputEvent,
|
||||||
event => {
|
(event) => {
|
||||||
player.volume = event.target.value;
|
player.volume = event.target.value;
|
||||||
},
|
},
|
||||||
'volume',
|
'volume',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update controls.hover state (used for ui.toggleControls to avoid hiding when interacting)
|
// Update controls.hover state (used for ui.toggleControls to avoid hiding when interacting)
|
||||||
this.bind(elements.controls, 'mouseenter mouseleave', event => {
|
this.bind(elements.controls, 'mouseenter mouseleave', (event) => {
|
||||||
elements.controls.hover = !player.touch && event.type === 'mouseenter';
|
elements.controls.hover = !player.touch && event.type === 'mouseenter';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Also update controls.hover state for any non-player children of fullscreen element (as above)
|
||||||
|
if (elements.fullscreen) {
|
||||||
|
Array.from(elements.fullscreen.children)
|
||||||
|
.filter((c) => !c.contains(elements.container))
|
||||||
|
.forEach((child) => {
|
||||||
|
this.bind(child, 'mouseenter mouseleave', (event) => {
|
||||||
|
if (elements.controls) {
|
||||||
|
elements.controls.hover = !player.touch && event.type === 'mouseenter';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Update controls.pressed state (used for ui.toggleControls to avoid hiding when interacting)
|
// Update controls.pressed state (used for ui.toggleControls to avoid hiding when interacting)
|
||||||
this.bind(elements.controls, 'mousedown mouseup touchstart touchend touchcancel', event => {
|
this.bind(elements.controls, 'mousedown mouseup touchstart touchend touchcancel', (event) => {
|
||||||
elements.controls.pressed = ['mousedown', 'touchstart'].includes(event.type);
|
elements.controls.pressed = ['mousedown', 'touchstart'].includes(event.type);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -825,12 +882,12 @@ class Listeners {
|
|||||||
this.bind(
|
this.bind(
|
||||||
elements.inputs.volume,
|
elements.inputs.volume,
|
||||||
'wheel',
|
'wheel',
|
||||||
event => {
|
(event) => {
|
||||||
// Detect "natural" scroll - suppored on OS X Safari only
|
// Detect "natural" scroll - suppored on OS X Safari only
|
||||||
// Other browsers on OS X will be inverted until support improves
|
// Other browsers on OS X will be inverted until support improves
|
||||||
const inverted = event.webkitDirectionInvertedFromDevice;
|
const inverted = event.webkitDirectionInvertedFromDevice;
|
||||||
// Get delta from event. Invert if `inverted` is true
|
// Get delta from event. Invert if `inverted` is true
|
||||||
const [x, y] = [event.deltaX, -event.deltaY].map(value => (inverted ? -value : value));
|
const [x, y] = [event.deltaX, -event.deltaY].map((value) => (inverted ? -value : value));
|
||||||
// Using the biggest delta, normalize to 1 or -1 (or 0 if no delta)
|
// Using the biggest delta, normalize to 1 or -1 (or 0 if no delta)
|
||||||
const direction = Math.sign(Math.abs(x) > Math.abs(y) ? x : y);
|
const direction = Math.sign(Math.abs(x) > Math.abs(y) ? x : y);
|
||||||
|
|
||||||
@@ -846,7 +903,7 @@ class Listeners {
|
|||||||
'volume',
|
'volume',
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Listeners;
|
export default Listeners;
|
||||||
|
|||||||
+2
-2
@@ -38,7 +38,7 @@ const media = {
|
|||||||
// Wrap the video in a container
|
// Wrap the video in a container
|
||||||
wrap(this.media, this.elements.wrapper);
|
wrap(this.media, this.elements.wrapper);
|
||||||
|
|
||||||
// Faux poster container
|
// Poster image container
|
||||||
this.elements.poster = createElement('div', {
|
this.elements.poster = createElement('div', {
|
||||||
class: this.config.classNames.poster,
|
class: this.config.classNames.poster,
|
||||||
});
|
});
|
||||||
@@ -47,7 +47,7 @@ const media = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.isHTML5) {
|
if (this.isHTML5) {
|
||||||
html5.extend.call(this);
|
html5.setup.call(this);
|
||||||
} else if (this.isYouTube) {
|
} else if (this.isYouTube) {
|
||||||
youtube.setup.call(this);
|
youtube.setup.call(this);
|
||||||
} else if (this.isVimeo) {
|
} else if (this.isVimeo) {
|
||||||
|
|||||||
+69
-61
@@ -11,10 +11,11 @@ import { triggerEvent } from '../utils/events';
|
|||||||
import i18n from '../utils/i18n';
|
import i18n from '../utils/i18n';
|
||||||
import is from '../utils/is';
|
import is from '../utils/is';
|
||||||
import loadScript from '../utils/load-script';
|
import loadScript from '../utils/load-script';
|
||||||
|
import { silencePromise } from '../utils/promise';
|
||||||
import { formatTime } from '../utils/time';
|
import { formatTime } from '../utils/time';
|
||||||
import { buildUrlParams } from '../utils/urls';
|
import { buildUrlParams } from '../utils/urls';
|
||||||
|
|
||||||
const destroy = instance => {
|
const destroy = (instance) => {
|
||||||
// Destroy our adsManager
|
// Destroy our adsManager
|
||||||
if (instance.manager) {
|
if (instance.manager) {
|
||||||
instance.manager.destroy();
|
instance.manager.destroy();
|
||||||
@@ -76,7 +77,7 @@ class Ads {
|
|||||||
/**
|
/**
|
||||||
* Load the IMA SDK
|
* Load the IMA SDK
|
||||||
*/
|
*/
|
||||||
load() {
|
load = () => {
|
||||||
if (!this.enabled) {
|
if (!this.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -94,12 +95,12 @@ class Ads {
|
|||||||
} else {
|
} else {
|
||||||
this.ready();
|
this.ready();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ads instance ready
|
* Get the ads instance ready
|
||||||
*/
|
*/
|
||||||
ready() {
|
ready = () => {
|
||||||
// Double check we're enabled
|
// Double check we're enabled
|
||||||
if (!this.enabled) {
|
if (!this.enabled) {
|
||||||
destroy(this);
|
destroy(this);
|
||||||
@@ -119,7 +120,7 @@ class Ads {
|
|||||||
|
|
||||||
// Setup the IMA SDK
|
// Setup the IMA SDK
|
||||||
this.setupIMA();
|
this.setupIMA();
|
||||||
}
|
};
|
||||||
|
|
||||||
// Build the tag URL
|
// Build the tag URL
|
||||||
get tagUrl() {
|
get tagUrl() {
|
||||||
@@ -136,7 +137,7 @@ class Ads {
|
|||||||
cb: Date.now(),
|
cb: Date.now(),
|
||||||
AV_WIDTH: 640,
|
AV_WIDTH: 640,
|
||||||
AV_HEIGHT: 480,
|
AV_HEIGHT: 480,
|
||||||
AV_CDIM2: this.publisherId,
|
AV_CDIM2: config.publisherId,
|
||||||
};
|
};
|
||||||
|
|
||||||
const base = 'https://go.aniview.com/api/adserver6/vast/';
|
const base = 'https://go.aniview.com/api/adserver6/vast/';
|
||||||
@@ -152,7 +153,7 @@ class Ads {
|
|||||||
* properly place mid-rolls. After we create the ad display container, we initialize it. On
|
* properly place mid-rolls. After we create the ad display container, we initialize it. On
|
||||||
* mobile devices, this initialization is done as the result of a user action.
|
* mobile devices, this initialization is done as the result of a user action.
|
||||||
*/
|
*/
|
||||||
setupIMA() {
|
setupIMA = () => {
|
||||||
// Create the container for our advertisements
|
// Create the container for our advertisements
|
||||||
this.elements.container = createElement('div', {
|
this.elements.container = createElement('div', {
|
||||||
class: this.player.config.classNames.ads,
|
class: this.player.config.classNames.ads,
|
||||||
@@ -172,28 +173,28 @@ class Ads {
|
|||||||
// We assume the adContainer is the video container of the plyr element that will house the ads
|
// We assume the adContainer is the video container of the plyr element that will house the ads
|
||||||
this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container, this.player.media);
|
this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container, this.player.media);
|
||||||
|
|
||||||
// Request video ads to be pre-loaded
|
|
||||||
this.requestAds();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request advertisements
|
|
||||||
*/
|
|
||||||
requestAds() {
|
|
||||||
const { container } = this.player.elements;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Create ads loader
|
// Create ads loader
|
||||||
this.loader = new google.ima.AdsLoader(this.elements.displayContainer);
|
this.loader = new google.ima.AdsLoader(this.elements.displayContainer);
|
||||||
|
|
||||||
// Listen and respond to ads loaded and error events
|
// Listen and respond to ads loaded and error events
|
||||||
this.loader.addEventListener(
|
this.loader.addEventListener(
|
||||||
google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
|
google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
|
||||||
event => this.onAdsManagerLoaded(event),
|
(event) => this.onAdsManagerLoaded(event),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error), false);
|
this.loader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, (error) => this.onAdError(error), false);
|
||||||
|
|
||||||
|
// Request video ads to be pre-loaded
|
||||||
|
this.requestAds();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request advertisements
|
||||||
|
*/
|
||||||
|
requestAds = () => {
|
||||||
|
const { container } = this.player.elements;
|
||||||
|
|
||||||
|
try {
|
||||||
// Request video ads
|
// Request video ads
|
||||||
const request = new google.ima.AdsRequest();
|
const request = new google.ima.AdsRequest();
|
||||||
request.adTagUrl = this.tagUrl;
|
request.adTagUrl = this.tagUrl;
|
||||||
@@ -212,16 +213,16 @@ class Ads {
|
|||||||
request.setAdWillPlayMuted(!this.player.muted);
|
request.setAdWillPlayMuted(!this.player.muted);
|
||||||
|
|
||||||
this.loader.requestAds(request);
|
this.loader.requestAds(request);
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
this.onAdError(e);
|
this.onAdError(error);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the ad countdown
|
* Update the ad countdown
|
||||||
* @param {Boolean} start
|
* @param {Boolean} start
|
||||||
*/
|
*/
|
||||||
pollCountdown(start = false) {
|
pollCountdown = (start = false) => {
|
||||||
if (!start) {
|
if (!start) {
|
||||||
clearInterval(this.countdownTimer);
|
clearInterval(this.countdownTimer);
|
||||||
this.elements.container.removeAttribute('data-badge-text');
|
this.elements.container.removeAttribute('data-badge-text');
|
||||||
@@ -235,13 +236,13 @@ class Ads {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.countdownTimer = setInterval(update, 100);
|
this.countdownTimer = setInterval(update, 100);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called whenever the ads are ready inside the AdDisplayContainer
|
* This method is called whenever the ads are ready inside the AdDisplayContainer
|
||||||
* @param {Event} adsManagerLoadedEvent
|
* @param {Event} adsManagerLoadedEvent
|
||||||
*/
|
*/
|
||||||
onAdsManagerLoaded(event) {
|
onAdsManagerLoaded = (event) => {
|
||||||
// Load could occur after a source change (race condition)
|
// Load could occur after a source change (race condition)
|
||||||
if (!this.enabled) {
|
if (!this.enabled) {
|
||||||
return;
|
return;
|
||||||
@@ -263,21 +264,21 @@ class Ads {
|
|||||||
|
|
||||||
// Add listeners to the required events
|
// Add listeners to the required events
|
||||||
// Advertisement error events
|
// Advertisement error events
|
||||||
this.manager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error));
|
this.manager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, (error) => this.onAdError(error));
|
||||||
|
|
||||||
// Advertisement regular events
|
// Advertisement regular events
|
||||||
Object.keys(google.ima.AdEvent.Type).forEach(type => {
|
Object.keys(google.ima.AdEvent.Type).forEach((type) => {
|
||||||
this.manager.addEventListener(google.ima.AdEvent.Type[type], e => this.onAdEvent(e));
|
this.manager.addEventListener(google.ima.AdEvent.Type[type], (e) => this.onAdEvent(e));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Resolve our adsManager
|
// Resolve our adsManager
|
||||||
this.trigger('loaded');
|
this.trigger('loaded');
|
||||||
}
|
};
|
||||||
|
|
||||||
addCuePoints() {
|
addCuePoints = () => {
|
||||||
// Add advertisement cue's within the time line if available
|
// Add advertisement cue's within the time line if available
|
||||||
if (!is.empty(this.cuePoints)) {
|
if (!is.empty(this.cuePoints)) {
|
||||||
this.cuePoints.forEach(cuePoint => {
|
this.cuePoints.forEach((cuePoint) => {
|
||||||
if (cuePoint !== 0 && cuePoint !== -1 && cuePoint < this.player.duration) {
|
if (cuePoint !== 0 && cuePoint !== -1 && cuePoint < this.player.duration) {
|
||||||
const seekElement = this.player.elements.progress;
|
const seekElement = this.player.elements.progress;
|
||||||
|
|
||||||
@@ -293,7 +294,7 @@ class Ads {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is where all the event handling takes place. Retrieve the ad from the event. Some
|
* This is where all the event handling takes place. Retrieve the ad from the event. Some
|
||||||
@@ -301,7 +302,7 @@ class Ads {
|
|||||||
* https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdEvent.Type
|
* https://developers.google.com/interactive-media-ads/docs/sdks/html5/v3/apis#ima.AdEvent.Type
|
||||||
* @param {Event} event
|
* @param {Event} event
|
||||||
*/
|
*/
|
||||||
onAdEvent(event) {
|
onAdEvent = (event) => {
|
||||||
const { container } = this.player.elements;
|
const { container } = this.player.elements;
|
||||||
// Retrieve the ad from the event. Some events (e.g. ALL_ADS_COMPLETED)
|
// Retrieve the ad from the event. Some events (e.g. ALL_ADS_COMPLETED)
|
||||||
// don't have ad object associated
|
// don't have ad object associated
|
||||||
@@ -309,7 +310,7 @@ class Ads {
|
|||||||
const adData = event.getAdData();
|
const adData = event.getAdData();
|
||||||
|
|
||||||
// Proxy event
|
// Proxy event
|
||||||
const dispatchEvent = type => {
|
const dispatchEvent = (type) => {
|
||||||
triggerEvent.call(this.player, this.player.media, `ads${type.replace(/_/g, '').toLowerCase()}`);
|
triggerEvent.call(this.player, this.player.media, `ads${type.replace(/_/g, '').toLowerCase()}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -369,7 +370,12 @@ class Ads {
|
|||||||
// TODO: So there is still this thing where a video should only be allowed to start
|
// TODO: So there is still this thing where a video should only be allowed to start
|
||||||
// playing when the IMA SDK is ready or has failed
|
// playing when the IMA SDK is ready or has failed
|
||||||
|
|
||||||
|
if (this.player.ended) {
|
||||||
this.loadAds();
|
this.loadAds();
|
||||||
|
} else {
|
||||||
|
// The SDK won't allow new ads to be called without receiving a contentComplete()
|
||||||
|
this.loader.contentComplete();
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -404,23 +410,23 @@ class Ads {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Any ad error handling comes through here
|
* Any ad error handling comes through here
|
||||||
* @param {Event} event
|
* @param {Event} event
|
||||||
*/
|
*/
|
||||||
onAdError(event) {
|
onAdError = (event) => {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
this.player.debug.warn('Ads error', event);
|
this.player.debug.warn('Ads error', event);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup hooks for Plyr and window events. This ensures
|
* Setup hooks for Plyr and window events. This ensures
|
||||||
* the mid- and post-roll launch at the correct time. And
|
* the mid- and post-roll launch at the correct time. And
|
||||||
* resize the advertisement when the player resizes
|
* resize the advertisement when the player resizes
|
||||||
*/
|
*/
|
||||||
listeners() {
|
listeners = () => {
|
||||||
const { container } = this.player.elements;
|
const { container } = this.player.elements;
|
||||||
let time;
|
let time;
|
||||||
|
|
||||||
@@ -458,12 +464,12 @@ class Ads {
|
|||||||
this.manager.resize(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL);
|
this.manager.resize(container.offsetWidth, container.offsetHeight, google.ima.ViewMode.NORMAL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the adsManager and start playing advertisements
|
* Initialize the adsManager and start playing advertisements
|
||||||
*/
|
*/
|
||||||
play() {
|
play = () => {
|
||||||
const { container } = this.player.elements;
|
const { container } = this.player.elements;
|
||||||
|
|
||||||
if (!this.managerPromise) {
|
if (!this.managerPromise) {
|
||||||
@@ -497,12 +503,12 @@ class Ads {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resume our video
|
* Resume our video
|
||||||
*/
|
*/
|
||||||
resumeContent() {
|
resumeContent = () => {
|
||||||
// Hide the advertisement container
|
// Hide the advertisement container
|
||||||
this.elements.container.style.zIndex = '';
|
this.elements.container.style.zIndex = '';
|
||||||
|
|
||||||
@@ -510,13 +516,13 @@ class Ads {
|
|||||||
this.playing = false;
|
this.playing = false;
|
||||||
|
|
||||||
// Play video
|
// Play video
|
||||||
this.player.media.play();
|
silencePromise(this.player.media.play());
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pause our video
|
* Pause our video
|
||||||
*/
|
*/
|
||||||
pauseContent() {
|
pauseContent = () => {
|
||||||
// Show the advertisement container
|
// Show the advertisement container
|
||||||
this.elements.container.style.zIndex = 3;
|
this.elements.container.style.zIndex = 3;
|
||||||
|
|
||||||
@@ -525,7 +531,7 @@ class Ads {
|
|||||||
|
|
||||||
// Pause our video.
|
// Pause our video.
|
||||||
this.player.media.pause();
|
this.player.media.pause();
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the adsManager so we can grab new ads after this. If we don't then we're not
|
* Destroy the adsManager so we can grab new ads after this. If we don't then we're not
|
||||||
@@ -533,7 +539,7 @@ class Ads {
|
|||||||
* video requests. https://developers.google.com/interactive-
|
* video requests. https://developers.google.com/interactive-
|
||||||
* media-ads/docs/sdks/android/faq#8
|
* media-ads/docs/sdks/android/faq#8
|
||||||
*/
|
*/
|
||||||
cancel() {
|
cancel = () => {
|
||||||
// Pause our video
|
// Pause our video
|
||||||
if (this.initialized) {
|
if (this.initialized) {
|
||||||
this.resumeContent();
|
this.resumeContent();
|
||||||
@@ -544,12 +550,12 @@ class Ads {
|
|||||||
|
|
||||||
// Re-create our adsManager
|
// Re-create our adsManager
|
||||||
this.loadAds();
|
this.loadAds();
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-create our adsManager
|
* Re-create our adsManager
|
||||||
*/
|
*/
|
||||||
loadAds() {
|
loadAds = () => {
|
||||||
// Tell our adsManager to go bye bye
|
// Tell our adsManager to go bye bye
|
||||||
this.managerPromise
|
this.managerPromise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -559,32 +565,34 @@ class Ads {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Re-set our adsManager promises
|
// Re-set our adsManager promises
|
||||||
this.managerPromise = new Promise(resolve => {
|
this.managerPromise = new Promise((resolve) => {
|
||||||
this.on('loaded', resolve);
|
this.on('loaded', resolve);
|
||||||
this.player.debug.log(this.manager);
|
this.player.debug.log(this.manager);
|
||||||
});
|
});
|
||||||
|
// Now that the manager has been destroyed set it to also be un-initialized
|
||||||
|
this.initialized = false;
|
||||||
|
|
||||||
// Now request some new advertisements
|
// Now request some new advertisements
|
||||||
this.requestAds();
|
this.requestAds();
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles callbacks after an ad event was invoked
|
* Handles callbacks after an ad event was invoked
|
||||||
* @param {String} event - Event type
|
* @param {String} event - Event type
|
||||||
*/
|
*/
|
||||||
trigger(event, ...args) {
|
trigger = (event, ...args) => {
|
||||||
const handlers = this.events[event];
|
const handlers = this.events[event];
|
||||||
|
|
||||||
if (is.array(handlers)) {
|
if (is.array(handlers)) {
|
||||||
handlers.forEach(handler => {
|
handlers.forEach((handler) => {
|
||||||
if (is.function(handler)) {
|
if (is.function(handler)) {
|
||||||
handler.apply(this, args);
|
handler.apply(this, args);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add event listeners
|
* Add event listeners
|
||||||
@@ -592,7 +600,7 @@ class Ads {
|
|||||||
* @param {Function} callback - Callback for when event occurs
|
* @param {Function} callback - Callback for when event occurs
|
||||||
* @return {Ads}
|
* @return {Ads}
|
||||||
*/
|
*/
|
||||||
on(event, callback) {
|
on = (event, callback) => {
|
||||||
if (!is.array(this.events[event])) {
|
if (!is.array(this.events[event])) {
|
||||||
this.events[event] = [];
|
this.events[event] = [];
|
||||||
}
|
}
|
||||||
@@ -600,7 +608,7 @@ class Ads {
|
|||||||
this.events[event].push(callback);
|
this.events[event].push(callback);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup a safety timer for when the ad network doesn't respond for whatever reason.
|
* Setup a safety timer for when the ad network doesn't respond for whatever reason.
|
||||||
@@ -610,27 +618,27 @@ class Ads {
|
|||||||
* @param {Number} time
|
* @param {Number} time
|
||||||
* @param {String} from
|
* @param {String} from
|
||||||
*/
|
*/
|
||||||
startSafetyTimer(time, from) {
|
startSafetyTimer = (time, from) => {
|
||||||
this.player.debug.log(`Safety timer invoked from: ${from}`);
|
this.player.debug.log(`Safety timer invoked from: ${from}`);
|
||||||
|
|
||||||
this.safetyTimer = setTimeout(() => {
|
this.safetyTimer = setTimeout(() => {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
this.clearSafetyTimer('startSafetyTimer()');
|
this.clearSafetyTimer('startSafetyTimer()');
|
||||||
}, time);
|
}, time);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear our safety timer(s)
|
* Clear our safety timer(s)
|
||||||
* @param {String} from
|
* @param {String} from
|
||||||
*/
|
*/
|
||||||
clearSafetyTimer(from) {
|
clearSafetyTimer = (from) => {
|
||||||
if (!is.nullOrUndefined(this.safetyTimer)) {
|
if (!is.nullOrUndefined(this.safetyTimer)) {
|
||||||
this.player.debug.log(`Safety timer cleared from: ${from}`);
|
this.player.debug.log(`Safety timer cleared from: ${from}`);
|
||||||
|
|
||||||
clearTimeout(this.safetyTimer);
|
clearTimeout(this.safetyTimer);
|
||||||
this.safetyTimer = null;
|
this.safetyTimer = null;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Ads;
|
export default Ads;
|
||||||
|
|||||||
@@ -5,15 +5,15 @@ import is from '../utils/is';
|
|||||||
import { formatTime } from '../utils/time';
|
import { formatTime } from '../utils/time';
|
||||||
|
|
||||||
// Arg: vttDataString example: "WEBVTT\n\n1\n00:00:05.000 --> 00:00:10.000\n1080p-00001.jpg"
|
// Arg: vttDataString example: "WEBVTT\n\n1\n00:00:05.000 --> 00:00:10.000\n1080p-00001.jpg"
|
||||||
const parseVtt = vttDataString => {
|
const parseVtt = (vttDataString) => {
|
||||||
const processedList = [];
|
const processedList = [];
|
||||||
const frames = vttDataString.split(/\r\n\r\n|\n\n|\r\r/);
|
const frames = vttDataString.split(/\r\n\r\n|\n\n|\r\r/);
|
||||||
|
|
||||||
frames.forEach(frame => {
|
frames.forEach((frame) => {
|
||||||
const result = {};
|
const result = {};
|
||||||
const lines = frame.split(/\r\n|\n|\r/);
|
const lines = frame.split(/\r\n|\n|\r/);
|
||||||
|
|
||||||
lines.forEach(line => {
|
lines.forEach((line) => {
|
||||||
if (!is.number(result.startTime)) {
|
if (!is.number(result.startTime)) {
|
||||||
// The line with start and end times on it is the first line of interest
|
// The line with start and end times on it is the first line of interest
|
||||||
const matchTimes = line.match(
|
const matchTimes = line.match(
|
||||||
@@ -63,6 +63,20 @@ const parseVtt = vttDataString => {
|
|||||||
* - This implementation uses multiple separate img elements. Other implementations use background-image on one element. This would be nice and simple, but Firefox and Safari have flickering issues with replacing backgrounds of larger images. It seems that YouTube perhaps only avoids this because they don't have the option for high-res previews (even the fullscreen ones, when mousedown/seeking). Images appear over the top of each other, and previous ones are discarded once the new ones have been rendered
|
* - This implementation uses multiple separate img elements. Other implementations use background-image on one element. This would be nice and simple, but Firefox and Safari have flickering issues with replacing backgrounds of larger images. It seems that YouTube perhaps only avoids this because they don't have the option for high-res previews (even the fullscreen ones, when mousedown/seeking). Images appear over the top of each other, and previous ones are discarded once the new ones have been rendered
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const fitRatio = (ratio, outer) => {
|
||||||
|
const targetRatio = outer.width / outer.height;
|
||||||
|
const result = {};
|
||||||
|
if (ratio > targetRatio) {
|
||||||
|
result.width = outer.width;
|
||||||
|
result.height = (1 / ratio) * outer.width;
|
||||||
|
} else {
|
||||||
|
result.height = outer.height;
|
||||||
|
result.width = ratio * outer.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
class PreviewThumbnails {
|
class PreviewThumbnails {
|
||||||
/**
|
/**
|
||||||
* PreviewThumbnails constructor.
|
* PreviewThumbnails constructor.
|
||||||
@@ -89,7 +103,7 @@ class PreviewThumbnails {
|
|||||||
return this.player.isHTML5 && this.player.isVideo && this.player.config.previewThumbnails.enabled;
|
return this.player.isHTML5 && this.player.isVideo && this.player.config.previewThumbnails.enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
load() {
|
load = () => {
|
||||||
// Toggle the regular seek tooltip
|
// Toggle the regular seek tooltip
|
||||||
if (this.player.elements.display.seekTooltip) {
|
if (this.player.elements.display.seekTooltip) {
|
||||||
this.player.elements.display.seekTooltip.hidden = this.enabled;
|
this.player.elements.display.seekTooltip.hidden = this.enabled;
|
||||||
@@ -112,37 +126,50 @@ class PreviewThumbnails {
|
|||||||
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// Download VTT files and parse them
|
// Download VTT files and parse them
|
||||||
getThumbnails() {
|
getThumbnails = () => {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve) => {
|
||||||
const { src } = this.player.config.previewThumbnails;
|
const { src } = this.player.config.previewThumbnails;
|
||||||
|
|
||||||
if (is.empty(src)) {
|
if (is.empty(src)) {
|
||||||
throw new Error('Missing previewThumbnails.src config attribute');
|
throw new Error('Missing previewThumbnails.src config attribute');
|
||||||
}
|
}
|
||||||
|
|
||||||
// If string, convert into single-element list
|
// Resolve promise
|
||||||
const urls = is.string(src) ? [src] : src;
|
const sortAndResolve = () => {
|
||||||
// Loop through each src URL. Download and process the VTT file, storing the resulting data in this.thumbnails
|
|
||||||
const promises = urls.map(u => this.getThumbnail(u));
|
|
||||||
|
|
||||||
Promise.all(promises).then(() => {
|
|
||||||
// Sort smallest to biggest (e.g., [120p, 480p, 1080p])
|
// Sort smallest to biggest (e.g., [120p, 480p, 1080p])
|
||||||
this.thumbnails.sort((x, y) => x.height - y.height);
|
this.thumbnails.sort((x, y) => x.height - y.height);
|
||||||
|
|
||||||
this.player.debug.log('Preview thumbnails', this.thumbnails);
|
this.player.debug.log('Preview thumbnails', this.thumbnails);
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// Via callback()
|
||||||
|
if (is.function(src)) {
|
||||||
|
src((thumbnails) => {
|
||||||
|
this.thumbnails = thumbnails;
|
||||||
|
sortAndResolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// VTT urls
|
||||||
|
else {
|
||||||
|
// If string, convert into single-element list
|
||||||
|
const urls = is.string(src) ? [src] : src;
|
||||||
|
// Loop through each src URL. Download and process the VTT file, storing the resulting data in this.thumbnails
|
||||||
|
const promises = urls.map((u) => this.getThumbnail(u));
|
||||||
|
// Resolve
|
||||||
|
Promise.all(promises).then(sortAndResolve);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Process individual VTT file
|
// Process individual VTT file
|
||||||
getThumbnail(url) {
|
getThumbnail = (url) => {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve) => {
|
||||||
fetch(url).then(response => {
|
fetch(url).then((response) => {
|
||||||
const thumbnail = {
|
const thumbnail = {
|
||||||
frames: parseVtt(response),
|
frames: parseVtt(response),
|
||||||
height: null,
|
height: null,
|
||||||
@@ -175,9 +202,9 @@ class PreviewThumbnails {
|
|||||||
tempImage.src = thumbnail.urlPrefix + thumbnail.frames[0].text;
|
tempImage.src = thumbnail.urlPrefix + thumbnail.frames[0].text;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
startMove(event) {
|
startMove = (event) => {
|
||||||
if (!this.loaded) {
|
if (!this.loaded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -214,19 +241,28 @@ class PreviewThumbnails {
|
|||||||
|
|
||||||
// Set time text inside image container
|
// Set time text inside image container
|
||||||
this.elements.thumb.time.innerText = formatTime(this.seekTime);
|
this.elements.thumb.time.innerText = formatTime(this.seekTime);
|
||||||
|
|
||||||
|
// Get marker point for time
|
||||||
|
const point = this.player.config.markers?.points?.find(({ time: t }) => t === Math.round(this.seekTime));
|
||||||
|
|
||||||
|
// Append the point label to the tooltip
|
||||||
|
if (point) {
|
||||||
|
// this.elements.thumb.time.innerText.concat('\n');
|
||||||
|
this.elements.thumb.time.insertAdjacentHTML('afterbegin', `${point.label}<br>`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download and show image
|
// Download and show image
|
||||||
this.showImageAtCurrentTime();
|
this.showImageAtCurrentTime();
|
||||||
}
|
};
|
||||||
|
|
||||||
endMove() {
|
endMove = () => {
|
||||||
this.toggleThumbContainer(false, true);
|
this.toggleThumbContainer(false, true);
|
||||||
}
|
};
|
||||||
|
|
||||||
startScrubbing(event) {
|
startScrubbing = (event) => {
|
||||||
// Only act on left mouse button (0), or touch device (event.button is false)
|
// Only act on left mouse button (0), or touch device (event.button does not exist or is false)
|
||||||
if (event.button === false || event.button === 0) {
|
if (is.nullOrUndefined(event.button) || event.button === false || event.button === 0) {
|
||||||
this.mouseDown = true;
|
this.mouseDown = true;
|
||||||
|
|
||||||
// Wait until media has a duration
|
// Wait until media has a duration
|
||||||
@@ -238,9 +274,9 @@ class PreviewThumbnails {
|
|||||||
this.showImageAtCurrentTime();
|
this.showImageAtCurrentTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
endScrubbing() {
|
endScrubbing = () => {
|
||||||
this.mouseDown = false;
|
this.mouseDown = false;
|
||||||
|
|
||||||
// Hide scrubbing preview. But wait until the video has successfully seeked before hiding the scrubbing preview
|
// Hide scrubbing preview. But wait until the video has successfully seeked before hiding the scrubbing preview
|
||||||
@@ -256,12 +292,12 @@ class PreviewThumbnails {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup hooks for Plyr and window events
|
* Setup hooks for Plyr and window events
|
||||||
*/
|
*/
|
||||||
listeners() {
|
listeners = () => {
|
||||||
// Hide thumbnail preview - on mouse click, mouse leave (in listeners.js for now), and video play/seek. All four are required, e.g., for buffering
|
// Hide thumbnail preview - on mouse click, mouse leave (in listeners.js for now), and video play/seek. All four are required, e.g., for buffering
|
||||||
this.player.on('play', () => {
|
this.player.on('play', () => {
|
||||||
this.toggleThumbContainer(false, true);
|
this.toggleThumbContainer(false, true);
|
||||||
@@ -274,12 +310,12 @@ class PreviewThumbnails {
|
|||||||
this.player.on('timeupdate', () => {
|
this.player.on('timeupdate', () => {
|
||||||
this.lastTime = this.player.media.currentTime;
|
this.lastTime = this.player.media.currentTime;
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create HTML elements for image containers
|
* Create HTML elements for image containers
|
||||||
*/
|
*/
|
||||||
render() {
|
render = () => {
|
||||||
// Create HTML element: plyr__preview-thumbnail-container
|
// Create HTML element: plyr__preview-thumbnail-container
|
||||||
this.elements.thumb.container = createElement('div', {
|
this.elements.thumb.container = createElement('div', {
|
||||||
class: this.player.config.classNames.previewThumbnails.thumbContainer,
|
class: this.player.config.classNames.previewThumbnails.thumbContainer,
|
||||||
@@ -299,7 +335,7 @@ class PreviewThumbnails {
|
|||||||
this.elements.thumb.time = createElement('span', {}, '00:00');
|
this.elements.thumb.time = createElement('span', {}, '00:00');
|
||||||
timeContainer.appendChild(this.elements.thumb.time);
|
timeContainer.appendChild(this.elements.thumb.time);
|
||||||
|
|
||||||
this.elements.thumb.container.appendChild(timeContainer);
|
this.elements.thumb.imageContainer.appendChild(timeContainer);
|
||||||
|
|
||||||
// Inject the whole thumb
|
// Inject the whole thumb
|
||||||
if (is.element(this.player.elements.progress)) {
|
if (is.element(this.player.elements.progress)) {
|
||||||
@@ -312,9 +348,18 @@ class PreviewThumbnails {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.player.elements.wrapper.appendChild(this.elements.scrubbing.container);
|
this.player.elements.wrapper.appendChild(this.elements.scrubbing.container);
|
||||||
}
|
};
|
||||||
|
|
||||||
showImageAtCurrentTime() {
|
destroy = () => {
|
||||||
|
if (this.elements.thumb.container) {
|
||||||
|
this.elements.thumb.container.remove();
|
||||||
|
}
|
||||||
|
if (this.elements.scrubbing.container) {
|
||||||
|
this.elements.scrubbing.container.remove();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
showImageAtCurrentTime = () => {
|
||||||
if (this.mouseDown) {
|
if (this.mouseDown) {
|
||||||
this.setScrubbingContainerSize();
|
this.setScrubbingContainerSize();
|
||||||
} else {
|
} else {
|
||||||
@@ -324,7 +369,7 @@ class PreviewThumbnails {
|
|||||||
// Find the desired thumbnail index
|
// Find the desired thumbnail index
|
||||||
// TODO: Handle a video longer than the thumbs where thumbNum is null
|
// TODO: Handle a video longer than the thumbs where thumbNum is null
|
||||||
const thumbNum = this.thumbnails[0].frames.findIndex(
|
const thumbNum = this.thumbnails[0].frames.findIndex(
|
||||||
frame => this.seekTime >= frame.startTime && this.seekTime <= frame.endTime,
|
(frame) => this.seekTime >= frame.startTime && this.seekTime <= frame.endTime,
|
||||||
);
|
);
|
||||||
const hasThumb = thumbNum >= 0;
|
const hasThumb = thumbNum >= 0;
|
||||||
let qualityIndex = 0;
|
let qualityIndex = 0;
|
||||||
@@ -351,10 +396,10 @@ class PreviewThumbnails {
|
|||||||
this.showingThumb = thumbNum;
|
this.showingThumb = thumbNum;
|
||||||
this.loadImage(qualityIndex);
|
this.loadImage(qualityIndex);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// Show the image that's currently specified in this.showingThumb
|
// Show the image that's currently specified in this.showingThumb
|
||||||
loadImage(qualityIndex = 0) {
|
loadImage = (qualityIndex = 0) => {
|
||||||
const thumbNum = this.showingThumb;
|
const thumbNum = this.showingThumb;
|
||||||
const thumbnail = this.thumbnails[qualityIndex];
|
const thumbnail = this.thumbnails[qualityIndex];
|
||||||
const { urlPrefix } = thumbnail;
|
const { urlPrefix } = thumbnail;
|
||||||
@@ -381,8 +426,7 @@ class PreviewThumbnails {
|
|||||||
this.player.debug.log(`Loading image: ${thumbUrl}`);
|
this.player.debug.log(`Loading image: ${thumbUrl}`);
|
||||||
|
|
||||||
// For some reason, passing the named function directly causes it to execute immediately. So I've wrapped it in an anonymous function...
|
// For some reason, passing the named function directly causes it to execute immediately. So I've wrapped it in an anonymous function...
|
||||||
previewImage.onload = () =>
|
previewImage.onload = () => this.showImage(previewImage, frame, qualityIndex, thumbNum, thumbFilename, true);
|
||||||
this.showImage(previewImage, frame, qualityIndex, thumbNum, thumbFilename, true);
|
|
||||||
this.loadingImage = previewImage;
|
this.loadingImage = previewImage;
|
||||||
this.removeOldImages(previewImage);
|
this.removeOldImages(previewImage);
|
||||||
} else {
|
} else {
|
||||||
@@ -391,9 +435,9 @@ class PreviewThumbnails {
|
|||||||
this.currentImageElement.dataset.index = thumbNum;
|
this.currentImageElement.dataset.index = thumbNum;
|
||||||
this.removeOldImages(this.currentImageElement);
|
this.removeOldImages(this.currentImageElement);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
showImage(previewImage, frame, qualityIndex, thumbNum, thumbFilename, newImage = true) {
|
showImage = (previewImage, frame, qualityIndex, thumbNum, thumbFilename, newImage = true) => {
|
||||||
this.player.debug.log(
|
this.player.debug.log(
|
||||||
`Showing thumb: ${thumbFilename}. num: ${thumbNum}. qual: ${qualityIndex}. newimg: ${newImage}`,
|
`Showing thumb: ${thumbFilename}. num: ${thumbNum}. qual: ${qualityIndex}. newimg: ${newImage}`,
|
||||||
);
|
);
|
||||||
@@ -414,12 +458,12 @@ class PreviewThumbnails {
|
|||||||
this.preloadNearby(thumbNum, true)
|
this.preloadNearby(thumbNum, true)
|
||||||
.then(this.preloadNearby(thumbNum, false))
|
.then(this.preloadNearby(thumbNum, false))
|
||||||
.then(this.getHigherQuality(qualityIndex, previewImage, frame, thumbFilename));
|
.then(this.getHigherQuality(qualityIndex, previewImage, frame, thumbFilename));
|
||||||
}
|
};
|
||||||
|
|
||||||
// Remove all preview images that aren't the designated current image
|
// Remove all preview images that aren't the designated current image
|
||||||
removeOldImages(currentImage) {
|
removeOldImages = (currentImage) => {
|
||||||
// Get a list of all images, convert it from a DOM list to an array
|
// Get a list of all images, convert it from a DOM list to an array
|
||||||
Array.from(this.currentImageContainer.children).forEach(image => {
|
Array.from(this.currentImageContainer.children).forEach((image) => {
|
||||||
if (image.tagName.toLowerCase() !== 'img') {
|
if (image.tagName.toLowerCase() !== 'img') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -441,12 +485,12 @@ class PreviewThumbnails {
|
|||||||
}, removeDelay);
|
}, removeDelay);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// Preload images before and after the current one. Only if the user is still hovering/seeking the same frame
|
// Preload images before and after the current one. Only if the user is still hovering/seeking the same frame
|
||||||
// This will only preload the lowest quality
|
// This will only preload the lowest quality
|
||||||
preloadNearby(thumbNum, forward = true) {
|
preloadNearby = (thumbNum, forward = true) => {
|
||||||
return new Promise(resolve => {
|
return new Promise((resolve) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const oldThumbFilename = this.thumbnails[0].frames[thumbNum].text;
|
const oldThumbFilename = this.thumbnails[0].frames[thumbNum].text;
|
||||||
|
|
||||||
@@ -461,7 +505,7 @@ class PreviewThumbnails {
|
|||||||
|
|
||||||
let foundOne = false;
|
let foundOne = false;
|
||||||
|
|
||||||
thumbnailsClone.forEach(frame => {
|
thumbnailsClone.forEach((frame) => {
|
||||||
const newThumbFilename = frame.text;
|
const newThumbFilename = frame.text;
|
||||||
|
|
||||||
if (newThumbFilename !== oldThumbFilename) {
|
if (newThumbFilename !== oldThumbFilename) {
|
||||||
@@ -476,8 +520,7 @@ class PreviewThumbnails {
|
|||||||
previewImage.src = thumbURL;
|
previewImage.src = thumbURL;
|
||||||
previewImage.onload = () => {
|
previewImage.onload = () => {
|
||||||
this.player.debug.log(`Preloaded thumb filename: ${newThumbFilename}`);
|
this.player.debug.log(`Preloaded thumb filename: ${newThumbFilename}`);
|
||||||
if (!this.loadedImages.includes(newThumbFilename))
|
if (!this.loadedImages.includes(newThumbFilename)) this.loadedImages.push(newThumbFilename);
|
||||||
this.loadedImages.push(newThumbFilename);
|
|
||||||
|
|
||||||
// We don't resolve until the thumb is loaded
|
// We don't resolve until the thumb is loaded
|
||||||
resolve();
|
resolve();
|
||||||
@@ -493,10 +536,10 @@ class PreviewThumbnails {
|
|||||||
}
|
}
|
||||||
}, 300);
|
}, 300);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// If user has been hovering current image for half a second, look for a higher quality one
|
// If user has been hovering current image for half a second, look for a higher quality one
|
||||||
getHigherQuality(currentQualityIndex, previewImage, frame, thumbFilename) {
|
getHigherQuality = (currentQualityIndex, previewImage, frame, thumbFilename) => {
|
||||||
if (currentQualityIndex < this.thumbnails.length - 1) {
|
if (currentQualityIndex < this.thumbnails.length - 1) {
|
||||||
// Only use the higher quality version if it's going to look any better - if the current thumb is of a lower pixel density than the thumbnail container
|
// Only use the higher quality version if it's going to look any better - if the current thumb is of a lower pixel density than the thumbnail container
|
||||||
let previewImageHeight = previewImage.naturalHeight;
|
let previewImageHeight = previewImage.naturalHeight;
|
||||||
@@ -516,7 +559,7 @@ class PreviewThumbnails {
|
|||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
get currentImageContainer() {
|
get currentImageContainer() {
|
||||||
if (this.mouseDown) {
|
if (this.mouseDown) {
|
||||||
@@ -540,8 +583,16 @@ class PreviewThumbnails {
|
|||||||
|
|
||||||
get thumbContainerHeight() {
|
get thumbContainerHeight() {
|
||||||
if (this.mouseDown) {
|
if (this.mouseDown) {
|
||||||
// Can't use media.clientHeight - HTML5 video goes big and does black bars above and below
|
const { height } = fitRatio(this.thumbAspectRatio, {
|
||||||
return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio);
|
width: this.player.media.clientWidth,
|
||||||
|
height: this.player.media.clientHeight,
|
||||||
|
});
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If css is used this needs to return the css height for sprites to work (see setImageSizeAndOffset)
|
||||||
|
if (this.sizeSpecifiedInCSS) {
|
||||||
|
return this.elements.thumb.imageContainer.clientHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio / 4);
|
return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio / 4);
|
||||||
@@ -563,7 +614,7 @@ class PreviewThumbnails {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleThumbContainer(toggle = false, clearShowing = false) {
|
toggleThumbContainer = (toggle = false, clearShowing = false) => {
|
||||||
const className = this.player.config.classNames.previewThumbnails.thumbContainerShown;
|
const className = this.player.config.classNames.previewThumbnails.thumbContainerShown;
|
||||||
this.elements.thumb.container.classList.toggle(className, toggle);
|
this.elements.thumb.container.classList.toggle(className, toggle);
|
||||||
|
|
||||||
@@ -571,9 +622,9 @@ class PreviewThumbnails {
|
|||||||
this.showingThumb = null;
|
this.showingThumb = null;
|
||||||
this.showingThumbFilename = null;
|
this.showingThumbFilename = null;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
toggleScrubbingContainer(toggle = false) {
|
toggleScrubbingContainer = (toggle = false) => {
|
||||||
const className = this.player.config.classNames.previewThumbnails.scrubbingContainerShown;
|
const className = this.player.config.classNames.previewThumbnails.scrubbingContainerShown;
|
||||||
this.elements.scrubbing.container.classList.toggle(className, toggle);
|
this.elements.scrubbing.container.classList.toggle(className, toggle);
|
||||||
|
|
||||||
@@ -581,27 +632,39 @@ class PreviewThumbnails {
|
|||||||
this.showingThumb = null;
|
this.showingThumb = null;
|
||||||
this.showingThumbFilename = null;
|
this.showingThumbFilename = null;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
determineContainerAutoSizing() {
|
determineContainerAutoSizing = () => {
|
||||||
if (this.elements.thumb.imageContainer.clientHeight > 20) {
|
if (this.elements.thumb.imageContainer.clientHeight > 20 || this.elements.thumb.imageContainer.clientWidth > 20) {
|
||||||
// This will prevent auto sizing in this.setThumbContainerSizeAndPos()
|
// This will prevent auto sizing in this.setThumbContainerSizeAndPos()
|
||||||
this.sizeSpecifiedInCSS = true;
|
this.sizeSpecifiedInCSS = true;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// Set the size to be about a quarter of the size of video. Unless option dynamicSize === false, in which case it needs to be set in CSS
|
// Set the size to be about a quarter of the size of video. Unless option dynamicSize === false, in which case it needs to be set in CSS
|
||||||
setThumbContainerSizeAndPos() {
|
setThumbContainerSizeAndPos = () => {
|
||||||
if (!this.sizeSpecifiedInCSS) {
|
if (!this.sizeSpecifiedInCSS) {
|
||||||
const thumbWidth = Math.floor(this.thumbContainerHeight * this.thumbAspectRatio);
|
const thumbWidth = Math.floor(this.thumbContainerHeight * this.thumbAspectRatio);
|
||||||
this.elements.thumb.imageContainer.style.height = `${this.thumbContainerHeight}px`;
|
this.elements.thumb.imageContainer.style.height = `${this.thumbContainerHeight}px`;
|
||||||
this.elements.thumb.imageContainer.style.width = `${thumbWidth}px`;
|
this.elements.thumb.imageContainer.style.width = `${thumbWidth}px`;
|
||||||
|
} else if (
|
||||||
|
this.elements.thumb.imageContainer.clientHeight > 20 &&
|
||||||
|
this.elements.thumb.imageContainer.clientWidth < 20
|
||||||
|
) {
|
||||||
|
const thumbWidth = Math.floor(this.elements.thumb.imageContainer.clientHeight * this.thumbAspectRatio);
|
||||||
|
this.elements.thumb.imageContainer.style.width = `${thumbWidth}px`;
|
||||||
|
} else if (
|
||||||
|
this.elements.thumb.imageContainer.clientHeight < 20 &&
|
||||||
|
this.elements.thumb.imageContainer.clientWidth > 20
|
||||||
|
) {
|
||||||
|
const thumbHeight = Math.floor(this.elements.thumb.imageContainer.clientWidth / this.thumbAspectRatio);
|
||||||
|
this.elements.thumb.imageContainer.style.height = `${thumbHeight}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setThumbContainerPos();
|
this.setThumbContainerPos();
|
||||||
}
|
};
|
||||||
|
|
||||||
setThumbContainerPos() {
|
setThumbContainerPos = () => {
|
||||||
const seekbarRect = this.player.elements.progress.getBoundingClientRect();
|
const seekbarRect = this.player.elements.progress.getBoundingClientRect();
|
||||||
const plyrRect = this.player.elements.container.getBoundingClientRect();
|
const plyrRect = this.player.elements.container.getBoundingClientRect();
|
||||||
const { container } = this.elements.thumb;
|
const { container } = this.elements.thumb;
|
||||||
@@ -620,17 +683,20 @@ class PreviewThumbnails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.style.left = `${previewPos}px`;
|
container.style.left = `${previewPos}px`;
|
||||||
}
|
};
|
||||||
|
|
||||||
// Can't use 100% width, in case the video is a different aspect ratio to the video container
|
// Can't use 100% width, in case the video is a different aspect ratio to the video container
|
||||||
setScrubbingContainerSize() {
|
setScrubbingContainerSize = () => {
|
||||||
this.elements.scrubbing.container.style.width = `${this.player.media.clientWidth}px`;
|
const { width, height } = fitRatio(this.thumbAspectRatio, {
|
||||||
// Can't use media.clientHeight - html5 video goes big and does black bars above and below
|
width: this.player.media.clientWidth,
|
||||||
this.elements.scrubbing.container.style.height = `${this.player.media.clientWidth / this.thumbAspectRatio}px`;
|
height: this.player.media.clientHeight,
|
||||||
}
|
});
|
||||||
|
this.elements.scrubbing.container.style.width = `${width}px`;
|
||||||
|
this.elements.scrubbing.container.style.height = `${height}px`;
|
||||||
|
};
|
||||||
|
|
||||||
// Sprites need to be offset to the correct location
|
// Sprites need to be offset to the correct location
|
||||||
setImageSizeAndOffset(previewImage, frame) {
|
setImageSizeAndOffset = (previewImage, frame) => {
|
||||||
if (!this.usingSprites) {
|
if (!this.usingSprites) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -639,14 +705,14 @@ class PreviewThumbnails {
|
|||||||
const multiplier = this.thumbContainerHeight / frame.h;
|
const multiplier = this.thumbContainerHeight / frame.h;
|
||||||
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
previewImage.style.height = `${Math.floor(previewImage.naturalHeight * multiplier)}px`;
|
previewImage.style.height = `${previewImage.naturalHeight * multiplier}px`;
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
previewImage.style.width = `${Math.floor(previewImage.naturalWidth * multiplier)}px`;
|
previewImage.style.width = `${previewImage.naturalWidth * multiplier}px`;
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
previewImage.style.left = `-${frame.x * multiplier}px`;
|
previewImage.style.left = `-${frame.x * multiplier}px`;
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
previewImage.style.top = `-${frame.y * multiplier}px`;
|
previewImage.style.top = `-${frame.y * multiplier}px`;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PreviewThumbnails;
|
export default PreviewThumbnails;
|
||||||
|
|||||||
+105
-59
@@ -10,9 +10,8 @@ import { triggerEvent } from '../utils/events';
|
|||||||
import fetch from '../utils/fetch';
|
import fetch from '../utils/fetch';
|
||||||
import is from '../utils/is';
|
import is from '../utils/is';
|
||||||
import loadScript from '../utils/load-script';
|
import loadScript from '../utils/load-script';
|
||||||
import { extend } from '../utils/objects';
|
|
||||||
import { format, stripHTML } from '../utils/strings';
|
import { format, stripHTML } from '../utils/strings';
|
||||||
import { setAspectRatio } from '../utils/style';
|
import { roundAspectRatio, setAspectRatio } from '../utils/style';
|
||||||
import { buildUrlParams } from '../utils/urls';
|
import { buildUrlParams } from '../utils/urls';
|
||||||
|
|
||||||
// Parse Vimeo ID from URL
|
// Parse Vimeo ID from URL
|
||||||
@@ -29,6 +28,21 @@ function parseId(url) {
|
|||||||
return url.match(regex) ? RegExp.$2 : url;
|
return url.match(regex) ? RegExp.$2 : url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to extract a hash for private videos from the URL
|
||||||
|
function parseHash(url) {
|
||||||
|
/* This regex matches a hexadecimal hash if given in any of these forms:
|
||||||
|
* - [https://player.]vimeo.com/video/{id}/{hash}[?params]
|
||||||
|
* - [https://player.]vimeo.com/video/{id}?h={hash}[¶ms]
|
||||||
|
* - [https://player.]vimeo.com/video/{id}?[params]&h={hash}
|
||||||
|
* - video/{id}/{hash}
|
||||||
|
* If matched, the hash is available in capture group 4
|
||||||
|
*/
|
||||||
|
const regex = /^.*(vimeo.com\/|video\/)(\d+)(\?.*&*h=|\/)+([\d,a-f]+)/;
|
||||||
|
const found = url.match(regex);
|
||||||
|
|
||||||
|
return found && found.length === 5 ? found[4] : null;
|
||||||
|
}
|
||||||
|
|
||||||
// Set playback state and trigger change (only on actual change)
|
// Set playback state and trigger change (only on actual change)
|
||||||
function assurePlaybackState(play) {
|
function assurePlaybackState(play) {
|
||||||
if (play && !this.embed.hasPlayed) {
|
if (play && !this.embed.hasPlayed) {
|
||||||
@@ -42,23 +56,28 @@ function assurePlaybackState(play) {
|
|||||||
|
|
||||||
const vimeo = {
|
const vimeo = {
|
||||||
setup() {
|
setup() {
|
||||||
|
const player = this;
|
||||||
|
|
||||||
// Add embed class for responsive
|
// Add embed class for responsive
|
||||||
toggleClass(this.elements.wrapper, this.config.classNames.embed, true);
|
toggleClass(player.elements.wrapper, player.config.classNames.embed, true);
|
||||||
|
|
||||||
|
// Set speed options from config
|
||||||
|
player.options.speed = player.config.speed.options;
|
||||||
|
|
||||||
// Set intial ratio
|
// Set intial ratio
|
||||||
setAspectRatio.call(this);
|
setAspectRatio.call(player);
|
||||||
|
|
||||||
// Load the SDK if not already
|
// Load the SDK if not already
|
||||||
if (!is.object(window.Vimeo)) {
|
if (!is.object(window.Vimeo)) {
|
||||||
loadScript(this.config.urls.vimeo.sdk)
|
loadScript(player.config.urls.vimeo.sdk)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
vimeo.ready.call(this);
|
vimeo.ready.call(player);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
this.debug.warn('Vimeo SDK (player.js) failed to load', error);
|
player.debug.warn('Vimeo SDK (player.js) failed to load', error);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
vimeo.ready.call(this);
|
vimeo.ready.call(player);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -66,29 +85,39 @@ const vimeo = {
|
|||||||
ready() {
|
ready() {
|
||||||
const player = this;
|
const player = this;
|
||||||
const config = player.config.vimeo;
|
const config = player.config.vimeo;
|
||||||
|
const { premium, referrerPolicy, ...frameParams } = config;
|
||||||
|
// Get the source URL or ID
|
||||||
|
let source = player.media.getAttribute('src');
|
||||||
|
let hash = '';
|
||||||
|
// Get from <div> if needed
|
||||||
|
if (is.empty(source)) {
|
||||||
|
source = player.media.getAttribute(player.config.attributes.embed.id);
|
||||||
|
// hash can also be set as attribute on the <div>
|
||||||
|
hash = player.media.getAttribute(player.config.attributes.embed.hash);
|
||||||
|
} else {
|
||||||
|
hash = parseHash(source);
|
||||||
|
}
|
||||||
|
const hashParam = hash ? { h: hash } : {};
|
||||||
|
|
||||||
|
// If the owner has a pro or premium account then we can hide controls etc
|
||||||
|
if (premium) {
|
||||||
|
Object.assign(frameParams, {
|
||||||
|
controls: false,
|
||||||
|
sidedock: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Get Vimeo params for the iframe
|
// Get Vimeo params for the iframe
|
||||||
const params = buildUrlParams(
|
const params = buildUrlParams({
|
||||||
extend(
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
loop: player.config.loop.active,
|
loop: player.config.loop.active,
|
||||||
autoplay: player.autoplay,
|
autoplay: player.autoplay,
|
||||||
muted: player.muted,
|
muted: player.muted,
|
||||||
gesture: 'media',
|
gesture: 'media',
|
||||||
playsinline: !this.config.fullscreen.iosNative,
|
playsinline: !this.config.fullscreen.iosNative,
|
||||||
},
|
// hash has to be added to iframe-URL
|
||||||
config,
|
...hashParam,
|
||||||
),
|
...frameParams,
|
||||||
);
|
});
|
||||||
|
|
||||||
// Get the source URL or ID
|
|
||||||
let source = player.media.getAttribute('src');
|
|
||||||
|
|
||||||
// Get from <div> if needed
|
|
||||||
if (is.empty(source)) {
|
|
||||||
source = player.media.getAttribute(player.config.attributes.embed.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
const id = parseId(source);
|
const id = parseId(source);
|
||||||
// Build an iframe
|
// Build an iframe
|
||||||
@@ -96,31 +125,40 @@ const vimeo = {
|
|||||||
const src = format(player.config.urls.vimeo.iframe, id, params);
|
const src = format(player.config.urls.vimeo.iframe, id, params);
|
||||||
iframe.setAttribute('src', src);
|
iframe.setAttribute('src', src);
|
||||||
iframe.setAttribute('allowfullscreen', '');
|
iframe.setAttribute('allowfullscreen', '');
|
||||||
iframe.setAttribute('allowtransparency', '');
|
iframe.setAttribute(
|
||||||
iframe.setAttribute('allow', 'autoplay');
|
'allow',
|
||||||
|
['autoplay', 'fullscreen', 'picture-in-picture', 'encrypted-media', 'accelerometer', 'gyroscope'].join('; '),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Set the referrer policy if required
|
||||||
|
if (!is.empty(referrerPolicy)) {
|
||||||
|
iframe.setAttribute('referrerPolicy', referrerPolicy);
|
||||||
|
}
|
||||||
|
|
||||||
// Get poster, if already set
|
|
||||||
const { poster } = player;
|
|
||||||
// Inject the package
|
// Inject the package
|
||||||
const wrapper = createElement('div', { poster, class: player.config.classNames.embedContainer });
|
if (premium || !config.customControls) {
|
||||||
|
iframe.setAttribute('data-poster', player.poster);
|
||||||
|
player.media = replaceElement(iframe, player.media);
|
||||||
|
} else {
|
||||||
|
const wrapper = createElement('div', {
|
||||||
|
class: player.config.classNames.embedContainer,
|
||||||
|
'data-poster': player.poster,
|
||||||
|
});
|
||||||
wrapper.appendChild(iframe);
|
wrapper.appendChild(iframe);
|
||||||
player.media = replaceElement(wrapper, player.media);
|
player.media = replaceElement(wrapper, player.media);
|
||||||
|
}
|
||||||
|
|
||||||
// Get poster image
|
// Get poster image
|
||||||
fetch(format(player.config.urls.vimeo.api, id), 'json').then(response => {
|
if (!config.customControls) {
|
||||||
if (is.empty(response)) {
|
fetch(format(player.config.urls.vimeo.api, src)).then((response) => {
|
||||||
|
if (is.empty(response) || !response.thumbnail_url) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the URL for thumbnail
|
|
||||||
const url = new URL(response[0].thumbnail_large);
|
|
||||||
|
|
||||||
// Get original image
|
|
||||||
url.pathname = `${url.pathname.split('_')[0]}.jpg`;
|
|
||||||
|
|
||||||
// Set and show poster
|
// Set and show poster
|
||||||
ui.setPoster.call(player, url.href).catch(() => {});
|
ui.setPoster.call(player, response.thumbnail_url).catch(() => {});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Setup instance
|
// Setup instance
|
||||||
// https://github.com/vimeo/player.js
|
// https://github.com/vimeo/player.js
|
||||||
@@ -197,11 +235,9 @@ const vimeo = {
|
|||||||
speed = input;
|
speed = input;
|
||||||
triggerEvent.call(player, player.media, 'ratechange');
|
triggerEvent.call(player, player.media, 'ratechange');
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(() => {
|
||||||
// Hide menu item (and menu if empty)
|
// Cannot set Playback Rate, Video is probably not on Pro account
|
||||||
if (error.name === 'Error') {
|
player.options.speed = [1];
|
||||||
controls.setSpeedMenu.call(player, []);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -255,11 +291,11 @@ const vimeo = {
|
|||||||
let currentSrc;
|
let currentSrc;
|
||||||
player.embed
|
player.embed
|
||||||
.getVideoUrl()
|
.getVideoUrl()
|
||||||
.then(value => {
|
.then((value) => {
|
||||||
currentSrc = value;
|
currentSrc = value;
|
||||||
controls.setDownloadUrl.call(player);
|
controls.setDownloadUrl.call(player);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
this.debug.warn(error);
|
this.debug.warn(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -277,49 +313,49 @@ const vimeo = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Set aspect ratio based on video size
|
// Set aspect ratio based on video size
|
||||||
Promise.all([player.embed.getVideoWidth(), player.embed.getVideoHeight()]).then(dimensions => {
|
Promise.all([player.embed.getVideoWidth(), player.embed.getVideoHeight()]).then((dimensions) => {
|
||||||
const [width, height] = dimensions;
|
const [width, height] = dimensions;
|
||||||
player.embed.ratio = [width, height];
|
player.embed.ratio = roundAspectRatio(width, height);
|
||||||
setAspectRatio.call(this);
|
setAspectRatio.call(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set autopause
|
// Set autopause
|
||||||
player.embed.setAutopause(player.config.autopause).then(state => {
|
player.embed.setAutopause(player.config.autopause).then((state) => {
|
||||||
player.config.autopause = state;
|
player.config.autopause = state;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get title
|
// Get title
|
||||||
player.embed.getVideoTitle().then(title => {
|
player.embed.getVideoTitle().then((title) => {
|
||||||
player.config.title = title;
|
player.config.title = title;
|
||||||
ui.setTitle.call(this);
|
ui.setTitle.call(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get current time
|
// Get current time
|
||||||
player.embed.getCurrentTime().then(value => {
|
player.embed.getCurrentTime().then((value) => {
|
||||||
currentTime = value;
|
currentTime = value;
|
||||||
triggerEvent.call(player, player.media, 'timeupdate');
|
triggerEvent.call(player, player.media, 'timeupdate');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get duration
|
// Get duration
|
||||||
player.embed.getDuration().then(value => {
|
player.embed.getDuration().then((value) => {
|
||||||
player.media.duration = value;
|
player.media.duration = value;
|
||||||
triggerEvent.call(player, player.media, 'durationchange');
|
triggerEvent.call(player, player.media, 'durationchange');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get captions
|
// Get captions
|
||||||
player.embed.getTextTracks().then(tracks => {
|
player.embed.getTextTracks().then((tracks) => {
|
||||||
player.media.textTracks = tracks;
|
player.media.textTracks = tracks;
|
||||||
captions.setup.call(player);
|
captions.setup.call(player);
|
||||||
});
|
});
|
||||||
|
|
||||||
player.embed.on('cuechange', ({ cues = [] }) => {
|
player.embed.on('cuechange', ({ cues = [] }) => {
|
||||||
const strippedCues = cues.map(cue => stripHTML(cue.text));
|
const strippedCues = cues.map((cue) => stripHTML(cue.text));
|
||||||
captions.updateCues.call(player, strippedCues);
|
captions.updateCues.call(player, strippedCues);
|
||||||
});
|
});
|
||||||
|
|
||||||
player.embed.on('loaded', () => {
|
player.embed.on('loaded', () => {
|
||||||
// Assure state and events are updated on autoplay
|
// Assure state and events are updated on autoplay
|
||||||
player.embed.getPaused().then(paused => {
|
player.embed.getPaused().then((paused) => {
|
||||||
assurePlaybackState.call(player, !paused);
|
assurePlaybackState.call(player, !paused);
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
triggerEvent.call(player, player.media, 'playing');
|
triggerEvent.call(player, player.media, 'playing');
|
||||||
@@ -335,6 +371,14 @@ const vimeo = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
player.embed.on('bufferstart', () => {
|
||||||
|
triggerEvent.call(player, player.media, 'waiting');
|
||||||
|
});
|
||||||
|
|
||||||
|
player.embed.on('bufferend', () => {
|
||||||
|
triggerEvent.call(player, player.media, 'playing');
|
||||||
|
});
|
||||||
|
|
||||||
player.embed.on('play', () => {
|
player.embed.on('play', () => {
|
||||||
assurePlaybackState.call(player, true);
|
assurePlaybackState.call(player, true);
|
||||||
triggerEvent.call(player, player.media, 'playing');
|
triggerEvent.call(player, player.media, 'playing');
|
||||||
@@ -344,13 +388,13 @@ const vimeo = {
|
|||||||
assurePlaybackState.call(player, false);
|
assurePlaybackState.call(player, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
player.embed.on('timeupdate', data => {
|
player.embed.on('timeupdate', (data) => {
|
||||||
player.media.seeking = false;
|
player.media.seeking = false;
|
||||||
currentTime = data.seconds;
|
currentTime = data.seconds;
|
||||||
triggerEvent.call(player, player.media, 'timeupdate');
|
triggerEvent.call(player, player.media, 'timeupdate');
|
||||||
});
|
});
|
||||||
|
|
||||||
player.embed.on('progress', data => {
|
player.embed.on('progress', (data) => {
|
||||||
player.media.buffered = data.percent;
|
player.media.buffered = data.percent;
|
||||||
triggerEvent.call(player, player.media, 'progress');
|
triggerEvent.call(player, player.media, 'progress');
|
||||||
|
|
||||||
@@ -361,7 +405,7 @@ const vimeo = {
|
|||||||
|
|
||||||
// Get duration as if we do it before load, it gives an incorrect value
|
// Get duration as if we do it before load, it gives an incorrect value
|
||||||
// https://github.com/sampotts/plyr/issues/891
|
// https://github.com/sampotts/plyr/issues/891
|
||||||
player.embed.getDuration().then(value => {
|
player.embed.getDuration().then((value) => {
|
||||||
if (value !== player.media.duration) {
|
if (value !== player.media.duration) {
|
||||||
player.media.duration = value;
|
player.media.duration = value;
|
||||||
triggerEvent.call(player, player.media, 'durationchange');
|
triggerEvent.call(player, player.media, 'durationchange');
|
||||||
@@ -379,13 +423,15 @@ const vimeo = {
|
|||||||
triggerEvent.call(player, player.media, 'ended');
|
triggerEvent.call(player, player.media, 'ended');
|
||||||
});
|
});
|
||||||
|
|
||||||
player.embed.on('error', detail => {
|
player.embed.on('error', (detail) => {
|
||||||
player.media.error = detail;
|
player.media.error = detail;
|
||||||
triggerEvent.call(player, player.media, 'error');
|
triggerEvent.call(player, player.media, 'error');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Rebuild UI
|
// Rebuild UI
|
||||||
|
if (config.customControls) {
|
||||||
setTimeout(() => ui.build.call(player), 0);
|
setTimeout(() => ui.build.call(player), 0);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+37
-22
@@ -11,7 +11,7 @@ import loadImage from '../utils/load-image';
|
|||||||
import loadScript from '../utils/load-script';
|
import loadScript from '../utils/load-script';
|
||||||
import { extend } from '../utils/objects';
|
import { extend } from '../utils/objects';
|
||||||
import { format, generateId } from '../utils/strings';
|
import { format, generateId } from '../utils/strings';
|
||||||
import { setAspectRatio } from '../utils/style';
|
import { roundAspectRatio, setAspectRatio } from '../utils/style';
|
||||||
|
|
||||||
// Parse YouTube ID from URL
|
// Parse YouTube ID from URL
|
||||||
function parseId(url) {
|
function parseId(url) {
|
||||||
@@ -70,7 +70,7 @@ const youtube = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Load the SDK
|
// Load the SDK
|
||||||
loadScript(this.config.urls.youtube.sdk).catch(error => {
|
loadScript(this.config.urls.youtube.sdk).catch((error) => {
|
||||||
this.debug.warn('YouTube API failed to load', error);
|
this.debug.warn('YouTube API failed to load', error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ const youtube = {
|
|||||||
const url = format(this.config.urls.youtube.api, videoId);
|
const url = format(this.config.urls.youtube.api, videoId);
|
||||||
|
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then(data => {
|
.then((data) => {
|
||||||
if (is.object(data)) {
|
if (is.object(data)) {
|
||||||
const { title, height, width } = data;
|
const { title, height, width } = data;
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ const youtube = {
|
|||||||
ui.setTitle.call(this);
|
ui.setTitle.call(this);
|
||||||
|
|
||||||
// Set aspect ratio
|
// Set aspect ratio
|
||||||
this.embed.ratio = [width, height];
|
this.embed.ratio = roundAspectRatio(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
setAspectRatio.call(this);
|
setAspectRatio.call(this);
|
||||||
@@ -104,6 +104,7 @@ const youtube = {
|
|||||||
// API ready
|
// API ready
|
||||||
ready() {
|
ready() {
|
||||||
const player = this;
|
const player = this;
|
||||||
|
const config = player.config.youtube;
|
||||||
// Ignore already setup (race condition)
|
// Ignore already setup (race condition)
|
||||||
const currentId = player.media && player.media.getAttribute('id');
|
const currentId = player.media && player.media.getAttribute('id');
|
||||||
if (!is.empty(currentId) && currentId.startsWith('youtube-')) {
|
if (!is.empty(currentId) && currentId.startsWith('youtube-')) {
|
||||||
@@ -121,43 +122,46 @@ const youtube = {
|
|||||||
// Replace the <iframe> with a <div> due to YouTube API issues
|
// Replace the <iframe> with a <div> due to YouTube API issues
|
||||||
const videoId = parseId(source);
|
const videoId = parseId(source);
|
||||||
const id = generateId(player.provider);
|
const id = generateId(player.provider);
|
||||||
// Get poster, if already set
|
|
||||||
const { poster } = player;
|
|
||||||
// Replace media element
|
// Replace media element
|
||||||
const container = createElement('div', { id, poster });
|
const container = createElement('div', { id, 'data-poster': config.customControls ? player.poster : undefined });
|
||||||
player.media = replaceElement(container, player.media);
|
player.media = replaceElement(container, player.media);
|
||||||
|
|
||||||
// Id to poster wrapper
|
// Only load the poster when using custom controls
|
||||||
const posterSrc = s => `https://i.ytimg.com/vi/${videoId}/${s}default.jpg`;
|
if (config.customControls) {
|
||||||
|
const posterSrc = (s) => `https://i.ytimg.com/vi/${videoId}/${s}default.jpg`;
|
||||||
|
|
||||||
// Check thumbnail images in order of quality, but reject fallback thumbnails (120px wide)
|
// Check thumbnail images in order of quality, but reject fallback thumbnails (120px wide)
|
||||||
loadImage(posterSrc('maxres'), 121) // Higest quality and unpadded
|
loadImage(posterSrc('maxres'), 121) // Higest quality and unpadded
|
||||||
.catch(() => loadImage(posterSrc('sd'), 121)) // 480p padded 4:3
|
.catch(() => loadImage(posterSrc('sd'), 121)) // 480p padded 4:3
|
||||||
.catch(() => loadImage(posterSrc('hq'))) // 360p padded 4:3. Always exists
|
.catch(() => loadImage(posterSrc('hq'))) // 360p padded 4:3. Always exists
|
||||||
.then(image => ui.setPoster.call(player, image.src))
|
.then((image) => ui.setPoster.call(player, image.src))
|
||||||
.then(src => {
|
.then((src) => {
|
||||||
// If the image is padded, use background-size "cover" instead (like youtube does too with their posters)
|
// If the image is padded, use background-size "cover" instead (like youtube does too with their posters)
|
||||||
if (!src.includes('maxres')) {
|
if (!src.includes('maxres')) {
|
||||||
player.elements.poster.style.backgroundSize = 'cover';
|
player.elements.poster.style.backgroundSize = 'cover';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
|
}
|
||||||
const config = player.config.youtube;
|
|
||||||
|
|
||||||
// Setup instance
|
// Setup instance
|
||||||
// https://developers.google.com/youtube/iframe_api_reference
|
// https://developers.google.com/youtube/iframe_api_reference
|
||||||
player.embed = new window.YT.Player(id, {
|
player.embed = new window.YT.Player(player.media, {
|
||||||
videoId,
|
videoId,
|
||||||
host: getHost(config),
|
host: getHost(config),
|
||||||
playerVars: extend(
|
playerVars: extend(
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
autoplay: player.config.autoplay ? 1 : 0, // Autoplay
|
// Autoplay
|
||||||
hl: player.config.hl, // iframe interface language
|
autoplay: player.config.autoplay ? 1 : 0,
|
||||||
controls: player.supported.ui ? 0 : 1, // Only show controls if not fully supported
|
// iframe interface language
|
||||||
disablekb: 1, // Disable keyboard as we handle it
|
hl: player.config.hl,
|
||||||
playsinline: !player.config.fullscreen.iosNative ? 1 : 0, // Allow iOS inline playback
|
// Only show controls if not fully supported or opted out
|
||||||
|
controls: player.supported.ui && config.customControls ? 0 : 1,
|
||||||
|
// Disable keyboard as we handle it
|
||||||
|
disablekb: 1,
|
||||||
|
// Allow iOS inline playback
|
||||||
|
playsinline: !player.config.fullscreen.iosNative ? 1 : 0,
|
||||||
// Captions are flaky on YouTube
|
// Captions are flaky on YouTube
|
||||||
cc_load_policy: player.captions.active ? 1 : 0,
|
cc_load_policy: player.captions.active ? 1 : 0,
|
||||||
cc_lang_pref: player.config.captions.language,
|
cc_lang_pref: player.config.captions.language,
|
||||||
@@ -278,6 +282,7 @@ const youtube = {
|
|||||||
const toggle = is.boolean(input) ? input : muted;
|
const toggle = is.boolean(input) ? input : muted;
|
||||||
muted = toggle;
|
muted = toggle;
|
||||||
instance[toggle ? 'mute' : 'unMute']();
|
instance[toggle ? 'mute' : 'unMute']();
|
||||||
|
instance.setVolume(volume * 100);
|
||||||
triggerEvent.call(player, player.media, 'volumechange');
|
triggerEvent.call(player, player.media, 'volumechange');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -297,10 +302,12 @@ const youtube = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Get available speeds
|
// Get available speeds
|
||||||
player.options.speed = instance.getAvailablePlaybackRates();
|
const speeds = instance.getAvailablePlaybackRates();
|
||||||
|
// Filter based on config
|
||||||
|
player.options.speed = speeds.filter((s) => player.config.speed.options.includes(s));
|
||||||
|
|
||||||
// Set the tabindex to avoid focus entering iframe
|
// Set the tabindex to avoid focus entering iframe
|
||||||
if (player.supported.ui) {
|
if (player.supported.ui && config.customControls) {
|
||||||
player.media.setAttribute('tabindex', -1);
|
player.media.setAttribute('tabindex', -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,7 +340,9 @@ const youtube = {
|
|||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
// Rebuild UI
|
// Rebuild UI
|
||||||
|
if (config.customControls) {
|
||||||
setTimeout(() => ui.build.call(player), 50);
|
setTimeout(() => ui.build.call(player), 50);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onStateChange(event) {
|
onStateChange(event) {
|
||||||
// Get the instance
|
// Get the instance
|
||||||
@@ -384,7 +393,7 @@ const youtube = {
|
|||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// Restore paused state (YouTube starts playing on seek if the video hasn't been played yet)
|
// Restore paused state (YouTube starts playing on seek if the video hasn't been played yet)
|
||||||
if (!player.config.autoplay && player.media.paused && !player.embed.hasPlayed) {
|
if (config.customControls && !player.config.autoplay && player.media.paused && !player.embed.hasPlayed) {
|
||||||
player.media.pause();
|
player.media.pause();
|
||||||
} else {
|
} else {
|
||||||
assurePlaybackState.call(player, true);
|
assurePlaybackState.call(player, true);
|
||||||
@@ -416,6 +425,12 @@ const youtube = {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
// Trigger waiting event to add loading classes to container as the video buffers.
|
||||||
|
triggerEvent.call(player, player.media, 'waiting');
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+711
@@ -0,0 +1,711 @@
|
|||||||
|
// Type definitions for plyr 3.5
|
||||||
|
// Project: https://plyr.io
|
||||||
|
// Definitions by: ondratra <https://github.com/ondratra>
|
||||||
|
// TypeScript Version: 3.0
|
||||||
|
|
||||||
|
export = Plyr;
|
||||||
|
export as namespace Plyr;
|
||||||
|
|
||||||
|
declare class Plyr {
|
||||||
|
/**
|
||||||
|
* Setup a new instance
|
||||||
|
*/
|
||||||
|
static setup(targets: NodeList | HTMLElement | HTMLElement[] | string, options?: Plyr.Options): Plyr[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for support
|
||||||
|
* @param mediaType
|
||||||
|
* @param provider
|
||||||
|
* @param playsInline Whether the player has the playsinline attribute (only applicable to iOS 10+)
|
||||||
|
*/
|
||||||
|
static supported(mediaType?: Plyr.MediaType, provider?: Plyr.Provider, playsInline?: boolean): Plyr.Support;
|
||||||
|
|
||||||
|
constructor(targets: NodeList | HTMLElement | HTMLElement[] | string, options?: Plyr.Options);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the current player is HTML5.
|
||||||
|
*/
|
||||||
|
readonly isHTML5: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the current player is an embedded player.
|
||||||
|
*/
|
||||||
|
readonly isEmbed: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the current player is playing.
|
||||||
|
*/
|
||||||
|
readonly playing: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the current player is paused.
|
||||||
|
*/
|
||||||
|
readonly paused: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the current player is stopped.
|
||||||
|
*/
|
||||||
|
readonly stopped: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the current player has finished playback.
|
||||||
|
*/
|
||||||
|
readonly ended: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a float between 0 and 1 indicating how much of the media is buffered
|
||||||
|
*/
|
||||||
|
readonly buffered: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the currentTime for the player. The setter accepts a float in seconds.
|
||||||
|
*/
|
||||||
|
currentTime: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the current player is seeking.
|
||||||
|
*/
|
||||||
|
readonly seeking: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the duration for the current media.
|
||||||
|
*/
|
||||||
|
readonly duration: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the volume for the player. The setter accepts a float between 0 and 1.
|
||||||
|
*/
|
||||||
|
volume: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the muted state of the player. The setter accepts a boolean.
|
||||||
|
*/
|
||||||
|
muted: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the current media has an audio track.
|
||||||
|
*/
|
||||||
|
readonly hasAudio: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the speed for the player. The setter accepts a value in the options specified in your config. Generally the minimum should be 0.5.
|
||||||
|
*/
|
||||||
|
speed: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the quality for the player. The setter accepts a value from the options specified in your config.
|
||||||
|
*/
|
||||||
|
quality: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the current loop state of the player.
|
||||||
|
*/
|
||||||
|
loop: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the current source for the player.
|
||||||
|
*/
|
||||||
|
source: Plyr.SourceInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the current poster image URL for the player.
|
||||||
|
*/
|
||||||
|
poster: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the autoplay state of the player.
|
||||||
|
*/
|
||||||
|
autoplay: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the caption track by index. 1 means the track is missing or captions is not active
|
||||||
|
*/
|
||||||
|
currentTrack: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the preferred captions language for the player. The setter accepts an ISO twoletter language code. Support for the languages is dependent on the captions you include.
|
||||||
|
* If your captions don't have any language data, or if you have multiple tracks with the same language, you may want to use currentTrack instead.
|
||||||
|
*/
|
||||||
|
language: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the picture-in-picture state of the player. This currently only supported on Safari 10+ on MacOS Sierra+ and iOS 10+.
|
||||||
|
*/
|
||||||
|
pip: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets or sets the aspect ratio for embedded players.
|
||||||
|
*/
|
||||||
|
ratio?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access Elements cache
|
||||||
|
*/
|
||||||
|
elements: Plyr.Elements;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current video Provider
|
||||||
|
*/
|
||||||
|
readonly provider: Plyr.Provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the native API for Vimeo or Youtube players
|
||||||
|
*/
|
||||||
|
readonly embed?: any;
|
||||||
|
|
||||||
|
readonly fullscreen: Plyr.FullscreenControl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start playback.
|
||||||
|
* For HTML5 players, play() will return a Promise in some browsers - WebKit and Mozilla according to MDN at time of writing.
|
||||||
|
*/
|
||||||
|
play(): Promise<void> | void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pause playback.
|
||||||
|
*/
|
||||||
|
pause(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle playback, if no parameters are passed, it will toggle based on current status.
|
||||||
|
*/
|
||||||
|
togglePlay(toggle?: boolean): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop playback and reset to start.
|
||||||
|
*/
|
||||||
|
stop(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restart playback.
|
||||||
|
*/
|
||||||
|
restart(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewind playback by the specified seek time. If no parameter is passed, the default seek time will be used.
|
||||||
|
*/
|
||||||
|
rewind(seekTime?: number): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fast forward by the specified seek time. If no parameter is passed, the default seek time will be used.
|
||||||
|
*/
|
||||||
|
forward(seekTime?: number): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase volume by the specified step. If no parameter is passed, the default step will be used.
|
||||||
|
*/
|
||||||
|
increaseVolume(step?: number): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase volume by the specified step. If no parameter is passed, the default step will be used.
|
||||||
|
*/
|
||||||
|
decreaseVolume(step?: number): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle captions display. If no parameter is passed, it will toggle based on current status.
|
||||||
|
*/
|
||||||
|
toggleCaptions(toggle?: boolean): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger the airplay dialog on supported devices.
|
||||||
|
*/
|
||||||
|
airplay(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the preview thubmnails for the current source.
|
||||||
|
*/
|
||||||
|
setPreviewThumbnails(source: Plyr.PreviewThumbnailsOptions): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle the controls (video only). Takes optional truthy value to force it on/off.
|
||||||
|
*/
|
||||||
|
toggleControls(toggle: boolean): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an event listener for the specified event.
|
||||||
|
*/
|
||||||
|
on<K extends keyof Plyr.PlyrEventMap>(event: K, callback: (this: this, event: Plyr.PlyrEventMap[K]) => void): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an event listener for the specified event once.
|
||||||
|
*/
|
||||||
|
once<K extends keyof Plyr.PlyrEventMap>(event: K, callback: (this: this, event: Plyr.PlyrEventMap[K]) => void): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove an event listener for the specified event.
|
||||||
|
*/
|
||||||
|
off<K extends keyof Plyr.PlyrEventMap>(event: K, callback: (this: this, event: Plyr.PlyrEventMap[K]) => void): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check support for a mime type.
|
||||||
|
*/
|
||||||
|
supports(type: string): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy lib instance
|
||||||
|
* @param {Function} callback - Callback for when destroy is complete
|
||||||
|
* @param {Boolean} soft - Whether it's a soft destroy (for source changes etc)
|
||||||
|
*/
|
||||||
|
destroy(callback?: (...args: any[]) => void, soft?: boolean): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare namespace Plyr {
|
||||||
|
type MediaType = 'audio' | 'video';
|
||||||
|
type Provider = 'html5' | 'youtube' | 'vimeo';
|
||||||
|
type StandardEventMap = {
|
||||||
|
progress: PlyrEvent;
|
||||||
|
playing: PlyrEvent;
|
||||||
|
play: PlyrEvent;
|
||||||
|
pause: PlyrEvent;
|
||||||
|
timeupdate: PlyrEvent;
|
||||||
|
volumechange: PlyrEvent;
|
||||||
|
seeking: PlyrEvent;
|
||||||
|
seeked: PlyrEvent;
|
||||||
|
ratechange: PlyrEvent;
|
||||||
|
ended: PlyrEvent;
|
||||||
|
enterfullscreen: PlyrEvent;
|
||||||
|
exitfullscreen: PlyrEvent;
|
||||||
|
captionsenabled: PlyrEvent;
|
||||||
|
captionsdisabled: PlyrEvent;
|
||||||
|
languagechange: PlyrEvent;
|
||||||
|
controlshidden: PlyrEvent;
|
||||||
|
controlsshown: PlyrEvent;
|
||||||
|
ready: PlyrEvent;
|
||||||
|
};
|
||||||
|
// For retrocompatibility, we keep StandadEvent
|
||||||
|
type StandadEvent = keyof Plyr.StandardEventMap;
|
||||||
|
type Html5EventMap = {
|
||||||
|
loadstart: PlyrEvent;
|
||||||
|
loadeddata: PlyrEvent;
|
||||||
|
loadedmetadata: PlyrEvent;
|
||||||
|
canplay: PlyrEvent;
|
||||||
|
canplaythrough: PlyrEvent;
|
||||||
|
stalled: PlyrEvent;
|
||||||
|
waiting: PlyrEvent;
|
||||||
|
emptied: PlyrEvent;
|
||||||
|
cuechange: PlyrEvent;
|
||||||
|
error: PlyrEvent;
|
||||||
|
};
|
||||||
|
// For retrocompatibility, we keep Html5Event
|
||||||
|
type Html5Event = keyof Plyr.Html5EventMap;
|
||||||
|
type YoutubeEventMap = {
|
||||||
|
statechange: PlyrStateChangeEvent;
|
||||||
|
qualitychange: PlyrEvent;
|
||||||
|
qualityrequested: PlyrEvent;
|
||||||
|
};
|
||||||
|
// For retrocompatibility, we keep YoutubeEvent
|
||||||
|
type YoutubeEvent = keyof Plyr.YoutubeEventMap;
|
||||||
|
|
||||||
|
type PlyrEventMap = StandardEventMap & Html5EventMap & YoutubeEventMap;
|
||||||
|
|
||||||
|
interface FullscreenControl {
|
||||||
|
/**
|
||||||
|
* Indicates if the current player is in fullscreen mode.
|
||||||
|
*/
|
||||||
|
readonly active: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the current player has fullscreen enabled.
|
||||||
|
*/
|
||||||
|
readonly enabled: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter fullscreen. If fullscreen is not supported, a fallback ""full window/viewport"" is used instead.
|
||||||
|
*/
|
||||||
|
enter(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exit fullscreen.
|
||||||
|
*/
|
||||||
|
exit(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle fullscreen.
|
||||||
|
*/
|
||||||
|
toggle(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Options {
|
||||||
|
/**
|
||||||
|
* Completely disable Plyr. This would allow you to do a User Agent check or similar to programmatically enable or disable Plyr for a certain UA. Example below.
|
||||||
|
*/
|
||||||
|
enabled?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display debugging information in the console
|
||||||
|
*/
|
||||||
|
debug?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a function is passed, it is assumed your method will return either an element or HTML string for the controls. Three arguments will be passed to your function;
|
||||||
|
* id (the unique id for the player), seektime (the seektime step in seconds), and title (the media title). See CONTROLS.md for more info on how the html needs to be structured.
|
||||||
|
* Defaults to ['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'captions', 'settings', 'pip', 'airplay', 'fullscreen']
|
||||||
|
*/
|
||||||
|
controls?: string[] | ((id: string, seektime: number, title: string) => unknown) | Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you're using the default controls are used then you can specify which settings to show in the menu
|
||||||
|
* Defaults to ['captions', 'quality', 'speed', 'loop']
|
||||||
|
*/
|
||||||
|
settings?: string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for internationalization (i18n) of the text within the UI.
|
||||||
|
*/
|
||||||
|
i18n?: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the SVG sprite specified as the iconUrl option (if a URL). If false, it is assumed you are handling sprite loading yourself.
|
||||||
|
*/
|
||||||
|
loadSprite?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify a URL or path to the SVG sprite. See the SVG section for more info.
|
||||||
|
*/
|
||||||
|
iconUrl?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the id prefix for the icons used in the default controls (e.g. plyr-play would be plyr).
|
||||||
|
* This is to prevent clashes if you're using your own SVG sprite but with the default controls.
|
||||||
|
* Most people can ignore this option.
|
||||||
|
*/
|
||||||
|
iconPrefix?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify a URL or path to a blank video file used to properly cancel network requests.
|
||||||
|
*/
|
||||||
|
blankVideo?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Autoplay the media on load. This is generally advised against on UX grounds. It is also disabled by default in some browsers.
|
||||||
|
* If the autoplay attribute is present on a <video> or <audio> element, this will be automatically set to true.
|
||||||
|
*/
|
||||||
|
autoplay?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only allow one player playing at once.
|
||||||
|
*/
|
||||||
|
autopause?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time, in seconds, to seek when a user hits fast forward or rewind.
|
||||||
|
*/
|
||||||
|
seekTime?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A number, between 0 and 1, representing the initial volume of the player.
|
||||||
|
*/
|
||||||
|
volume?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to start playback muted. If the muted attribute is present on a <video> or <audio> element, this will be automatically set to true.
|
||||||
|
*/
|
||||||
|
muted?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Click (or tap) of the video container will toggle play/pause.
|
||||||
|
*/
|
||||||
|
clickToPlay?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable right click menu on video to help as very primitive obfuscation to prevent downloads of content.
|
||||||
|
*/
|
||||||
|
disableContextMenu?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide video controls automatically after 2s of no mouse or focus movement, on control element blur (tab out), on playback start or entering fullscreen.
|
||||||
|
* As soon as the mouse is moved, a control element is focused or playback is paused, the controls reappear instantly.
|
||||||
|
*/
|
||||||
|
hideControls?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the playback to the start once playback is complete.
|
||||||
|
*/
|
||||||
|
resetOnEnd?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable keyboard shortcuts for focused players only or globally
|
||||||
|
*/
|
||||||
|
keyboard?: KeyboardOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* controls: Display control labels as tooltips on :hover & :focus (by default, the labels are screen reader only).
|
||||||
|
* seek: Display a seek tooltip to indicate on click where the media would seek to.
|
||||||
|
*/
|
||||||
|
tooltips?: TooltipOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify a custom duration for media.
|
||||||
|
*/
|
||||||
|
duration?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the duration of the media on the metadataloaded event (on startup) in the current time display.
|
||||||
|
* This will only work if the preload attribute is not set to none (or is not set at all) and you choose not to display the duration (see controls option).
|
||||||
|
*/
|
||||||
|
displayDuration?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the current time as a countdown rather than an incremental counter.
|
||||||
|
*/
|
||||||
|
invertTime?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow users to click to toggle the above.
|
||||||
|
*/
|
||||||
|
toggleInvert?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows binding of event listeners to the controls before the default handlers. See the defaults.js for available listeners.
|
||||||
|
* If your handler prevents default on the event (event.preventDefault()), the default handler will not fire.
|
||||||
|
*/
|
||||||
|
listeners?: {[key: string]: (error: PlyrEvent) => void};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* active: Toggles if captions should be active by default. language: Sets the default language to load (if available). 'auto' uses the browser language.
|
||||||
|
* update: Listen to changes to tracks and update menu. This is needed for some streaming libraries, but can result in unselectable language options).
|
||||||
|
*/
|
||||||
|
captions?: CaptionOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* enabled: Toggles whether fullscreen should be enabled. fallback: Allow fallback to a full-window solution.
|
||||||
|
* iosNative: whether to use native iOS fullscreen when entering fullscreen (no custom controls)
|
||||||
|
*/
|
||||||
|
fullscreen?: FullScreenOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The aspect ratio you want to use for embedded players.
|
||||||
|
*/
|
||||||
|
ratio?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* enabled: Allow use of local storage to store user settings. key: The key name to use.
|
||||||
|
*/
|
||||||
|
storage?: StorageOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* selected: The default speed for playback. options: The speed options to display in the UI. YouTube and Vimeo will ignore any options outside of the 0.5-2 range, so options outside of this range will be hidden automatically.
|
||||||
|
*/
|
||||||
|
speed?: SpeedOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Currently only supported by YouTube. default is the default quality level, determined by YouTube. options are the options to display.
|
||||||
|
*/
|
||||||
|
quality?: QualityOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* active: Whether to loop the current video. If the loop attribute is present on a <video> or <audio> element,
|
||||||
|
* this will be automatically set to true This is an object to support future functionality.
|
||||||
|
*/
|
||||||
|
loop?: LoopOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* enabled: Whether to enable vi.ai ads. publisherId: Your unique vi.ai publisher ID.
|
||||||
|
*/
|
||||||
|
ads?: AdOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vimeo Player Options.
|
||||||
|
*/
|
||||||
|
vimeo?: object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Youtube Player Options.
|
||||||
|
*/
|
||||||
|
youtube?: object;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preview Thumbnails Options.
|
||||||
|
*/
|
||||||
|
previewThumbnails?: PreviewThumbnailsOptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Media Metadata Options.
|
||||||
|
*/
|
||||||
|
mediaMetadata?: MediaMetadataOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface QualityOptions {
|
||||||
|
default: number;
|
||||||
|
forced?: boolean;
|
||||||
|
onChange?: (quality: number) => void;
|
||||||
|
options: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LoopOptions {
|
||||||
|
active: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AdOptions {
|
||||||
|
enabled: boolean;
|
||||||
|
publisherId?: string;
|
||||||
|
tagUrl?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SpeedOptions {
|
||||||
|
selected: number;
|
||||||
|
options: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KeyboardOptions {
|
||||||
|
focused?: boolean;
|
||||||
|
global?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TooltipOptions {
|
||||||
|
controls?: boolean;
|
||||||
|
seek?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FullScreenOptions {
|
||||||
|
enabled?: boolean;
|
||||||
|
fallback?: boolean | 'force';
|
||||||
|
allowAudio?: boolean;
|
||||||
|
iosNative?: boolean;
|
||||||
|
container?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CaptionOptions {
|
||||||
|
active?: boolean;
|
||||||
|
language?: string;
|
||||||
|
update?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StorageOptions {
|
||||||
|
enabled?: boolean;
|
||||||
|
key?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PreviewThumbnailsOptions {
|
||||||
|
enabled?: boolean;
|
||||||
|
src?: string | string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MediaMetadataArtwork {
|
||||||
|
src: string;
|
||||||
|
sizes?: string;
|
||||||
|
type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MediaMetadataOptions {
|
||||||
|
title?: string;
|
||||||
|
artist?: string;
|
||||||
|
album?: string;
|
||||||
|
artwork?: MediaMetadataArtwork[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Elements {
|
||||||
|
buttons: {
|
||||||
|
airplay?: HTMLButtonElement;
|
||||||
|
captions?: HTMLButtonElement;
|
||||||
|
download?: HTMLButtonElement;
|
||||||
|
fastForward?: HTMLButtonElement;
|
||||||
|
fullscreen?: HTMLButtonElement;
|
||||||
|
mute?: HTMLButtonElement;
|
||||||
|
pip?: HTMLButtonElement;
|
||||||
|
play?: HTMLButtonElement | HTMLButtonElement[];
|
||||||
|
restart?: HTMLButtonElement;
|
||||||
|
rewind?: HTMLButtonElement;
|
||||||
|
settings?: HTMLButtonElement;
|
||||||
|
};
|
||||||
|
captions: HTMLElement | null;
|
||||||
|
container: HTMLElement | null;
|
||||||
|
controls: HTMLElement | null;
|
||||||
|
fullscreen: HTMLElement | null;
|
||||||
|
wrapper: HTMLElement | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SourceInfo {
|
||||||
|
/**
|
||||||
|
* Note: YouTube and Vimeo are currently not supported as audio sources.
|
||||||
|
*/
|
||||||
|
type: MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Title of the new media. Used for the aria-label attribute on the play button, and outer container. YouTube and Vimeo are populated automatically.
|
||||||
|
*/
|
||||||
|
title?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is an array of sources. For HTML5 media, the properties of this object are mapped directly to HTML attributes so more can be added to the object if required.
|
||||||
|
*/
|
||||||
|
sources: Source[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL for the poster image (HTML5 video only).
|
||||||
|
*/
|
||||||
|
poster?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of track objects. Each element in the array is mapped directly to a track element and any keys mapped directly to HTML attributes so as in the example above,
|
||||||
|
* it will render as <track kind="captions" label="English" srclang="en" src="https://cdn.selz.com/plyr/1.0/example_captions_en.vtt" default> and similar for the French version.
|
||||||
|
* Booleans are converted to HTML5 value-less attributes.
|
||||||
|
*/
|
||||||
|
tracks?: Track[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable preview thumbnails for current source
|
||||||
|
*/
|
||||||
|
previewThumbnails?: Plyr.PreviewThumbnailsOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Source {
|
||||||
|
/**
|
||||||
|
* The URL of the media file (or YouTube/Vimeo URL).
|
||||||
|
*/
|
||||||
|
src: string;
|
||||||
|
/**
|
||||||
|
* The MIME type of the media file (if HTML5).
|
||||||
|
*/
|
||||||
|
type?: string;
|
||||||
|
provider?: Provider;
|
||||||
|
size?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
type TrackKind = 'subtitles' | 'captions' | 'descriptions' | 'chapters' | 'metadata';
|
||||||
|
interface Track {
|
||||||
|
/**
|
||||||
|
* Indicates how the text track is meant to be used
|
||||||
|
*/
|
||||||
|
kind: TrackKind;
|
||||||
|
/**
|
||||||
|
* Indicates a user-readable title for the track
|
||||||
|
*/
|
||||||
|
label: string;
|
||||||
|
/**
|
||||||
|
* The language of the track text data. It must be a valid BCP 47 language tag. If the kind attribute is set to subtitles, then srclang must be defined.
|
||||||
|
*/
|
||||||
|
srcLang?: string;
|
||||||
|
/**
|
||||||
|
* The URL of the track (.vtt file).
|
||||||
|
*/
|
||||||
|
src: string;
|
||||||
|
|
||||||
|
default?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PlyrEvent extends CustomEvent {
|
||||||
|
readonly detail: {readonly plyr: Plyr};
|
||||||
|
}
|
||||||
|
|
||||||
|
enum YoutubeState {
|
||||||
|
UNSTARTED = -1,
|
||||||
|
ENDED = 0,
|
||||||
|
PLAYING = 1,
|
||||||
|
PAUSED = 2,
|
||||||
|
BUFFERING = 3,
|
||||||
|
CUED = 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PlyrStateChangeEvent extends CustomEvent {
|
||||||
|
readonly detail: {
|
||||||
|
readonly plyr: Plyr;
|
||||||
|
readonly code: YoutubeState;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Support {
|
||||||
|
api: boolean;
|
||||||
|
ui: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
+87
-55
@@ -1,6 +1,6 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// Plyr
|
// Plyr
|
||||||
// plyr.js v3.5.6
|
// plyr.js v3.7.0
|
||||||
// https://github.com/sampotts/plyr
|
// https://github.com/sampotts/plyr
|
||||||
// License: The MIT License (MIT)
|
// License: The MIT License (MIT)
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
@@ -12,6 +12,7 @@ import { getProviderByUrl, providers, types } from './config/types';
|
|||||||
import Console from './console';
|
import Console from './console';
|
||||||
import controls from './controls';
|
import controls from './controls';
|
||||||
import Fullscreen from './fullscreen';
|
import Fullscreen from './fullscreen';
|
||||||
|
import html5 from './html5';
|
||||||
import Listeners from './listeners';
|
import Listeners from './listeners';
|
||||||
import media from './media';
|
import media from './media';
|
||||||
import Ads from './plugins/ads';
|
import Ads from './plugins/ads';
|
||||||
@@ -27,7 +28,8 @@ import is from './utils/is';
|
|||||||
import loadSprite from './utils/load-sprite';
|
import loadSprite from './utils/load-sprite';
|
||||||
import { clamp } from './utils/numbers';
|
import { clamp } from './utils/numbers';
|
||||||
import { cloneDeep, extend } from './utils/objects';
|
import { cloneDeep, extend } from './utils/objects';
|
||||||
import { getAspectRatio, reduceAspectRatio, setAspectRatio, validateRatio } from './utils/style';
|
import { silencePromise } from './utils/promise';
|
||||||
|
import { getAspectRatio, reduceAspectRatio, setAspectRatio, validateAspectRatio } from './utils/style';
|
||||||
import { parseUrl } from './utils/urls';
|
import { parseUrl } from './utils/urls';
|
||||||
|
|
||||||
// Private properties
|
// Private properties
|
||||||
@@ -70,7 +72,7 @@ class Plyr {
|
|||||||
(() => {
|
(() => {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(this.media.getAttribute('data-plyr-config'));
|
return JSON.parse(this.media.getAttribute('data-plyr-config'));
|
||||||
} catch (e) {
|
} catch (_) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
@@ -79,6 +81,7 @@ class Plyr {
|
|||||||
// Elements cache
|
// Elements cache
|
||||||
this.elements = {
|
this.elements = {
|
||||||
container: null,
|
container: null,
|
||||||
|
fullscreen: null,
|
||||||
captions: null,
|
captions: null,
|
||||||
buttons: {},
|
buttons: {},
|
||||||
display: {},
|
display: {},
|
||||||
@@ -203,7 +206,7 @@ class Plyr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unsupported or missing provider
|
// Unsupported or missing provider
|
||||||
if (is.empty(this.provider) || !Object.keys(providers).includes(this.provider)) {
|
if (is.empty(this.provider) || !Object.values(providers).includes(this.provider)) {
|
||||||
this.debug.error('Setup failed: Invalid provider');
|
this.debug.error('Setup failed: Invalid provider');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -268,6 +271,9 @@ class Plyr {
|
|||||||
wrap(this.media, this.elements.container);
|
wrap(this.media, this.elements.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Migrate custom properties from media to container (so they work 😉)
|
||||||
|
ui.migrateStyles.call(this);
|
||||||
|
|
||||||
// Add style hook
|
// Add style hook
|
||||||
ui.addStyleHook.call(this);
|
ui.addStyleHook.call(this);
|
||||||
|
|
||||||
@@ -276,11 +282,14 @@ class Plyr {
|
|||||||
|
|
||||||
// Listen for events if debugging
|
// Listen for events if debugging
|
||||||
if (this.config.debug) {
|
if (this.config.debug) {
|
||||||
on.call(this, this.elements.container, this.config.events.join(' '), event => {
|
on.call(this, this.elements.container, this.config.events.join(' '), (event) => {
|
||||||
this.debug.log(`event: ${event.type}`);
|
this.debug.log(`event: ${event.type}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup fullscreen
|
||||||
|
this.fullscreen = new Fullscreen(this);
|
||||||
|
|
||||||
// Setup interface
|
// Setup interface
|
||||||
// If embed but not fully supported, build interface now to avoid flash of controls
|
// If embed but not fully supported, build interface now to avoid flash of controls
|
||||||
if (this.isHTML5 || (this.isEmbed && !this.supported.ui)) {
|
if (this.isHTML5 || (this.isEmbed && !this.supported.ui)) {
|
||||||
@@ -293,9 +302,6 @@ class Plyr {
|
|||||||
// Global listeners
|
// Global listeners
|
||||||
this.listeners.global();
|
this.listeners.global();
|
||||||
|
|
||||||
// Setup fullscreen
|
|
||||||
this.fullscreen = new Fullscreen(this);
|
|
||||||
|
|
||||||
// Setup ads if provided
|
// Setup ads if provided
|
||||||
if (this.config.ads.enabled) {
|
if (this.config.ads.enabled) {
|
||||||
this.ads = new Ads(this);
|
this.ads = new Ads(this);
|
||||||
@@ -303,7 +309,7 @@ class Plyr {
|
|||||||
|
|
||||||
// Autoplay if required
|
// Autoplay if required
|
||||||
if (this.isHTML5 && this.config.autoplay) {
|
if (this.isHTML5 && this.config.autoplay) {
|
||||||
setTimeout(() => this.play(), 10);
|
this.once('canplay', () => silencePromise(this.play()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Seek time will be recorded (in listeners.js) so we can prevent hiding controls for a few seconds after seek
|
// Seek time will be recorded (in listeners.js) so we can prevent hiding controls for a few seconds after seek
|
||||||
@@ -349,30 +355,30 @@ class Plyr {
|
|||||||
/**
|
/**
|
||||||
* Play the media, or play the advertisement (if they are not blocked)
|
* Play the media, or play the advertisement (if they are not blocked)
|
||||||
*/
|
*/
|
||||||
play() {
|
play = () => {
|
||||||
if (!is.function(this.media.play)) {
|
if (!is.function(this.media.play)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Intecept play with ads
|
// Intecept play with ads
|
||||||
if (this.ads && this.ads.enabled) {
|
if (this.ads && this.ads.enabled) {
|
||||||
this.ads.managerPromise.then(() => this.ads.play()).catch(() => this.media.play());
|
this.ads.managerPromise.then(() => this.ads.play()).catch(() => silencePromise(this.media.play()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the promise (for HTML5)
|
// Return the promise (for HTML5)
|
||||||
return this.media.play();
|
return this.media.play();
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pause the media
|
* Pause the media
|
||||||
*/
|
*/
|
||||||
pause() {
|
pause = () => {
|
||||||
if (!this.playing || !is.function(this.media.pause)) {
|
if (!this.playing || !is.function(this.media.pause)) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.media.pause();
|
return this.media.pause();
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get playing state
|
* Get playing state
|
||||||
@@ -406,51 +412,51 @@ class Plyr {
|
|||||||
* Toggle playback based on current status
|
* Toggle playback based on current status
|
||||||
* @param {Boolean} input
|
* @param {Boolean} input
|
||||||
*/
|
*/
|
||||||
togglePlay(input) {
|
togglePlay = (input) => {
|
||||||
// Toggle based on current state if nothing passed
|
// Toggle based on current state if nothing passed
|
||||||
const toggle = is.boolean(input) ? input : !this.playing;
|
const toggle = is.boolean(input) ? input : !this.playing;
|
||||||
|
|
||||||
if (toggle) {
|
if (toggle) {
|
||||||
this.play();
|
return this.play();
|
||||||
} else {
|
|
||||||
this.pause();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this.pause();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop playback
|
* Stop playback
|
||||||
*/
|
*/
|
||||||
stop() {
|
stop = () => {
|
||||||
if (this.isHTML5) {
|
if (this.isHTML5) {
|
||||||
this.pause();
|
this.pause();
|
||||||
this.restart();
|
this.restart();
|
||||||
} else if (is.function(this.media.stop)) {
|
} else if (is.function(this.media.stop)) {
|
||||||
this.media.stop();
|
this.media.stop();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restart playback
|
* Restart playback
|
||||||
*/
|
*/
|
||||||
restart() {
|
restart = () => {
|
||||||
this.currentTime = 0;
|
this.currentTime = 0;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rewind
|
* Rewind
|
||||||
* @param {Number} seekTime - how far to rewind in seconds. Defaults to the config.seekTime
|
* @param {Number} seekTime - how far to rewind in seconds. Defaults to the config.seekTime
|
||||||
*/
|
*/
|
||||||
rewind(seekTime) {
|
rewind = (seekTime) => {
|
||||||
this.currentTime = this.currentTime - (is.number(seekTime) ? seekTime : this.config.seekTime);
|
this.currentTime -= is.number(seekTime) ? seekTime : this.config.seekTime;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fast forward
|
* Fast forward
|
||||||
* @param {Number} seekTime - how far to fast forward in seconds. Defaults to the config.seekTime
|
* @param {Number} seekTime - how far to fast forward in seconds. Defaults to the config.seekTime
|
||||||
*/
|
*/
|
||||||
forward(seekTime) {
|
forward = (seekTime) => {
|
||||||
this.currentTime = this.currentTime + (is.number(seekTime) ? seekTime : this.config.seekTime);
|
this.currentTime += is.number(seekTime) ? seekTime : this.config.seekTime;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Seek to a time
|
* Seek to a time
|
||||||
@@ -576,18 +582,18 @@ class Plyr {
|
|||||||
* Increase volume
|
* Increase volume
|
||||||
* @param {Boolean} step - How much to decrease by (between 0 and 1)
|
* @param {Boolean} step - How much to decrease by (between 0 and 1)
|
||||||
*/
|
*/
|
||||||
increaseVolume(step) {
|
increaseVolume = (step) => {
|
||||||
const volume = this.media.muted ? 0 : this.volume;
|
const volume = this.media.muted ? 0 : this.volume;
|
||||||
this.volume = volume + (is.number(step) ? step : 0);
|
this.volume = volume + (is.number(step) ? step : 0);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrease volume
|
* Decrease volume
|
||||||
* @param {Boolean} step - How much to decrease by (between 0 and 1)
|
* @param {Boolean} step - How much to decrease by (between 0 and 1)
|
||||||
*/
|
*/
|
||||||
decreaseVolume(step) {
|
decreaseVolume = (step) => {
|
||||||
this.increaseVolume(-step);
|
this.increaseVolume(-step);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set muted state
|
* Set muted state
|
||||||
@@ -669,7 +675,9 @@ class Plyr {
|
|||||||
|
|
||||||
// Set media speed
|
// Set media speed
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
if (this.media) {
|
||||||
this.media.playbackRate = speed;
|
this.media.playbackRate = speed;
|
||||||
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -885,7 +893,7 @@ class Plyr {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.media.getAttribute('poster');
|
return this.media.getAttribute('poster') || this.media.getAttribute('data-poster');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -910,12 +918,12 @@ class Plyr {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is.string(input) || !validateRatio(input)) {
|
if (!is.string(input) || !validateAspectRatio(input)) {
|
||||||
this.debug.error(`Invalid aspect ratio specified (${input})`);
|
this.debug.error(`Invalid aspect ratio specified (${input})`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.config.ratio = input;
|
this.config.ratio = reduceAspectRatio(input);
|
||||||
|
|
||||||
setAspectRatio.call(this);
|
setAspectRatio.call(this);
|
||||||
}
|
}
|
||||||
@@ -950,6 +958,7 @@ class Plyr {
|
|||||||
*/
|
*/
|
||||||
set currentTrack(input) {
|
set currentTrack(input) {
|
||||||
captions.set.call(this, input, false);
|
captions.set.call(this, input, false);
|
||||||
|
captions.setup.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1023,22 +1032,39 @@ class Plyr {
|
|||||||
return this.media === document.pictureInPictureElement;
|
return this.media === document.pictureInPictureElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the preview thubmnails for the current source
|
||||||
|
*/
|
||||||
|
setPreviewThumbnails(thumbnailSource) {
|
||||||
|
if (this.previewThumbnails && this.previewThumbnails.loaded) {
|
||||||
|
this.previewThumbnails.destroy();
|
||||||
|
this.previewThumbnails = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(this.config.previewThumbnails, thumbnailSource);
|
||||||
|
|
||||||
|
// Create new instance if it is still enabled
|
||||||
|
if (this.config.previewThumbnails.enabled) {
|
||||||
|
this.previewThumbnails = new PreviewThumbnails(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger the airplay dialog
|
* Trigger the airplay dialog
|
||||||
* TODO: update player with state, support, enabled
|
* TODO: update player with state, support, enabled
|
||||||
*/
|
*/
|
||||||
airplay() {
|
airplay = () => {
|
||||||
// Show dialog if supported
|
// Show dialog if supported
|
||||||
if (support.airplay) {
|
if (support.airplay) {
|
||||||
this.media.webkitShowPlaybackTargetPicker();
|
this.media.webkitShowPlaybackTargetPicker();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle the player controls
|
* Toggle the player controls
|
||||||
* @param {Boolean} [toggle] - Whether to show the controls
|
* @param {Boolean} [toggle] - Whether to show the controls
|
||||||
*/
|
*/
|
||||||
toggleControls(toggle) {
|
toggleControls = (toggle) => {
|
||||||
// Don't toggle if missing UI support or if it's audio
|
// Don't toggle if missing UI support or if it's audio
|
||||||
if (this.supported.ui && !this.isAudio) {
|
if (this.supported.ui && !this.isAudio) {
|
||||||
// Get state before change
|
// Get state before change
|
||||||
@@ -1049,7 +1075,12 @@ class Plyr {
|
|||||||
const hiding = toggleClass(this.elements.container, this.config.classNames.hideControls, force);
|
const hiding = toggleClass(this.elements.container, this.config.classNames.hideControls, force);
|
||||||
|
|
||||||
// Close menu
|
// Close menu
|
||||||
if (hiding && this.config.controls.includes('settings') && !is.empty(this.config.settings)) {
|
if (
|
||||||
|
hiding &&
|
||||||
|
is.array(this.config.controls) &&
|
||||||
|
this.config.controls.includes('settings') &&
|
||||||
|
!is.empty(this.config.settings)
|
||||||
|
) {
|
||||||
controls.toggleMenu.call(this, false);
|
controls.toggleMenu.call(this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1063,34 +1094,34 @@ class Plyr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add event listeners
|
* Add event listeners
|
||||||
* @param {String} event - Event type
|
* @param {String} event - Event type
|
||||||
* @param {Function} callback - Callback for when event occurs
|
* @param {Function} callback - Callback for when event occurs
|
||||||
*/
|
*/
|
||||||
on(event, callback) {
|
on = (event, callback) => {
|
||||||
on.call(this, this.elements.container, event, callback);
|
on.call(this, this.elements.container, event, callback);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add event listeners once
|
* Add event listeners once
|
||||||
* @param {String} event - Event type
|
* @param {String} event - Event type
|
||||||
* @param {Function} callback - Callback for when event occurs
|
* @param {Function} callback - Callback for when event occurs
|
||||||
*/
|
*/
|
||||||
once(event, callback) {
|
once = (event, callback) => {
|
||||||
once.call(this, this.elements.container, event, callback);
|
once.call(this, this.elements.container, event, callback);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove event listeners
|
* Remove event listeners
|
||||||
* @param {String} event - Event type
|
* @param {String} event - Event type
|
||||||
* @param {Function} callback - Callback for when event occurs
|
* @param {Function} callback - Callback for when event occurs
|
||||||
*/
|
*/
|
||||||
off(event, callback) {
|
off = (event, callback) => {
|
||||||
off(this.elements.container, event, callback);
|
off(this.elements.container, event, callback);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy an instance
|
* Destroy an instance
|
||||||
@@ -1099,7 +1130,7 @@ class Plyr {
|
|||||||
* @param {Function} callback - Callback for when destroy is complete
|
* @param {Function} callback - Callback for when destroy is complete
|
||||||
* @param {Boolean} soft - Whether it's a soft destroy (for source changes etc)
|
* @param {Boolean} soft - Whether it's a soft destroy (for source changes etc)
|
||||||
*/
|
*/
|
||||||
destroy(callback, soft = false) {
|
destroy = (callback, soft = false) => {
|
||||||
if (!this.ready) {
|
if (!this.ready) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1135,6 +1166,9 @@ class Plyr {
|
|||||||
// Unbind listeners
|
// Unbind listeners
|
||||||
unbindListeners.call(this);
|
unbindListeners.call(this);
|
||||||
|
|
||||||
|
// Cancel current network requests
|
||||||
|
html5.cancelRequests.call(this);
|
||||||
|
|
||||||
// Replace the container with the original element provided
|
// Replace the container with the original element provided
|
||||||
replaceElement(this.elements.original, this.elements.container);
|
replaceElement(this.elements.original, this.elements.container);
|
||||||
|
|
||||||
@@ -1194,15 +1228,13 @@ class Plyr {
|
|||||||
// Vimeo does not always return
|
// Vimeo does not always return
|
||||||
setTimeout(done, 200);
|
setTimeout(done, 200);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for support for a mime type (HTML5 only)
|
* Check for support for a mime type (HTML5 only)
|
||||||
* @param {String} type - Mime type
|
* @param {String} type - Mime type
|
||||||
*/
|
*/
|
||||||
supports(type) {
|
supports = (type) => support.mime.call(this, type);
|
||||||
return support.mime.call(this, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for support
|
* Check for support
|
||||||
@@ -1243,7 +1275,7 @@ class Plyr {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return targets.map(t => new Plyr(t, options));
|
return targets.map((t) => new Plyr(t, options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// Plyr Polyfilled Build
|
// Plyr Polyfilled Build
|
||||||
// plyr.js v3.5.6
|
// plyr.js v3.7.0
|
||||||
// https://github.com/sampotts/plyr
|
// https://github.com/sampotts/plyr
|
||||||
// License: The MIT License (MIT)
|
// License: The MIT License (MIT)
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|||||||
+16
-4
@@ -5,6 +5,7 @@
|
|||||||
import { providers } from './config/types';
|
import { providers } from './config/types';
|
||||||
import html5 from './html5';
|
import html5 from './html5';
|
||||||
import media from './media';
|
import media from './media';
|
||||||
|
import PreviewThumbnails from './plugins/preview-thumbnails';
|
||||||
import support from './support';
|
import support from './support';
|
||||||
import ui from './ui';
|
import ui from './ui';
|
||||||
import { createElement, insertElement, removeElement } from './utils/elements';
|
import { createElement, insertElement, removeElement } from './utils/elements';
|
||||||
@@ -19,7 +20,7 @@ const source = {
|
|||||||
src: attributes,
|
src: attributes,
|
||||||
});
|
});
|
||||||
} else if (is.array(attributes)) {
|
} else if (is.array(attributes)) {
|
||||||
attributes.forEach(attribute => {
|
attributes.forEach((attribute) => {
|
||||||
insertElement(type, this.media, attribute);
|
insertElement(type, this.media, attribute);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -130,9 +131,20 @@ const source = {
|
|||||||
this.media.load();
|
this.media.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reload thumbnails
|
// Update previewThumbnails config & reload plugin
|
||||||
if (this.previewThumbnails) {
|
if (!is.empty(input.previewThumbnails)) {
|
||||||
this.previewThumbnails.load();
|
Object.assign(this.config.previewThumbnails, input.previewThumbnails);
|
||||||
|
|
||||||
|
// Cleanup previewThumbnails plugin if it was loaded
|
||||||
|
if (this.previewThumbnails && this.previewThumbnails.loaded) {
|
||||||
|
this.previewThumbnails.destroy();
|
||||||
|
this.previewThumbnails = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new instance if it is still enabled
|
||||||
|
if (this.config.previewThumbnails.enabled) {
|
||||||
|
this.previewThumbnails = new PreviewThumbnails(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the fullscreen support
|
// Update the fullscreen support
|
||||||
|
|||||||
+8
-4
@@ -26,12 +26,12 @@ class Storage {
|
|||||||
window.localStorage.removeItem(test);
|
window.localStorage.removeItem(test);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get(key) {
|
get = (key) => {
|
||||||
if (!Storage.supported || !this.enabled) {
|
if (!Storage.supported || !this.enabled) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -45,9 +45,9 @@ class Storage {
|
|||||||
const json = JSON.parse(store);
|
const json = JSON.parse(store);
|
||||||
|
|
||||||
return is.string(key) && key.length ? json[key] : json;
|
return is.string(key) && key.length ? json[key] : json;
|
||||||
}
|
};
|
||||||
|
|
||||||
set(object) {
|
set = (object) => {
|
||||||
// Bail if we don't have localStorage support or it's disabled
|
// Bail if we don't have localStorage support or it's disabled
|
||||||
if (!Storage.supported || !this.enabled) {
|
if (!Storage.supported || !this.enabled) {
|
||||||
return;
|
return;
|
||||||
@@ -70,8 +70,12 @@ class Storage {
|
|||||||
extend(storage, object);
|
extend(storage, object);
|
||||||
|
|
||||||
// Update storage
|
// Update storage
|
||||||
|
try {
|
||||||
window.localStorage.setItem(this.key, JSON.stringify(storage));
|
window.localStorage.setItem(this.key, JSON.stringify(storage));
|
||||||
|
} catch (_) {
|
||||||
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Storage;
|
export default Storage;
|
||||||
|
|||||||
+1
-1
@@ -88,7 +88,7 @@ const support = {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return Boolean(type && this.media.canPlayType(type).replace(/no/, ''));
|
return Boolean(type && this.media.canPlayType(type).replace(/no/, ''));
|
||||||
} catch (e) {
|
} catch (_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+40
-11
@@ -82,6 +82,9 @@ const ui = {
|
|||||||
// Reset time display
|
// Reset time display
|
||||||
controls.timeUpdate.call(this);
|
controls.timeUpdate.call(this);
|
||||||
|
|
||||||
|
// Reset duration display
|
||||||
|
controls.durationUpdate.call(this);
|
||||||
|
|
||||||
// Update the UI
|
// Update the UI
|
||||||
ui.checkPlaying.call(this);
|
ui.checkPlaying.call(this);
|
||||||
|
|
||||||
@@ -122,6 +125,11 @@ const ui = {
|
|||||||
if (this.config.duration) {
|
if (this.config.duration) {
|
||||||
controls.durationUpdate.call(this);
|
controls.durationUpdate.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Media metadata
|
||||||
|
if (this.config.mediaMetadata) {
|
||||||
|
controls.setMediaMetadata.call(this);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Setup aria attribute for play and iframe title
|
// Setup aria attribute for play and iframe title
|
||||||
@@ -135,7 +143,7 @@ const ui = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If there's a play button, set label
|
// If there's a play button, set label
|
||||||
Array.from(this.elements.buttons.play || []).forEach(button => {
|
Array.from(this.elements.buttons.play || []).forEach((button) => {
|
||||||
button.setAttribute('aria-label', label);
|
button.setAttribute('aria-label', label);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -170,7 +178,10 @@ const ui = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set property synchronously to respect the call order
|
// Set property synchronously to respect the call order
|
||||||
this.media.setAttribute('poster', poster);
|
this.media.setAttribute('data-poster', poster);
|
||||||
|
|
||||||
|
// Show the poster
|
||||||
|
this.elements.poster.removeAttribute('hidden');
|
||||||
|
|
||||||
// Wait until ui is ready
|
// Wait until ui is ready
|
||||||
return (
|
return (
|
||||||
@@ -178,13 +189,13 @@ const ui = {
|
|||||||
.call(this)
|
.call(this)
|
||||||
// Load image
|
// Load image
|
||||||
.then(() => loadImage(poster))
|
.then(() => loadImage(poster))
|
||||||
.catch(err => {
|
.catch((error) => {
|
||||||
// Hide poster on error unless it's been set by another call
|
// Hide poster on error unless it's been set by another call
|
||||||
if (poster === this.poster) {
|
if (poster === this.poster) {
|
||||||
ui.togglePoster.call(this, false);
|
ui.togglePoster.call(this, false);
|
||||||
}
|
}
|
||||||
// Rethrow
|
// Rethrow
|
||||||
throw err;
|
throw error;
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Prevent race conditions
|
// Prevent race conditions
|
||||||
@@ -198,7 +209,9 @@ const ui = {
|
|||||||
// Reset backgroundSize as well (since it can be set to "cover" for padded thumbnails for youtube)
|
// Reset backgroundSize as well (since it can be set to "cover" for padded thumbnails for youtube)
|
||||||
backgroundSize: '',
|
backgroundSize: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.togglePoster.call(this, true);
|
ui.togglePoster.call(this, true);
|
||||||
|
|
||||||
return poster;
|
return poster;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -212,8 +225,9 @@ const ui = {
|
|||||||
toggleClass(this.elements.container, this.config.classNames.stopped, this.stopped);
|
toggleClass(this.elements.container, this.config.classNames.stopped, this.stopped);
|
||||||
|
|
||||||
// Set state
|
// Set state
|
||||||
Array.from(this.elements.buttons.play || []).forEach(target => {
|
Array.from(this.elements.buttons.play || []).forEach((target) => {
|
||||||
Object.assign(target, { pressed: this.playing });
|
Object.assign(target, { pressed: this.playing });
|
||||||
|
target.setAttribute('aria-label', i18n.get(this.playing ? 'pause' : 'play', this.config));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Only update controls on non timeupdate events
|
// Only update controls on non timeupdate events
|
||||||
@@ -256,16 +270,31 @@ const ui = {
|
|||||||
// Show controls if force, loading, paused, button interaction, or recent seek, otherwise hide
|
// Show controls if force, loading, paused, button interaction, or recent seek, otherwise hide
|
||||||
this.toggleControls(
|
this.toggleControls(
|
||||||
Boolean(
|
Boolean(
|
||||||
force ||
|
force || this.loading || this.paused || controlsElement.pressed || controlsElement.hover || recentTouchSeek,
|
||||||
this.loading ||
|
|
||||||
this.paused ||
|
|
||||||
controlsElement.pressed ||
|
|
||||||
controlsElement.hover ||
|
|
||||||
recentTouchSeek,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Migrate any custom properties from the media to the parent
|
||||||
|
migrateStyles() {
|
||||||
|
// Loop through values (as they are the keys when the object is spread 🤔)
|
||||||
|
Object.values({ ...this.media.style })
|
||||||
|
// We're only fussed about Plyr specific properties
|
||||||
|
.filter((key) => !is.empty(key) && is.string(key) && key.startsWith('--plyr'))
|
||||||
|
.forEach((key) => {
|
||||||
|
// Set on the container
|
||||||
|
this.elements.container.style.setProperty(key, this.media.style.getPropertyValue(key));
|
||||||
|
|
||||||
|
// Clean up from media element
|
||||||
|
this.media.style.removeProperty(key);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Remove attribute if empty
|
||||||
|
if (is.empty(this.media.style)) {
|
||||||
|
this.media.removeAttribute('style');
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ui;
|
export default ui;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const transitionEndEvent = (() => {
|
|||||||
transition: 'transitionend',
|
transition: 'transitionend',
|
||||||
};
|
};
|
||||||
|
|
||||||
const type = Object.keys(events).find(event => element.style[event] !== undefined);
|
const type = Object.keys(events).find((event) => element.style[event] !== undefined);
|
||||||
|
|
||||||
return is.string(type) ? events[type] : false;
|
return is.string(type) ? events[type] : false;
|
||||||
})();
|
})();
|
||||||
@@ -31,7 +31,7 @@ export function repaint(element, delay) {
|
|||||||
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
element.hidden = false;
|
element.hidden = false;
|
||||||
} catch (e) {
|
} catch (_) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
}, delay);
|
}, delay);
|
||||||
|
|||||||
@@ -4,11 +4,13 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
const browser = {
|
const browser = {
|
||||||
isIE: /* @cc_on!@ */ false || !!document.documentMode,
|
isIE: Boolean(window.document.documentMode),
|
||||||
isEdge: window.navigator.userAgent.includes('Edge'),
|
isEdge: window.navigator.userAgent.includes('Edge'),
|
||||||
isWebkit: 'WebkitAppearance' in document.documentElement.style && !/Edge/.test(navigator.userAgent),
|
isWebkit: 'WebkitAppearance' in document.documentElement.style && !/Edge/.test(navigator.userAgent),
|
||||||
isIPhone: /(iPhone|iPod)/gi.test(navigator.platform),
|
isIPhone: /(iPhone|iPod)/gi.test(navigator.platform),
|
||||||
isIos: /(iPad|iPhone|iPod)/gi.test(navigator.platform),
|
isIos:
|
||||||
|
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1) ||
|
||||||
|
/(iPad|iPhone|iPod)/gi.test(navigator.platform),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default browser;
|
export default browser;
|
||||||
|
|||||||
+23
-37
@@ -2,7 +2,6 @@
|
|||||||
// Element utils
|
// Element utils
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import { toggleListener } from './events';
|
|
||||||
import is from './is';
|
import is from './is';
|
||||||
import { extend } from './objects';
|
import { extend } from './objects';
|
||||||
|
|
||||||
@@ -139,7 +138,7 @@ export function getAttributesFromSelector(sel, existingAttributes) {
|
|||||||
const attributes = {};
|
const attributes = {};
|
||||||
const existing = extend({}, existingAttributes);
|
const existing = extend({}, existingAttributes);
|
||||||
|
|
||||||
sel.split(',').forEach(s => {
|
sel.split(',').forEach((s) => {
|
||||||
// Remove whitespace
|
// Remove whitespace
|
||||||
const selector = s.trim();
|
const selector = s.trim();
|
||||||
const className = selector.replace('.', '');
|
const className = selector.replace('.', '');
|
||||||
@@ -199,7 +198,7 @@ export function toggleHidden(element, hidden) {
|
|||||||
// Mirror Element.classList.toggle, with IE compatibility for "force" argument
|
// Mirror Element.classList.toggle, with IE compatibility for "force" argument
|
||||||
export function toggleClass(element, className, force) {
|
export function toggleClass(element, className, force) {
|
||||||
if (is.nodeList(element)) {
|
if (is.nodeList(element)) {
|
||||||
return Array.from(element).map(e => toggleClass(e, className, force));
|
return Array.from(element).map((e) => toggleClass(e, className, force));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is.element(element)) {
|
if (is.element(element)) {
|
||||||
@@ -222,7 +221,7 @@ export function hasClass(element, className) {
|
|||||||
|
|
||||||
// Element matches selector
|
// Element matches selector
|
||||||
export function matches(element, selector) {
|
export function matches(element, selector) {
|
||||||
const prototype = { Element };
|
const { prototype } = Element;
|
||||||
|
|
||||||
function match() {
|
function match() {
|
||||||
return Array.from(document.querySelectorAll(selector)).includes(this);
|
return Array.from(document.querySelectorAll(selector)).includes(this);
|
||||||
@@ -238,6 +237,26 @@ export function matches(element, selector) {
|
|||||||
return method.call(element, selector);
|
return method.call(element, selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Closest ancestor element matching selector (also tests element itself)
|
||||||
|
export function closest(element, selector) {
|
||||||
|
const { prototype } = Element;
|
||||||
|
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
|
||||||
|
function closestElement() {
|
||||||
|
let el = this;
|
||||||
|
|
||||||
|
do {
|
||||||
|
if (matches.matches(el, selector)) return el;
|
||||||
|
el = el.parentElement || el.parentNode;
|
||||||
|
} while (el !== null && el.nodeType === 1);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const method = prototype.closest || closestElement;
|
||||||
|
|
||||||
|
return method.call(element, selector);
|
||||||
|
}
|
||||||
|
|
||||||
// Find all elements
|
// Find all elements
|
||||||
export function getElements(selector) {
|
export function getElements(selector) {
|
||||||
return this.elements.container.querySelectorAll(selector);
|
return this.elements.container.querySelectorAll(selector);
|
||||||
@@ -248,39 +267,6 @@ export function getElement(selector) {
|
|||||||
return this.elements.container.querySelector(selector);
|
return this.elements.container.querySelector(selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trap focus inside container
|
|
||||||
export function trapFocus(element = null, toggle = false) {
|
|
||||||
if (!is.element(element)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const focusable = getElements.call(this, 'button:not(:disabled), input:not(:disabled), [tabindex]');
|
|
||||||
const first = focusable[0];
|
|
||||||
const last = focusable[focusable.length - 1];
|
|
||||||
|
|
||||||
const trap = event => {
|
|
||||||
// Bail if not tab key or not fullscreen
|
|
||||||
if (event.key !== 'Tab' || event.keyCode !== 9) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the current focused element
|
|
||||||
const focused = document.activeElement;
|
|
||||||
|
|
||||||
if (focused === last && !event.shiftKey) {
|
|
||||||
// Move focus to first element that can be tabbed if Shift isn't used
|
|
||||||
first.focus();
|
|
||||||
event.preventDefault();
|
|
||||||
} else if (focused === first && event.shiftKey) {
|
|
||||||
// Move focus to last element that can be tabbed if Shift is used
|
|
||||||
last.focus();
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
toggleListener.call(this, this.elements.container, 'keydown', trap, toggle, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set focus and tab focus class
|
// Set focus and tab focus class
|
||||||
export function setFocus(element = null, tabFocus = false) {
|
export function setFocus(element = null, tabFocus = false) {
|
||||||
if (!is.element(element)) {
|
if (!is.element(element)) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const supportsPassiveListeners = (() => {
|
|||||||
});
|
});
|
||||||
window.addEventListener('test', null, options);
|
window.addEventListener('test', null, options);
|
||||||
window.removeEventListener('test', null, options);
|
window.removeEventListener('test', null, options);
|
||||||
} catch (e) {
|
} catch (_) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ export function toggleListener(element, event, callback, toggle = false, passive
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If a single node is passed, bind the event listener
|
// If a single node is passed, bind the event listener
|
||||||
events.forEach(type => {
|
events.forEach((type) => {
|
||||||
if (this && this.eventListeners && toggle) {
|
if (this && this.eventListeners && toggle) {
|
||||||
// Cache event listener
|
// Cache event listener
|
||||||
this.eventListeners.push({ element, type, callback, options });
|
this.eventListeners.push({ element, type, callback, options });
|
||||||
@@ -90,9 +90,7 @@ export function triggerEvent(element, type = '', bubbles = false, detail = {}) {
|
|||||||
// Create and dispatch the event
|
// Create and dispatch the event
|
||||||
const event = new CustomEvent(type, {
|
const event = new CustomEvent(type, {
|
||||||
bubbles,
|
bubbles,
|
||||||
detail: Object.assign({}, detail, {
|
detail: { ...detail, plyr: this },
|
||||||
plyr: this,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Dispatch the event
|
// Dispatch the event
|
||||||
@@ -102,7 +100,7 @@ export function triggerEvent(element, type = '', bubbles = false, detail = {}) {
|
|||||||
// Unbind all cached event listeners
|
// Unbind all cached event listeners
|
||||||
export function unbindListeners() {
|
export function unbindListeners() {
|
||||||
if (this && this.eventListeners) {
|
if (this && this.eventListeners) {
|
||||||
this.eventListeners.forEach(item => {
|
this.eventListeners.forEach((item) => {
|
||||||
const { element, type, callback, options } = item;
|
const { element, type, callback, options } = item;
|
||||||
element.removeEventListener(type, callback, options);
|
element.removeEventListener(type, callback, options);
|
||||||
});
|
});
|
||||||
@@ -113,7 +111,7 @@ export function unbindListeners() {
|
|||||||
|
|
||||||
// Run method when / if player is ready
|
// Run method when / if player is ready
|
||||||
export function ready() {
|
export function ready() {
|
||||||
return new Promise(resolve =>
|
return new Promise((resolve) =>
|
||||||
this.ready ? setTimeout(resolve, 0) : on.call(this, this.elements.container, 'ready', resolve),
|
this.ready ? setTimeout(resolve, 0) : on.call(this, this.elements.container, 'ready', resolve),
|
||||||
).then(() => {});
|
).then(() => {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export default function fetch(url, responseType = 'text') {
|
|||||||
if (responseType === 'text') {
|
if (responseType === 'text') {
|
||||||
try {
|
try {
|
||||||
resolve(JSON.parse(request.responseText));
|
resolve(JSON.parse(request.responseText));
|
||||||
} catch (e) {
|
} catch (_) {
|
||||||
resolve(request.responseText);
|
resolve(request.responseText);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -35,8 +35,8 @@ export default function fetch(url, responseType = 'text') {
|
|||||||
request.responseType = responseType;
|
request.responseType = responseType;
|
||||||
|
|
||||||
request.send();
|
request.send();
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
reject(e);
|
reject(error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-20
@@ -2,31 +2,37 @@
|
|||||||
// Type checking utils
|
// Type checking utils
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
const getConstructor = input => (input !== null && typeof input !== 'undefined' ? input.constructor : null);
|
const getConstructor = (input) => (input !== null && typeof input !== 'undefined' ? input.constructor : null);
|
||||||
const instanceOf = (input, constructor) => Boolean(input && constructor && input instanceof constructor);
|
const instanceOf = (input, constructor) => Boolean(input && constructor && input instanceof constructor);
|
||||||
const isNullOrUndefined = input => input === null || typeof input === 'undefined';
|
const isNullOrUndefined = (input) => input === null || typeof input === 'undefined';
|
||||||
const isObject = input => getConstructor(input) === Object;
|
const isObject = (input) => getConstructor(input) === Object;
|
||||||
const isNumber = input => getConstructor(input) === Number && !Number.isNaN(input);
|
const isNumber = (input) => getConstructor(input) === Number && !Number.isNaN(input);
|
||||||
const isString = input => getConstructor(input) === String;
|
const isString = (input) => getConstructor(input) === String;
|
||||||
const isBoolean = input => getConstructor(input) === Boolean;
|
const isBoolean = (input) => getConstructor(input) === Boolean;
|
||||||
const isFunction = input => getConstructor(input) === Function;
|
const isFunction = (input) => getConstructor(input) === Function;
|
||||||
const isArray = input => Array.isArray(input);
|
const isArray = (input) => Array.isArray(input);
|
||||||
const isWeakMap = input => instanceOf(input, WeakMap);
|
const isWeakMap = (input) => instanceOf(input, WeakMap);
|
||||||
const isNodeList = input => instanceOf(input, NodeList);
|
const isNodeList = (input) => instanceOf(input, NodeList);
|
||||||
const isElement = input => instanceOf(input, Element);
|
const isTextNode = (input) => getConstructor(input) === Text;
|
||||||
const isTextNode = input => getConstructor(input) === Text;
|
const isEvent = (input) => instanceOf(input, Event);
|
||||||
const isEvent = input => instanceOf(input, Event);
|
const isKeyboardEvent = (input) => instanceOf(input, KeyboardEvent);
|
||||||
const isKeyboardEvent = input => instanceOf(input, KeyboardEvent);
|
const isCue = (input) => instanceOf(input, window.TextTrackCue) || instanceOf(input, window.VTTCue);
|
||||||
const isCue = input => instanceOf(input, window.TextTrackCue) || instanceOf(input, window.VTTCue);
|
const isTrack = (input) => instanceOf(input, TextTrack) || (!isNullOrUndefined(input) && isString(input.kind));
|
||||||
const isTrack = input => instanceOf(input, TextTrack) || (!isNullOrUndefined(input) && isString(input.kind));
|
const isPromise = (input) => instanceOf(input, Promise) && isFunction(input.then);
|
||||||
const isPromise = input => instanceOf(input, Promise);
|
|
||||||
|
|
||||||
const isEmpty = input =>
|
const isElement = (input) =>
|
||||||
|
input !== null &&
|
||||||
|
typeof input === 'object' &&
|
||||||
|
input.nodeType === 1 &&
|
||||||
|
typeof input.style === 'object' &&
|
||||||
|
typeof input.ownerDocument === 'object';
|
||||||
|
|
||||||
|
const isEmpty = (input) =>
|
||||||
isNullOrUndefined(input) ||
|
isNullOrUndefined(input) ||
|
||||||
((isString(input) || isArray(input) || isNodeList(input)) && !input.length) ||
|
((isString(input) || isArray(input) || isNodeList(input)) && !input.length) ||
|
||||||
(isObject(input) && !Object.keys(input).length);
|
(isObject(input) && !Object.keys(input).length);
|
||||||
|
|
||||||
const isUrl = input => {
|
const isUrl = (input) => {
|
||||||
// Accept a URL object
|
// Accept a URL object
|
||||||
if (instanceOf(input, window.URL)) {
|
if (instanceOf(input, window.URL)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -45,7 +51,7 @@ const isUrl = input => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return !isEmpty(new URL(string).hostname);
|
return !isEmpty(new URL(string).hostname);
|
||||||
} catch (e) {
|
} catch (_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -54,18 +54,22 @@ export default function loadSprite(url, id) {
|
|||||||
|
|
||||||
// Get the sprite
|
// Get the sprite
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
if (is.empty(result)) {
|
if (is.empty(result)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useStorage) {
|
if (useStorage) {
|
||||||
|
try {
|
||||||
window.localStorage.setItem(
|
window.localStorage.setItem(
|
||||||
`${prefix}-${id}`,
|
`${prefix}-${id}`,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
content: result,
|
content: result,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
} catch (_) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update(container, result);
|
update(container, result);
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export function extend(target = {}, ...sources) {
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(source).forEach(key => {
|
Object.keys(source).forEach((key) => {
|
||||||
if (is.object(source[key])) {
|
if (is.object(source[key])) {
|
||||||
if (!Object.keys(target).includes(key)) {
|
if (!Object.keys(target).includes(key)) {
|
||||||
Object.assign(target, { [key]: {} });
|
Object.assign(target, { [key]: {} });
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import is from './is';
|
||||||
|
/**
|
||||||
|
* Silence a Promise-like object.
|
||||||
|
* This is useful for avoiding non-harmful, but potentially confusing "uncaught
|
||||||
|
* play promise" rejection error messages.
|
||||||
|
* @param {Object} value An object that may or may not be `Promise`-like.
|
||||||
|
*/
|
||||||
|
export function silencePromise(value) {
|
||||||
|
if (is.promise(value)) {
|
||||||
|
value.then(null, () => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { silencePromise };
|
||||||
@@ -28,17 +28,12 @@ export function getPercentage(current, max) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Replace all occurances of a string in a string
|
// Replace all occurances of a string in a string
|
||||||
export function replaceAll(input = '', find = '', replace = '') {
|
export const replaceAll = (input = '', find = '', replace = '') =>
|
||||||
return input.replace(
|
input.replace(new RegExp(find.toString().replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1'), 'g'), replace.toString());
|
||||||
new RegExp(find.toString().replace(/([.*+?^=!:${}()|[\]/\\])/g, '\\$1'), 'g'),
|
|
||||||
replace.toString(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert to title case
|
// Convert to title case
|
||||||
export function toTitleCase(input = '') {
|
export const toTitleCase = (input = '') =>
|
||||||
return input.toString().replace(/\w\S*/g, text => text.charAt(0).toUpperCase() + text.substr(1).toLowerCase());
|
input.toString().replace(/\w\S*/g, (text) => text.charAt(0).toUpperCase() + text.slice(1).toLowerCase());
|
||||||
}
|
|
||||||
|
|
||||||
// Convert string to pascalCase
|
// Convert string to pascalCase
|
||||||
export function toPascalCase(input = '') {
|
export function toPascalCase(input = '') {
|
||||||
|
|||||||
+79
-11
@@ -2,9 +2,39 @@
|
|||||||
// Style utils
|
// Style utils
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
|
import { closest } from './arrays';
|
||||||
import is from './is';
|
import is from './is';
|
||||||
|
|
||||||
export function validateRatio(input) {
|
// Check support for a CSS declaration
|
||||||
|
export function supportsCSS(declaration) {
|
||||||
|
if (!window || !window.CSS) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return window.CSS.supports(declaration);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Standard/common aspect ratios
|
||||||
|
const standardRatios = [
|
||||||
|
[1, 1],
|
||||||
|
[4, 3],
|
||||||
|
[3, 4],
|
||||||
|
[5, 4],
|
||||||
|
[4, 5],
|
||||||
|
[3, 2],
|
||||||
|
[2, 3],
|
||||||
|
[16, 10],
|
||||||
|
[10, 16],
|
||||||
|
[16, 9],
|
||||||
|
[9, 16],
|
||||||
|
[21, 9],
|
||||||
|
[9, 21],
|
||||||
|
[32, 9],
|
||||||
|
[9, 32],
|
||||||
|
].reduce((out, [x, y]) => ({ ...out, [x / y]: [x, y] }), {});
|
||||||
|
|
||||||
|
// Validate an aspect ratio
|
||||||
|
export function validateAspectRatio(input) {
|
||||||
if (!is.array(input) && (!is.string(input) || !input.includes(':'))) {
|
if (!is.array(input) && (!is.string(input) || !input.includes(':'))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -14,6 +44,7 @@ export function validateRatio(input) {
|
|||||||
return ratio.map(Number).every(is.number);
|
return ratio.map(Number).every(is.number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reduce an aspect ratio to it's lowest form
|
||||||
export function reduceAspectRatio(ratio) {
|
export function reduceAspectRatio(ratio) {
|
||||||
if (!is.array(ratio) || !ratio.every(is.number)) {
|
if (!is.array(ratio) || !ratio.every(is.number)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -26,8 +57,9 @@ export function reduceAspectRatio(ratio) {
|
|||||||
return [width / divider, height / divider];
|
return [width / divider, height / divider];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate an aspect ratio
|
||||||
export function getAspectRatio(input) {
|
export function getAspectRatio(input) {
|
||||||
const parse = ratio => (validateRatio(ratio) ? ratio.split(':').map(Number) : null);
|
const parse = (ratio) => (validateAspectRatio(ratio) ? ratio.split(':').map(Number) : null);
|
||||||
// Try provided ratio
|
// Try provided ratio
|
||||||
let ratio = parse(input);
|
let ratio = parse(input);
|
||||||
|
|
||||||
@@ -44,10 +76,10 @@ export function getAspectRatio(input) {
|
|||||||
// Get from HTML5 video
|
// Get from HTML5 video
|
||||||
if (ratio === null && this.isHTML5) {
|
if (ratio === null && this.isHTML5) {
|
||||||
const { videoWidth, videoHeight } = this.media;
|
const { videoWidth, videoHeight } = this.media;
|
||||||
ratio = reduceAspectRatio([videoWidth, videoHeight]);
|
ratio = [videoWidth, videoHeight];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ratio;
|
return reduceAspectRatio(ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set aspect ratio for responsive container
|
// Set aspect ratio for responsive container
|
||||||
@@ -56,22 +88,58 @@ export function setAspectRatio(input) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { wrapper } = this.elements;
|
||||||
const ratio = getAspectRatio.call(this, input);
|
const ratio = getAspectRatio.call(this, input);
|
||||||
const [w, h] = is.array(ratio) ? ratio : [0, 0];
|
|
||||||
const padding = (100 / w) * h;
|
|
||||||
|
|
||||||
this.elements.wrapper.style.paddingBottom = `${padding}%`;
|
if (!is.array(ratio)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const [x, y] = reduceAspectRatio(ratio);
|
||||||
|
const useNative = supportsCSS(`aspect-ratio: ${x}/${y}`);
|
||||||
|
const padding = (100 / x) * y;
|
||||||
|
|
||||||
|
if (useNative) {
|
||||||
|
wrapper.style.aspectRatio = `${x}/${y}`;
|
||||||
|
} else {
|
||||||
|
wrapper.style.paddingBottom = `${padding}%`;
|
||||||
|
}
|
||||||
|
|
||||||
// For Vimeo we have an extra <div> to hide the standard controls and UI
|
// For Vimeo we have an extra <div> to hide the standard controls and UI
|
||||||
if (this.isVimeo && this.supported.ui) {
|
if (this.isVimeo && !this.config.vimeo.premium && this.supported.ui) {
|
||||||
const height = 240;
|
const height = (100 / this.media.offsetWidth) * parseInt(window.getComputedStyle(this.media).paddingBottom, 10);
|
||||||
const offset = (height - padding) / (height / 50);
|
const offset = (height - padding) / (height / 50);
|
||||||
|
|
||||||
|
if (this.fullscreen.active) {
|
||||||
|
wrapper.style.paddingBottom = null;
|
||||||
|
} else {
|
||||||
this.media.style.transform = `translateY(-${offset}%)`;
|
this.media.style.transform = `translateY(-${offset}%)`;
|
||||||
|
}
|
||||||
} else if (this.isHTML5) {
|
} else if (this.isHTML5) {
|
||||||
this.elements.wrapper.classList.toggle(this.config.classNames.videoFixedRatio, ratio !== null);
|
wrapper.classList.add(this.config.classNames.videoFixedRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { padding, ratio };
|
return { padding, ratio };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default { setAspectRatio };
|
// Round an aspect ratio to closest standard ratio
|
||||||
|
export function roundAspectRatio(x, y, tolerance = 0.05) {
|
||||||
|
const ratio = x / y;
|
||||||
|
const closestRatio = closest(Object.keys(standardRatios), ratio);
|
||||||
|
|
||||||
|
// Check match is within tolerance
|
||||||
|
if (Math.abs(closestRatio - ratio) <= tolerance) {
|
||||||
|
return standardRatios[closestRatio];
|
||||||
|
}
|
||||||
|
|
||||||
|
// No match
|
||||||
|
return [x, y];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the size of the viewport
|
||||||
|
// https://stackoverflow.com/questions/1248081/how-to-get-the-browser-viewport-dimensions
|
||||||
|
export function getViewportSize() {
|
||||||
|
const width = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
|
||||||
|
const height = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0);
|
||||||
|
return [width, height];
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,19 +5,19 @@
|
|||||||
import is from './is';
|
import is from './is';
|
||||||
|
|
||||||
// Time helpers
|
// Time helpers
|
||||||
export const getHours = value => Math.trunc((value / 60 / 60) % 60, 10);
|
export const getHours = (value) => Math.trunc((value / 60 / 60) % 60, 10);
|
||||||
export const getMinutes = value => Math.trunc((value / 60) % 60, 10);
|
export const getMinutes = (value) => Math.trunc((value / 60) % 60, 10);
|
||||||
export const getSeconds = value => Math.trunc(value % 60, 10);
|
export const getSeconds = (value) => Math.trunc(value % 60, 10);
|
||||||
|
|
||||||
// Format time to UI friendly string
|
// Format time to UI friendly string
|
||||||
export function formatTime(time = 0, displayHours = false, inverted = false) {
|
export function formatTime(time = 0, displayHours = false, inverted = false) {
|
||||||
// Bail if the value isn't a number
|
// Bail if the value isn't a number
|
||||||
if (!is.number(time)) {
|
if (!is.number(time)) {
|
||||||
return formatTime(null, displayHours, inverted);
|
return formatTime(undefined, displayHours, inverted);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format time component to add leading zero
|
// Format time component to add leading zero
|
||||||
const format = value => `0${value}`.slice(-2);
|
const format = (value) => `0${value}`.slice(-2);
|
||||||
// Breakdown to hours, mins, secs
|
// Breakdown to hours, mins, secs
|
||||||
let hours = getHours(time);
|
let hours = getHours(time);
|
||||||
const mins = getMinutes(time);
|
const mins = getMinutes(time);
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user