@flowplayer/player
Version:
video player for the future
2 lines (1 loc) • 8.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.asel=t())}(this,(function(){"use strict";const e="audio:set",t="audio:tracks";var n=Object.freeze({__proto__:null,SET:e,SWITCH:"audio:update",TRACKS:t});function s(e,t,n){const s=function(e){return Array.isArray(e)?e.slice(0):e.split(".")}(t);for(;s.length;){if(null==e)return n;const t=s.shift();if("string"!=typeof t)return n;e=e[t]}return null==e?n:e}const i=navigator.languages||[navigator.language];function o(t,n){t.emit(e,n),n.autoselect&&t._storage.setItem("@flowplayer/audio/track",n.lang)}function a(e){return e.toLowerCase()}function r(e,t,n){t=t.slice(0);const o={},r=e.getItem("@flowplayer/audio/track");let l=function(){try{return i.reduce((e,t)=>~t.indexOf("-")?e.concat(t,t.split("-")[0]):e.concat(t),[])}catch(e){return[]}}().map(a),c=-1;if("number"==typeof n)return n;for("string"==typeof n&&(n=n.toLowerCase(),~l.indexOf(n)&&l.splice(l.indexOf(n),1),l.unshift(a(n))),Array.isArray(n)&&(l=n.map(a));t.length;){++c;const e=t.shift();if(null==e?void 0:e.autoselect){if(r==e.lang)return console.debug("restoring lang from previous session: ",r),c;if(e.default&&(o.fallback=[c,e]),e.lang&&~l.indexOf(e.lang.toLowerCase())){const t=l.indexOf(e.lang);if(t<s(o,"by_lang.2",1/0)&&(o.by_lang=[c,e,t]),0===t)break}}}return s(o,"by_lang.0",s(o,"fallback.0",void 0))}const l=(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);class FlowplayerComponent extends HTMLElement{constructor(e){super(),this.player=e}}const c="fp-on",u="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=m(),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||(d(),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(e){if(this.className=e.class,this.toggle_visibility(!0),this.summaryEle.id||(this.summaryEle.id=e.id||m()),this.summaryEle.setAttribute("aria-label",e.menuTitle||"Menu"),e.summaryTitle&&(this.summaryEle.textContent=e.summaryTitle),e.summaryIcon){const t=l(this.player,e.summaryIcon);t.setAttribute("tabindex",""),this.summaryEle.append(t)}e.menuTitle&&(this.menuTitle.textContent=e.menuTitle),this.menu.classList.toggle("fp-icons",!!e.icons),this.addEventListener(e.options_event,e=>{this.render(e.data)}),e.item_selected_event&&this.addEventListener(e.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((t,n)=>{t.classList.toggle(c,n===e)})}unselect_item(){this.options.forEach(e=>{e.classList.remove(c)})}toggle_visibility(e){this.classList.toggle(u,e),this.menu.style.setProperty("display",e?"none":"flex")}}function d(){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 m(){return Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5)}function f(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)&&(d(),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){}}();var p;const h=((p=class Asel{constructor(e){((e,t,n)=>{window.customElements.get(t)||window.customElements.define(t,n),e.customElements.get(t)||e.customElements.set(t,t)})(e,"flowplayer-audio-menu",FlowplayerMenu)}init(i,a,c){if(!1===i.asel)return;let u=[];const d=l(c,"flowplayer-audio-menu");d instanceof FlowplayerMenu&&d.setMenuAttrs({summaryTitle:c.i18n("audio.button_txt"),menuTitle:c.i18n("audio.menu_title"),class:"fp-asel",options_event:p.events.TRACKS,item_selected_event:p.events.SWITCH});const m=function(t){const s={tracks:[],events:n};return Object.assign(s,{set:function(n){if(!("number"!=typeof n||n<0||n>s.tracks.length-1))return t.emit(e,s.tracks[n]),s},get:function(e){if("number"==typeof e)return s.tracks[e]}}),s}(c);c.asel=m,c.on("mount",(function(){var e;null===(e=function(e,t){const n=e._customElements.get(t);return n&&e.root.querySelector(n)||void 0}(c,c.hasState("is-tv")?"flowplayer-tv-menu":"flowplayer-control"))||void 0===e||e.append(d)})),c.on("src",()=>{m.tracks=[],m.active_track=void 0,f(d,p.events.TRACKS,[])}),c.on(t,(function(e){if(!Array.isArray(e.data)||e.data.length===u.length&&e.data.every((e,t)=>e===u[t]))return;u=e.data,m.tracks=u.slice();const t=s(i,"asel.sort");"function"==typeof t&&m.tracks.sort(t),f(d,p.events.TRACKS,Array.from({length:m.tracks.length}).map((e,t)=>{const n=m.tracks[t];return{text:n.name||n.label||n.lang,onclick:o.bind(0,c,n)}})),m.active_track=m.tracks.find(e=>e.enabled),m.active_track&&f(d,p.events.SWITCH,{selected_index:m.tracks.indexOf(m.active_track)});const n=r(c._storage,m.tracks,s(i,"asel.default_lang",!1));return d instanceof FlowplayerMenu&&d.toggle_visibility(e.data.length<2),void 0!==n?m.set(n):void 0})),c.on("audio:update",(function(e){var t;null===(t=c.asel)||void 0===t||t.tracks.find((t,n)=>{var s,i;t!==e.detail&&t.id!==(null!==(i=null===(s=e.detail)||void 0===s?void 0:s.id)&&void 0!==i?i:-1)||(c.asel.active_track=t,f(d,p.events.SWITCH,{selected_index:n}))})})),c.audioTracks&&(c.audioTracks.addEventListener("addtrack",(function(){c.hls||c.emit(t,Array.from(c.audioTracks))})),c.on(e,(function(e){if(c.hls)return;const t=e.detail;m.active_track=t,t&&Array.from(c.audioTracks).forEach(e=>{e.enabled=t.id===e.id,e.enabled&&f(d,p.events.SWITCH,{selected_index:m.tracks.indexOf(t)})})})))}}).pluginName="asel",p.events=n,p);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,h)}));