@flowplayer/player
Version:
video player for the future
2 lines (1 loc) • 6.74 kB
JavaScript
!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.speed=t())}(this,(function(){"use strict";class FlowplayerComponent extends HTMLElement{constructor(e){super(),this.player=e}}const e=(e,t)=>new(((e,t)=>{const n=e.get(t);if(!n)throw new Error(`no flowplayer component with the name ${t} exists`);const s=window.customElements.get(t);if(!s)throw new Error(`no default flowplayer component with the name ${t} exists`);const i=window.customElements.get(n);return"function"!=typeof i?s:i})(e._customElements,t))(e),t="fp-on",n="fp-invis";class FlowplayerMenu extends FlowplayerComponent{constructor(e){super(e),this.player=e,this.menuContainer=document.createElement("details"),this.summaryEle=document.createElement("summary"),this.menuHeader=document.createElement("div"),this.menuTitle=document.createElement("h3"),this.olEle=document.createElement("ol"),this.olEle.id=i(),this.menu=document.createElement("div"),this.closeEle=document.createElement("span"),this.menuHeader.classList.add("fp-menu-header"),this.menuHeader.append(this.menuTitle,this.closeEle),this.menu.classList.add("fp-menu"),this.menu.append(this.menuHeader,this.olEle),this.closeEle.classList.add("fp-close"),this.closeEle.textContent="×",this.menuContainer.classList.add("fp-menu-container"),this.menuContainer.append(this.summaryEle,this.menu),this.menuContainer.addEventListener("click",t=>{if(t.defaultPrevented)return;t.preventDefault();const n=this.menuContainer.open;n||(s(),document.active_menu=this.menuContainer),this.menuContainer.open=!n,e.root.classList.toggle("has-menu-opened",!n),this.summaryEle.setAttribute("aria-expanded",n?"false":"true")}),this.addEventListener("focusin",e=>{const t=e.target;t instanceof HTMLLIElement&&t.setAttribute("aria-selected","true")}),this.addEventListener("focusout",e=>{const t=e.target;t instanceof HTMLLIElement&&t.setAttribute("aria-selected","false")}),this.append(this.menuContainer),this.olEle.setAttribute("aria-labelledby",this.summaryEle.id),this.olEle.setAttribute("role","menu"),this.summaryEle.setAttribute("aria-haspopup","true"),this.summaryEle.setAttribute("aria-controls",this.olEle.id),this.summaryEle.setAttribute("tabindex","0"),this.summaryEle.setAttribute("aria-expanded","false"),this.summaryEle.setAttribute("role","button")}get options(){return this.olEle.querySelectorAll("li")}setMenuAttrs(t){if(this.className=t.class,this.toggle_visibility(!0),this.summaryEle.id||(this.summaryEle.id=t.id||i()),this.summaryEle.setAttribute("aria-label",t.menuTitle||"Menu"),t.summaryTitle&&(this.summaryEle.textContent=t.summaryTitle),t.summaryIcon){const n=e(this.player,t.summaryIcon);n.setAttribute("tabindex",""),this.summaryEle.append(n)}t.menuTitle&&(this.menuTitle.textContent=t.menuTitle),this.menu.classList.toggle("fp-icons",!!t.icons),this.addEventListener(t.options_event,e=>{this.render(e.data)}),t.item_selected_event&&this.addEventListener(t.item_selected_event,e=>{void 0!==e.data&&this.select_item(e.data.selected_index)})}render(e){this.olEle&&(this.olEle.innerHTML="",e&&e.forEach(this.menuOption,this),this.toggle_visibility(!(null==e?void 0:e.length)))}menuOption(e,t){const n=document.createElement("li");n.setAttribute("role","menuitem"),n.setAttribute("aria-selected","false"),n.setAttribute("tabindex","0"),e.icon&&n.append(e.icon);const s=document.createElement("span");s.textContent=e.text,n.append(s),n.addEventListener("click",()=>{this.select_item(t),"function"==typeof e.onclick&&e.onclick()}),this.olEle.appendChild(n),e.selected&&this.select_item(t)}select_item(e){this.options.forEach((n,s)=>{n.classList.toggle(t,s===e)})}unselect_item(){this.options.forEach(e=>{e.classList.remove(t)})}toggle_visibility(e){this.classList.toggle(n,e),this.menu.style.setProperty("display",e?"none":"flex")}}function s(){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))})}function i(){return Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5)}function o(e,t,n){const s=function(e,t){const n=new CustomEvent(e,{detail:t,cancelable:!0});return t&&Object.defineProperty(n,"data",{get:()=>t}),n}(t,n);return e.dispatchEvent(s),e}document.addEventListener("click",(function(e){this.active_menu&&!e.composedPath().includes(this.active_menu)&&(s(),this.active_menu=void 0)})),function(){let e=!1;try{const t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("testPassive",null,t),window.removeEventListener("testPassive",null,t)}catch(e){}}();const l="flowplayer-speed-menu";var r;const a=((r=class Speed{constructor(e){this.selectedRate=1,((e,t,n)=>{window.customElements.get(t)||window.customElements.define(t,n),e.customElements.get(t)||e.customElements.set(t,t)})(e,l,FlowplayerMenu)}init(t,n,s){let i=void 0;const a=e(s,l);a instanceof FlowplayerMenu&&a.setMenuAttrs({menuTitle:s.i18n("speed.menu_title"),summaryTitle:"1x",class:".fp-speed",options_event:r.events.OPTIONS,item_selected_event:r.events.SWITCH}),s.on("loadstart",()=>this.select_speed(s,this.selectedRate)),s.on("config",()=>{var e;const n=null===(e=t.speed)||void 0===e||e;if(n===i)return;if(i=n,0==n)return this.select_speed(s,1),o(a,r.events.OPTIONS,[]);const l="boolean"!=typeof n&&n.options?n.options:r.DEFAULT_SPEED_OPTIONS,u="boolean"!=typeof n&&n.labels?n.labels:[];Array.isArray(l)&&(o(a,r.events.OPTIONS,Array.from({length:l.length}).map((e,t)=>{const n=l[t];return{text:u[t]||n+"x",onclick:this.select_speed.bind(this,s,n)}})),o(a,r.events.SWITCH,{selected_index:l.findIndex(e=>1===e)}))}),s.on("mount",(function(){var e;null===(e=function(e,t){const n=e._customElements.get(t);return n&&e.root.querySelector(n)||void 0}(s,s.hasState("is-tv")?"flowplayer-tv-menu":"flowplayer-control"))||void 0===e||e.append(a)}))}select_speed(e,t){var n;if(isNaN(t))return;const s=null===(n=e.root.querySelector(l))||void 0===n?void 0:n.summaryEle;s&&(s.textContent=t+"x"),e.playbackRate=this.selectedRate=t}}).pluginName="speed",r.DEFAULT_SPEED_OPTIONS=[.2,.5,1,2,10],r.events={OPTIONS:"speed:options",SWITCH:"speed:switch"},r);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)}));