diff options
author | Sam Potts <me@sampotts.me> | 2017-04-17 01:28:52 +1000 |
---|---|---|
committer | Sam Potts <me@sampotts.me> | 2017-04-17 01:28:52 +1000 |
commit | 9b2396f5ff266284bb6c526413d14b075e131d3d (patch) | |
tree | 3694c663ecd2d179bb4696817f2e7a200e58a7eb /src/js/plyr.js | |
parent | da15980b8a94fdee7c7e1bf1548d1400cc81fcb0 (diff) | |
download | plyr-9b2396f5ff266284bb6c526413d14b075e131d3d.tar.lz plyr-9b2396f5ff266284bb6c526413d14b075e131d3d.tar.xz plyr-9b2396f5ff266284bb6c526413d14b075e131d3d.zip |
Airplay and PiP
Diffstat (limited to 'src/js/plyr.js')
-rw-r--r-- | src/js/plyr.js | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js index aa1163d0..42124ea4 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -150,6 +150,10 @@ enabled: 'plyr--pip-enabled', active: 'plyr--pip-active' }, + airplay: { + enabled: 'plyr--airplay-enabled', + active: 'plyr--airplay-active' + }, tabFocus: 'tab-focus' }, captions: { @@ -609,6 +613,19 @@ return matches.call(element, selector); } + // Get the focused element + function getFocusElement() { + var focused = document.activeElement; + + if (!focused || focused === document.body) { + focused = null; + } else { + focused = document.querySelector(':focus'); + } + + return focused; + } + // Bind along with custom handler function proxy(element, eventName, customListener, defaultListener, useCapture) { on(element, eventName, function(event) { @@ -2399,7 +2416,10 @@ } // Check for picture-in-picture support - toggleClass(player.elements.container, config.classes.pip.enabled, support.pip); + toggleClass(player.elements.container, config.classes.pip.enabled, support.pip && player.type === 'video'); + + // Check for airplay support + toggleClass(player.elements.container, config.classes.airplay.enabled, support.airplay && player.type === 'video'); // If there's no autoplay attribute, assume the video is stopped and add state class toggleClass(player.elements.container, config.classes.stopped, config.autoplay); @@ -3922,19 +3942,6 @@ } } - // Get the focused element - function getFocusElement() { - var focused = document.activeElement; - - if (!focused || focused === document.body) { - focused = null; - } else { - focused = document.querySelector(':focus'); - } - - return focused; - } - // Get the key code for an event function getKeyCode(event) { return event.keyCode ? event.keyCode : event.which; @@ -4174,10 +4181,20 @@ // Picture-in-Picture proxy(player.elements.buttons.pip, 'click', config.listeners.pip, function(event) { - // TODO: Check support here + if (!support.pip) { + return; + } player.elements.media.webkitSetPresentationMode(player.elements.media.webkitPresentationMode === 'picture-in-picture' ? 'inline' : 'picture-in-picture'); }); + // Airplay + proxy(player.elements.buttons.airplay, 'click', config.listeners.airplay, function(event) { + if (!support.airplay) { + return; + } + player.elements.media.webkitShowPlaybackTargetPicker(); + }); + // Settings menu on(player.elements.settings.menu, 'click', function(event) { // Settings menu |