diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/js/plyr.js | 128 | ||||
-rw-r--r-- | src/less/plyr.less | 227 |
2 files changed, 214 insertions, 141 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js index 6cf4d5b9..5c0378db 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -40,7 +40,7 @@ volumeStep: 1, defaultSpeed: 1.0, currentSpeed: 1.0, - speeds: [ 0.5, 1.0, 1.5, 2.0 ], + speeds: [0.5, 1.0, 1.5, 2.0], duration: null, displayDuration: true, loadSprite: true, @@ -806,7 +806,7 @@ // Restart button if (_inArray(config.controls, 'restart')) { html.push( - '<button type="button" data-plyr="restart">', + '<button type="button" class="plyr__control" data-plyr="restart">', '<svg><use xlink:href="' + iconPath + '-restart" /></svg>', '<span class="plyr__sr-only">' + config.i18n.restart + '</span>', '</button>' @@ -816,7 +816,7 @@ // Rewind button if (_inArray(config.controls, 'rewind')) { html.push( - '<button type="button" data-plyr="rewind">', + '<button type="button" class="plyr__control" data-plyr="rewind">', '<svg><use xlink:href="' + iconPath + '-rewind" /></svg>', '<span class="plyr__sr-only">' + config.i18n.rewind + '</span>', '</button>' @@ -827,11 +827,11 @@ // TODO: This should be a toggle button really? if (_inArray(config.controls, 'play')) { html.push( - '<button type="button" data-plyr="play">', + '<button type="button" class="plyr__control" data-plyr="play">', '<svg><use xlink:href="' + iconPath + '-play" /></svg>', '<span class="plyr__sr-only">' + config.i18n.play + '</span>', '</button>', - '<button type="button" data-plyr="pause">', + '<button type="button" class="plyr__control" data-plyr="pause">', '<svg><use xlink:href="' + iconPath + '-pause" /></svg>', '<span class="plyr__sr-only">' + config.i18n.pause + '</span>', '</button>' @@ -841,7 +841,7 @@ // Fast forward button if (_inArray(config.controls, 'fast-forward')) { html.push( - '<button type="button" data-plyr="fast-forward">', + '<button type="button" class="plyr__control" data-plyr="fast-forward">', '<svg><use xlink:href="' + iconPath + '-fast-forward" /></svg>', '<span class="plyr__sr-only">' + config.i18n.forward + '</span>', '</button>' @@ -891,7 +891,7 @@ // Toggle mute button if (_inArray(config.controls, 'mute')) { html.push( - '<button type="button" data-plyr="mute">', + '<button type="button" class="plyr__control" data-plyr="mute">', '<svg class="icon--muted"><use xlink:href="' + iconPath + '-muted" /></svg>', '<svg><use xlink:href="' + iconPath + '-volume" /></svg>', '<span class="plyr__sr-only">' + config.i18n.toggleMute + '</span>', @@ -913,7 +913,7 @@ // Toggle captions button if (_inArray(config.controls, 'captions')) { html.push( - '<button type="button" data-plyr="captions">', + '<button type="button" class="plyr__control" data-plyr="captions">', '<svg class="icon--captions-on"><use xlink:href="' + iconPath + '-captions-on" /></svg>', '<svg><use xlink:href="' + iconPath+ '-captions-off" /></svg>', '<span class="plyr__sr-only">' + config.i18n.toggleCaptions + '</span>', @@ -925,7 +925,7 @@ if (_inArray(config.controls, 'settings')) { html.push( '<div class="plyr__menu" data-plyr="settings">', - '<button type="button" id="plyr-settings-toggle-{id}" aria-haspopup="true" aria-controls="plyr-settings-{id}" aria-expanded="false">', + '<button type="button" id="plyr-settings-toggle-{id}" class="plyr__control" aria-haspopup="true" aria-controls="plyr-settings-{id}" aria-expanded="false">', '<svg><use xlink:href="' + iconPath + '-settings" /></svg>', '<span class="plyr__sr-only">' + config.i18n.settings + '</span>', '</button>', @@ -934,18 +934,18 @@ '<div class="plyr__menu__primary" id="plyr-settings-{id}-primary" aria-hidden="false" aria-labelled-by="plyr-settings-toggle-{id}" role="tabpanel" tabindex="-1">', '<ul>', '<li role="tab">', - '<button type="button" class="plyr__menu__btn plyr__menu__btn--forward" id="plyr-settings-{id}-captions-toggle" aria-haspopup="true" aria-controls="plyr-settings-{id}-captions" aria-expanded="false">', - config.i18n.captions + ' <span class="plyr__menu__btn__value">{lang}</span>', + '<button type="button" class="plyr__control plyr__control--forward" id="plyr-settings-{id}-captions-toggle" aria-haspopup="true" aria-controls="plyr-settings-{id}-captions" aria-expanded="false">', + config.i18n.captions + ' <span class="plyr__menu__value">{lang}</span>', '</button>', '</li>', '<li role="tab">', - '<button type="button" class="plyr__menu__btn plyr__menu__btn--forward" id="plyr-settings-{id}-speed-toggle" aria-haspopup="true" aria-controls="plyr-settings-{id}-speed" aria-expanded="false">', - config.i18n.speed + ' <span class="plyr__menu__btn__value">{speed}</span>', + '<button type="button" class="plyr__control plyr__control--forward" id="plyr-settings-{id}-speed-toggle" aria-haspopup="true" aria-controls="plyr-settings-{id}-speed" aria-expanded="false">', + config.i18n.speed + ' <span class="plyr__menu__value">{speed}</span>', '</button>', '</li>', '<li role="tab">', - '<button type="button" class="plyr__menu__btn plyr__menu__btn--forward" id="plyr-settings-{id}-quality-toggle" aria-haspopup="true" aria-controls="plyr-settings-{id}-quality" aria-expanded="false">', - config.i18n.quality + ' <span class="plyr__menu__btn__value">Auto</span>', + '<button type="button" class="plyr__control plyr__control--forward" id="plyr-settings-{id}-quality-toggle" aria-haspopup="true" aria-controls="plyr-settings-{id}-quality" aria-expanded="false">', + config.i18n.quality + ' <span class="plyr__menu__value">Auto</span>', '</button>', '</li>', '</ul>', @@ -953,59 +953,95 @@ '<div class="plyr__menu__secondary" id="plyr-settings-{id}-captions" aria-hidden="true" aria-labelled-by="plyr-settings-{id}-captions-toggle" role="tabpanel" tabindex="-1">', '<ul>', '<li role="tab">', - '<button type="button" class="plyr__menu__btn plyr__menu__btn--back" aria-haspopup="true" aria-controls="plyr-settings-{id}-primary" aria-expanded="false">', + '<button type="button" class="plyr__control plyr__control--back" aria-haspopup="true" aria-controls="plyr-settings-{id}-primary" aria-expanded="false">', config.i18n.captions, '</button>', '</li>', '<li>', - '<button type="button">English</button>', + '<button type="button" class="plyr__control">English</button>', '</li>', '<li>', - '<button type="button">Off</button>', + '<button type="button" class="plyr__control">Off</button>', '</li>', '</ul>', '</div>', '<div class="plyr__menu__secondary" id="plyr-settings-{id}-speed" aria-hidden="true" aria-labelled-by="plyr-settings-{id}-speed-toggle" role="tabpanel" tabindex="-1">', '<ul>', '<li role="tab">', - '<button type="button" class="plyr__menu__btn plyr__menu__btn--back" aria-haspopup="true" aria-controls="plyr-settings-{id}-primary" aria-expanded="false">', + '<button type="button" class="plyr__control plyr__control--back" aria-haspopup="true" aria-controls="plyr-settings-{id}-primary" aria-expanded="false">', config.i18n.speed, '</button>', '</li>', '<li>', - '<button type="button">2×</button>', + '<button type="button" class="plyr__control">2×</button>', '</li>', '<li>', - '<button type="button">1.5×</button>', + '<button type="button" class="plyr__control">1.5×</button>', '</li>', '<li>', - '<button type="button">1×</button>', + '<button type="button" class="plyr__control">1×</button>', '</li>', '<li>', - '<button type="button">0.5×</button>', + '<button type="button" class="plyr__control">0.5×</button>', '</li>', '</ul>', '</div>', '<div class="plyr__menu__secondary" id="plyr-settings-{id}-quality" aria-hidden="true" aria-labelled-by="plyr-settings-{id}-quality-toggle" role="tabpanel" tabindex="-1">', '<ul>', '<li role="tab">', - '<button type="button" class="plyr__menu__btn plyr__menu__btn--back" aria-haspopup="true" aria-controls="plyr-settings-{id}-primary" aria-expanded="false">', + '<button type="button" class="plyr__control plyr__control--back" aria-haspopup="true" aria-controls="plyr-settings-{id}-primary" aria-expanded="false">', config.i18n.quality, '</button>', '</li>', '<li>', - '<button type="button">1080P <span class="plyr__menu__btn__badge"><span>HD</span></span></button>', + '<label class="plyr__control">', + '<input type="radio" name="quality">', + '2160P', + '<span class="plyr__menu__value">', + '<span class="plyr__badge">4K</span>', + '</span>', + '</label>', '</li>', '<li>', - '<button type="button">720P <span class="plyr__menu__btn__badge"><span>HD</span></span></button>', + '<label class="plyr__control">', + '<input type="radio" name="quality">', + '1440P', + '<span class="plyr__menu__value">', + '<span class="plyr__badge">WQHD</span>', + '</span>', + '</label>', '</li>', '<li>', - '<button type="button">480P</button>', + '<label class="plyr__control">', + '<input type="radio" name="quality">', + '1080P', + '<span class="plyr__menu__value">', + '<span class="plyr__badge">HD</span>', + '</span>', + '</label>', '</li>', '<li>', - '<button type="button">320P</button>', + '<label class="plyr__control">', + '<input type="radio" name="quality">', + '720P', + '<span class="plyr__menu__value">', + '<span class="plyr__badge">HD</span>', + '</span>', + '</label>', '</li>', - '</ul>', + '<li>', + '<label class="plyr__control">', + '<input type="radio" name="quality">', + '480P', + '</label>', + '</li>', + '<li>', + '<label class="plyr__control">', + '<input type="radio" name="quality">', + '360P', + '</label>', + '</li>', + '</ul>', '</div>', '</div>', '</div>', @@ -1016,7 +1052,7 @@ // Picture in picture button if (_inArray(config.controls, 'pip') && _support.pip) { html.push( - '<button type="button" data-plyr="pip">', + '<button type="button" class="plyr__control" data-plyr="pip">', '<svg><use xlink:href="' + iconPath + '-pip" /></svg>', '<span class="plyr__sr-only">PIP</span>', '</button>' @@ -1026,7 +1062,7 @@ // Airplay button if (_inArray(config.controls, 'airplay') && _support.airplay) { html.push( - '<button type="button" data-plyr="airplay">', + '<button type="button" class="plyr__control" data-plyr="airplay">', '<svg><use xlink:href="' + iconPath + '-airplay" /></svg>', '<span class="plyr__sr-only">AirPlay</span>', '</button>' @@ -1036,7 +1072,7 @@ // Toggle fullscreen button if (_inArray(config.controls, 'fullscreen')) { html.push( - '<button type="button" data-plyr="fullscreen">', + '<button type="button" class="plyr__control" data-plyr="fullscreen">', '<svg class="icon--exit-fullscreen"><use xlink:href="' + iconPath + '-exit-fullscreen" /></svg>', '<svg><use xlink:href="' + iconPath + '-enter-fullscreen" /></svg>', '<span class="plyr__sr-only">' + config.i18n.toggleFullscreen + '</span>', @@ -1847,6 +1883,15 @@ embed: event.target }); }, + 'onPlaybackQualityChange': function(event) { + // Get the instance + var instance = event.target; + + var quality = instance.getPlaybackQuality(); + + // var set = instance.setPlaybackQuality(); + console.warn(quality); + }, 'onReady': function(event) { // Get the instance var instance = event.target; @@ -1869,6 +1914,12 @@ plyr.media.currentTime = 0; plyr.media.muted = instance.isMuted(); + // Get available speeds + var speed = instance.getPlaybackRate(); + var speedOptions = instance.getAvailablePlaybackRates(); + //var set = instance.setPlaybackRate(); + console.warn(speed, speedOptions); + // Set title config.title = instance.getVideoData().title; @@ -1960,6 +2011,10 @@ _triggerEvent(plyr.media, 'durationchange'); } + // Get quality + var qualityOptions = instance.getAvailableQualityLevels(); + console.warn(qualityOptions, event.data); + break; case 2: @@ -3193,6 +3248,15 @@ if (pressed) { // Which keycodes should we prevent default var preventDefault = [48,49,50,51,52,53,54,56,57,32,75,38,40,77,39,37,70,67]; + var checkFocus = [38,40]; + + if (_inArray(checkFocus, code)) { + var focused = getFocusElement(); + + if (_is.htmlElement(focused) && getFocusElement().type === "radio") { + return; + } + } // If the code is found prevent default (e.g. prevent scrolling for arrows) if (_inArray(preventDefault, code)) { diff --git a/src/less/plyr.less b/src/less/plyr.less index 6bf8345b..76d46dbe 100644 --- a/src/less/plyr.less +++ b/src/less/plyr.less @@ -285,7 +285,7 @@ text-align: center; // Spacing - > button, + > .plyr__control, .plyr__progress, .plyr__time, .plyr__menu { @@ -302,52 +302,19 @@ margin-left: 0; } - // Buttons - button { - position: relative; - display: inline-block; - flex-shrink: 0; - overflow: visible; // IE11 - vertical-align: middle; - padding: @plyr-control-padding; - border: 0; - background: transparent; - border-radius: 3px; - cursor: pointer; - transition: background .3s ease, color .3s ease, opacity .3s ease; - color: inherit; - - svg { - width: @plyr-control-icon-size; - height: @plyr-control-icon-size; - display: block; - fill: currentColor; - } - // Default focus - &:focus { - outline: 0; - } - } - - // Hide toggle icons by default - .icon--exit-fullscreen, - .icon--muted, - .icon--captions-on { - display: none; - } @media (min-width: @plyr-bp-screen-sm) { - > button, + > .plyr__control, .plyr__progress, .plyr__time, .plyr__menu { margin-left: @plyr-control-spacing; } - > button + button, - .plyr__menu + button, - > button + .plyr__menu { + > .plyr__control + .plyr__control, + .plyr__menu + .plyr__control, + > .plyr__control + .plyr__menu { margin-left: (@plyr-control-spacing / 2); } } @@ -358,6 +325,40 @@ pointer-events: none; } +// Buttons +.plyr__control { + position: relative; + display: inline-block; + flex-shrink: 0; + overflow: visible; // IE11 + vertical-align: middle; + padding: @plyr-control-padding; + border: 0; + background: transparent; + border-radius: 3px; + cursor: pointer; + transition: background .3s ease, color .3s ease, opacity .3s ease; + color: inherit; + + svg { + width: @plyr-control-icon-size; + height: @plyr-control-icon-size; + display: block; + fill: currentColor; + } + // Hide toggle icons by default + .icon--exit-fullscreen, + .icon--muted, + .icon--captions-on { + display: none; + } + + // Default focus + &:focus { + outline: 0; + } +} + // Video controls .plyr--video .plyr__controls { position: absolute; @@ -371,7 +372,7 @@ color: @plyr-video-control-color; transition: opacity .3s ease; - button { + .plyr__control { // Hover and tab focus &.tab-focus:focus, &:hover, @@ -390,7 +391,7 @@ border: @plyr-audio-controls-border; color: @plyr-audio-control-color; - button { + .plyr__control { // Hover and tab focus &.tab-focus:focus, &:hover, @@ -451,9 +452,9 @@ } // Change icons on state change -.plyr--fullscreen-active .icon--exit-fullscreen, -.plyr--muted .plyr__controls .icon--muted, -.plyr--captions-active .plyr__controls .icon--captions-on { +.plyr--fullscreen-active .plyr__control .icon--exit-fullscreen, +.plyr--muted .plyr__control .icon--muted, +.plyr--captions-active .plyr__control .icon--captions-on { display: block; & + svg { @@ -477,10 +478,10 @@ position: relative; // Hide tooltip - button svg { + .plyr__control svg { transition: transform .3s ease; } - button[aria-expanded='true'] { + .plyr__control[aria-expanded='true'] { svg { transform: rotate(45deg); } @@ -529,94 +530,102 @@ list-style: none; overflow: hidden; } - button { + + // Options + .plyr__control { display: flex; width: 100%; padding: @plyr-control-padding (@plyr-control-padding * 2); color: @plyr-menu-color; font-weight: 600; user-select: none; - } - - // Buttons - .plyr__menu__btn::after { - content: ""; - position: absolute; - top: 50%; - transform: translateY(-50%); - border: 5px solid transparent; - } - .plyr__menu__btn--forward { - padding-right: ceil(@plyr-control-padding * 4); &::after { - right: 5px; - border-left-color: fade(@plyr-menu-color, 80%); + content: ""; + position: absolute; + top: 50%; + transform: translateY(-50%); + border: 5px solid transparent; + } + + &--forward { + padding-right: ceil(@plyr-control-padding * 4); + + &::after { + right: 5px; + border-left-color: fade(@plyr-menu-color, 80%); + } + } + + &--back { + position: relative; + padding-top: floor(@plyr-control-padding * .7); + padding-bottom: floor(@plyr-control-padding * .7); + padding-left: ceil(@plyr-control-padding * 4); + margin-bottom: ceil(@plyr-control-padding * 1.3); + font-weight: 500; + + &::after { + left: 5px; + border-right-color: fade(@plyr-menu-color, 80%); + } + &::before { + content: ""; + position: absolute; + top: 100%; + left: 0; + right: 0; + height: 1px; + overflow: hidden; + margin-top: ceil(@plyr-control-padding / 2); + background: fade(#000, 15%); + box-shadow: 0 1px 0 fade(#fff, 10%); + } } } - .plyr__menu__btn--back { - position: relative; - padding-top: floor(@plyr-control-padding * .7); - padding-bottom: floor(@plyr-control-padding * .7); - padding-left: ceil(@plyr-control-padding * 4); - margin-bottom: ceil(@plyr-control-padding * 1.3); - font-weight: 500; - &::after { - left: 5px; - border-right-color: fade(@plyr-menu-color, 80%); - } - &::before { - content: ""; - position: absolute; - top: 100%; - left: 0; - right: 0; - height: 1px; - overflow: hidden; - margin-top: ceil(@plyr-control-padding / 2); - background: fade(#000, 15%); - box-shadow: 0 1px 0 fade(#fff, 10%); + label.plyr__control { + padding-left: ceil(@plyr-control-padding * 2.5); + + input[type="radio"] { + position: relative; + left: -@plyr-control-padding; } } // Option value - .plyr__menu__btn__value, - .plyr__menu__btn__badge { + .plyr__menu__value { display: inherit; margin-left: auto; padding-left: ceil(@plyr-control-padding * 3.5); pointer-events: none; overflow: hidden; - } - - // Option value - .plyr__menu__btn__value { font-weight: 500; color: fade(@plyr-menu-color, 80%); - } - // Option value - .plyr__menu__btn__badge span { - padding: 2px 4px; - border-radius: 2px; - background: @plyr-menu-color; - color: @plyr-menu-bg; - font-size: 10px; + .plyr__badge { + font-weight: 600; + } } // When animating between menus &.is-resizing { overflow: hidden; transition: height .35s cubic-bezier(.4,0,.2,1), width .35s cubic-bezier(.4,0,.2,1); - - ul { - //opacity: 0; - } } } } +// Badge +// -------------------------------------------------------------- +.plyr__badge { + padding: 2px 4px; + border-radius: 2px; + background: @plyr-menu-color; + color: @plyr-menu-bg; + font-size: 10px; +} + // Tooltips // -------------------------------------------------------------- .plyr__tooltip { @@ -657,19 +666,19 @@ z-index: 2; } } -.plyr button:hover .plyr__tooltip, -.plyr button.tab-focus:focus .plyr__tooltip, +.plyr .plyr__control:hover .plyr__tooltip, +.plyr .plyr__control.tab-focus:focus .plyr__tooltip, .plyr__tooltip--visible { opacity: 1; transform: translate(-50%, 0) scale(1); } -.plyr button:hover .plyr__tooltip { +.plyr .plyr__control:hover .plyr__tooltip { z-index: 3; } // First tooltip -.plyr__controls > button:first-child .plyr__tooltip, -.plyr__controls > button:first-child + button .plyr__tooltip { +.plyr__controls > .plyr__control:first-child .plyr__tooltip, +.plyr__controls > .plyr__control:first-child + .plyr__control .plyr__tooltip { left: 0; transform: translate(0, 10px) scale(.8); transform-origin: 0 100%; @@ -680,7 +689,7 @@ } // Last tooltip -.plyr__controls > button:last-child .plyr__tooltip { +.plyr__controls > .plyr__control:last-child .plyr__tooltip { right: 0; transform: translate(0, 10px) scale(.8); transform-origin: 100% 100%; @@ -692,9 +701,9 @@ } } -.plyr__controls > button:first-child, -.plyr__controls > button:first-child + button, -.plyr__controls > button:last-child { +.plyr__controls > .plyr__control:first-child, +.plyr__controls > .plyr__control:first-child + .plyr__control, +.plyr__controls > .plyr__control:last-child { &:hover .plyr__tooltip, &.tab-focus:focus .plyr__tooltip, .plyr__tooltip--visible { |