UNPKG

@flowplayer/player

Version:
2 lines (1 loc) 10.7 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.share=t())}(this,(function(){"use strict";const e={name:"fp-facebook"},t={name:"fp-link"},n={name:"fp-share"},s={name:"fp-embed"},i={name:"fp-twitter"};function o(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}function r(){try{return(document.querySelector("meta[name='description']")||{content:""}).content}catch(e){return""}}function l(e){if("string"==typeof e.link)return e.link;const t=document.querySelector("link[rel=canonical]");return t?t.href:window.location.toString()}class FlowplayerComponent extends HTMLElement{constructor(e){super(),this.player=e}}class FlowplayerIcon extends FlowplayerComponent{constructor(e,t){super(e),this.classList.add("fp-icon",t.name),t.title&&this.setAttribute("title",t.title),t.title&&this.setAttribute("aria-label",t.title),t.translation_key&&this.setAttribute("aria-label",e.i18n(t.translation_key)),this.setAttribute("tabindex","0"),this.setAttribute("focusable","true")}}const a=(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),c=(e,t,n)=>{window.customElements.get(t)||window.customElements.define(t,n),e.customElements.get(t)||e.customElements.set(t,t)},u="fp-on",d="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=p(),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||(m(),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||p()),this.summaryEle.setAttribute("aria-label",e.menuTitle||"Menu"),e.summaryTitle&&(this.summaryEle.textContent=e.summaryTitle),e.summaryIcon){const t=a(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(u,n===e)})}unselect_item(){this.options.forEach(e=>{e.classList.remove(u)})}toggle_visibility(e){this.classList.toggle(d,e),this.menu.style.setProperty("display",e?"none":"flex")}}function m(){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 p(){return Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5)}function h(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}function f(e,t){const n=e._customElements.get(t);return n&&e.root.querySelector(n)||void 0}document.addEventListener("click",(function(e){this.active_menu&&!e.composedPath().includes(this.active_menu)&&(m(),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 y="flowplayer-share-menu";var w;const b=((w=class Share{constructor(o){this.umd=o,this.share_options=[],c(o,y,FlowplayerMenu),c(this.umd,"flowplayer-facebook-icon",class extends FlowplayerIcon{constructor(t){super(t,e)}}),c(this.umd,"flowplayer-twitter-icon",class extends FlowplayerIcon{constructor(e){super(e,i)}}),c(this.umd,"flowplayer-link-icon",class extends FlowplayerIcon{constructor(e){super(e,t)}}),c(this.umd,"flowplayer-embed-icon",class extends FlowplayerIcon{constructor(e){super(e,s)}}),c(this.umd,"flowplayer-share-icon",class extends FlowplayerIcon{constructor(e){super(e,n)}})}init(e,t,n){const s=a(n,y);s instanceof FlowplayerMenu&&s.setMenuAttrs({menuTitle:n.i18n("share.menu_title"),class:"fp-share-menu fp-togglable",summaryIcon:"flowplayer-share-icon",icons:!0,options_event:w.events.OPTIONS});const i={prev_config:0,webshare_listener:0};n.on("mount",(function(){var e;null===(e=f(n,"flowplayer-header-left-zone"))||void 0===e||e.append(s),s instanceof FlowplayerMenu&&s.menuContainer.addEventListener("toggle",(function(){t.classList.toggle("is-share-menu",this.open);const e=f(n,"flowplayer-control");this.open&&(t.classList.contains("is-small")?n.pause():e&&function(e,t){if(!t)return;e.menu.style.maxHeight=t.getBoundingClientRect().top+parseFloat(window.getComputedStyle(t).getPropertyValue("padding"))-e.menuContainer.getBoundingClientRect().bottom+"px"}(s,e))}))})),n.on("config",t=>{const c=o(t,"data.share",{});if(!1===c)return s instanceof FlowplayerMenu&&void s.classList.remove("webshare-enabled");if(i.prev_config===c)return;if(i.prev_config=c,s instanceof FlowplayerMenu&&function(){try{return"https:"===window.location.protocol&&"function"==typeof navigator.share}catch(e){return!1}}()&&o(c,"web_share",!0))return function(e){e.classList.add("webshare-enabled")}(s),i.webshare_listener||function(e,t,n){n.webshare_listener=!0,t.addEventListener("click",(function(){if(!t.classList.contains("webshare-enabled"))return;t.menuContainer.open=!1;navigator.share({title:o(e,"share.title",document.title),text:o(e,"share.text",r()),url:l(o(e,"share",{}))}).catch((function(){}))}))}(e,s,i);this.share_options=[];const u="string"==typeof c.link?c.link:window.location.toString();if(c.iframe){const e="string"==typeof c.iframe?c.iframe:u;this.share_options.push(g(n,s,"share.embed",_.bind(null,e,n),a(n,"flowplayer-embed-icon")))}c.link&&this.share_options.push(g(n,s,"share.link",x.bind(null,u),a(n,"flowplayer-link-icon"))),c.facebook&&this.share_options.push(g(n,s,"Facebook",A.bind(null,u),a(n,"flowplayer-facebook-icon"))),c.twitter&&this.share_options.push(g(n,s,"Twitter",L.bind(null,u),a(n,"flowplayer-twitter-icon"))),h(s,w.events.OPTIONS,this.share_options)})}add_options(e,...t){const n=e.root.querySelector(y);n&&t.forEach(t=>{const s=g(e,n,t.text,t.onclick,t.icon);n.menuOption(s,n.options.length)})}}).pluginName="share",w.events={OPTIONS:"share:options"},w);function g(e,t,n,s,i){return{text:E(e,n),icon:i,onclick:v.bind(null,e,t,s)}}function E(e,t){return 0===t.indexOf("share.")?e.i18n(t):t}function v(e,t,n){t instanceof FlowplayerMenu&&t.unselect_item();const s=n();s.success&&s.message&&e.message&&e.emit(e.message.events.SHOW_MESSAGE,{message:s.message})}function _(e,t){const n=t.videoHeight/t.videoWidth;return x('<div style="position:relative;width:100%;display:inline-block;"><iframe src="__IFRAME_SRC__" allowfullscreen style="border:none;position:absolute;top:0;left:0;width:100%;height:100%;"></iframe><div style="padding-top: __RATIO__%;"></div></div>'.replace("__IFRAME_SRC__",encodeURI(e)).replace("__RATIO__",""+100*n))}function x(e){const t=document.createElement("textarea");t.setAttribute("style","position:absolute;opacity:0"),t.value=e;const n=document.body;n.append(t),t.select();const s=document.execCommand("copy");return n.removeChild(t),{success:s,message:s?"<trans share.clipboard_success trans>":"<trans share.clipboard_failure trans>"}}function A(e){return C("https://www.facebook.com/sharer.php?u="+encodeURIComponent(e)),{success:!0}}function L(e){return C("https://twitter.com/intent/tweet?url="+encodeURIComponent(e)),{success:!0}}function C(e){let t;const n=screen.height,s=screen.width,i=Math.round(s/2-275);t=0,n>420&&(t=Math.round(n/2-210)),window.open(e,"sharer","scrollbars=yes,resizable=yes,toolbar=no,location=yes,width=550,height=420,left="+i+",top="+t)}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,b)}));