UNPKG

@flowplayer/player

Version:
2 lines (1 loc) 5.79 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).flowplayer=e.flowplayer||{},e.flowplayer.keyboard=t())}(this,(function(){"use strict";function e(e,t,n){const o=function(e){return Array.isArray(e)?e.slice(0):e.split(".")}(t);for(;o.length;){if(null==e)return n;const t=o.shift();if("string"!=typeof t)return n;e=e[t]}return null==e?n:e}var t={TAB:"Tab",ENTER:"Enter",ESCAPE:"Escape",SPACE:" ",ARROW_LEFT:"ArrowLeft",ARROW_UP:"ArrowUp",ARROW_RIGHT:"ArrowRight",ARROW_DOWN:"ArrowDown",F:"f",H:"h",J:"j",K:"k",L:"l",M:"m"};function n(){Array.from(document.querySelectorAll(".fp-engine")).forEach(e=>{var t;const n=e.root.querySelector("details[open].fp-menu-container");n&&(n.open=!1,null===(t=n.querySelector("summary"))||void 0===t||t.removeAttribute("aria-expanded"),e.root.classList.toggle("has-menu-opened",!1))})}document.addEventListener("click",(function(e){this.active_menu&&!e.composedPath().includes(this.active_menu)&&(n(),this.active_menu=void 0)}));let o=void 0;function r(e){e.setState("is-kb-active",!0),clearTimeout(o),o=setTimeout((function(){e.setState("is-kb-active",!1)}),2500)}function i(e,t){e.enqueueSeek(t)&&r(e)}const u="flowplayer-ad-ui";var s;const a=[t.ARROW_UP,t.ARROW_RIGHT,t.ARROW_LEFT,t.ARROW_DOWN],c=[t.SPACE,t.F,t.ESCAPE,t.M,t.ARROW_UP,t.ARROW_DOWN,t.ARROW_RIGHT,t.ARROW_LEFT,t.H,t.J,t.K,t.L];function l(e,t){e.volume=function(e,t,n=0){return Math.max(Math.min(t,e),n)}(e.volume+t,1,0),r(e)}function f(e){e.preventDefault(),e.stopPropagation()}function d(o){const r=o.key,s=R(),d=document.activeElement;if(!d)return;if(r===t.TAB)return function(){var e,t,n;const o=document.activeElement;if(!o)return;const r=null===(e=o.closest(".flowplayer"))||void 0===e?void 0:e.querySelector(".fp-engine");if(y().forEach(e=>{e.root.hasFocus=r===e,e.setState("is-accessibility",r===e)}),!r)return;if(r.root.dispatchEvent(new Event("mousemove")),!function(e){var t,n;return!(!e.hasState("ad-paused")&&!e.hasState("ad-playing")||!(null===(n=null===(t=null==e?void 0:e.ads)||void 0===t?void 0:t.adapter)||void 0===n?void 0:n.isLinearAd()))}(r)||m(o,u))return;const i=r.root.querySelector(u);if(!i)return;if(r.hasState("ad-playing"))return null===(t=i.querySelector(".fp-small-pause"))||void 0===t?void 0:t.focus();if(r.hasState("ad-paused"))return null===(n=i.querySelector(".fp-small-play"))||void 0===n?void 0:n.focus()}();if((r===t.SPACE||r===t.ENTER)&&d.hasAttribute("tabindex")&&(m(d,".flowplayer")||m(d,"flowplayer-playlist-controls")))return null==d||d.dispatchEvent(new CustomEvent("click",{cancelable:!0,bubbles:!0})),f(o);if((r===t.ARROW_DOWN||r===t.ARROW_UP||r===t.ESCAPE)&&(m(d,".fp-menu-container")||m(d,"flowplayer-playlist-controls"))){if(r===t.ARROW_DOWN&&d.nextSibling)return d.nextSibling.focus();if(r===t.ARROW_UP&&d.previousSibling)return d.previousSibling.focus();if(r===t.ESCAPE){const e=new CustomEvent("keyboard:close:menus",{cancelable:!0});if(null==s||s.dispatchEvent(e),e.defaultPrevented)return;return n()}}if(!s)return;let p=e(s,"opts.keyboard.seek_step",5);if(p<1&&(p=Math.round(p*s.duration)),~a.indexOf(r)&&d.hasAttribute("aria-valuenow")){const e=~[t.ARROW_UP,t.ARROW_RIGHT].indexOf(r);if(d.matches(".fp-volume"))return l(s,e?.15:-.15),f(o);if(d.matches(".fp-timeline"))return i(s,e?p:-1*p),f(o)}if(!1===function(e,t){return!(t.altKey||t.shiftKey||t.metaKey||t.ctrlKey)&&(!!(e&&e.hasState("is-in-viewport")&&e.started)&&(!!e.root&&void 0))}(s,o))return;const A=!s.hasState("no-timeline");switch(~c.indexOf(r)&&o.preventDefault(),r){case t.SPACE:return s.togglePlay();case t.F:return s.toggleFullScreen();case t.ESCAPE:return s.hasState("is-fullscreen")?s.toggleFullScreen(!1):void 0;case t.M:return s.toggleMute();case t.ARROW_UP:case t.K:return l(s,.15);case t.ARROW_DOWN:case t.J:return l(s,-.15);case t.ARROW_RIGHT:case t.L:return A&&i(s,p);case t.ARROW_LEFT:case t.H:return A&&i(s,-1*p)}}function p(e){setTimeout((function(){e.defaultPrevented||d(e)}),0)}function R(){return y().find(e=>function(e){let t=document.activeElement;for(;t;){if(t===e)return!0;t=t.parentElement}return!1}(e.root))||y().find(e=>document.activeElement===document.body&&e.root.hasFocus)}function y(){return Array.from(document.querySelectorAll(".fp-engine"))}function m(e,t){return!!function(e,t){return e.closest(t)}(e,t)}document.addEventListener("keydown",(function(e){if(e.key===t.TAB)return p(e);const n=R();if(n)return function(e,n){const o=document.activeElement;if(e.key===t.F&&n.root.classList.contains("no-fullscreen"))return;if([t.SPACE,t.ARROW_DOWN,t.ARROW_UP,t.ARROW_RIGHT,t.ARROW_LEFT].includes(e.key)||o&&m(o,".fp-menu-container")&&e.key===t.ENTER)return e.preventDefault(),d(e);p(e)}(e,n);const o=document.activeElement;[t.SPACE,t.ENTER,t.ARROW_DOWN,t.ARROW_UP,t.ARROW_RIGHT,t.ARROW_LEFT].includes(e.key)&&o&&m(o,"flowplayer-playlist-controls")&&(e.preventDefault(),d(e))})),document.addEventListener("mousedown",(function(e){const t=e.composedPath();y().forEach(e=>{e.setState("is-accessibility",!1),e.root.hasFocus=t.includes(e.root)})}));const A=((s=class Keyboard{init(e,t,n){n.once("beforeplay",()=>{n===R()&&n.hasState("is-accessibility")&&n.once("playing",()=>{if(n!==R()||!n.hasState("is-accessibility"))return;const e=n.root.querySelector(".fp-small-pause");e&&(n.root.dispatchEvent(new Event("mousemove")),e.focus())})})}}).pluginName="keyboard",s);return function(e,t){if("object"==typeof exports&&"undefined"!=typeof module)return t;if(null===document.currentScript)return t;"flowplayer"in e||(e.flowplayer={extensions:[]});const n=e.flowplayer;return"function"==typeof n?(n(t),t):(Array.isArray(n.extensions)||(n.extensions=[]),~n.extensions.indexOf(t)||n.extensions.push(t),t)}(window,A)}));