@shopgate/pwa-common
Version:
Common library for the Shopgate Connect PWA.
33 lines • 3.73 kB
JavaScript
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}/* eslint-disable extra-rules/potential-point-free */ /**
* Class to maintain embedded media within DOM containers.
*/var EmbeddedMedia=/*#__PURE__*/function(){/**
* Constructor
*/function EmbeddedMedia(){_classCallCheck(this,EmbeddedMedia);this.providers=new Set();}/**
* Add a provider for embedded media.
* @param {Object} provider A provider instance.
*/return _createClass(EmbeddedMedia,[{key:"addProvider",value:function addProvider(provider){this.providers.add(provider);}/**
* Remove a provider for embedded media.
* @param {Object} provider A provider instance.
*/},{key:"removeProvider",value:function removeProvider(provider){this.providers["delete"](provider);}/**
* Add a DOM container with embedded media.
* @param {ParentNode} container A DOM container.
*/},{key:"add",value:function add(container){this.providers.forEach(function(provider){provider.add(container);});}/**
* Remove a DOM container. Should be called whenever a component which hosts a DOM container with
* embedded media is unmounted.
* @param {ParentNode} container A DOM container.
*/},{key:"remove",value:function remove(container){this.providers.forEach(function(provider){provider.remove(container);});}/**
* Searches for embedded media and replaces it with a placeholder element when required cookie
* consent is not accepted.
* Should be invoked before container content is added to the DOM to fulfill all regulations.
* @param {ParentNode} container A DOM container.
* @param {Object} [cookieConsentSettings] Additional settings related to cookie consent.
* @param {boolean} [cookieConsentSettings.comfortCookiesAccepted] Whether comfort cookies
* are accepted.
* @param {boolean} [cookieConsentSettings.statisticsCookiesAccepted] Whether statistics cookies
* are accepted.
*/},{key:"handleCookieConsent",value:function handleCookieConsent(container){var cookieConsentSettings=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var cookieConsent=_extends({comfortCookiesAccepted:false,statisticsCookiesAccepted:false},cookieConsentSettings);this.providers.forEach(function(provider){if(provider.handleCookieConsent){provider.handleCookieConsent(container,cookieConsent);}});}/**
* Stops all playing media within the DOM containers.
*/},{key:"stop",value:function stop(){this.providers.forEach(function(provider){provider.stop();});}/**
* Check if we have media providers with not-ready SDK
* @returns {boolean}
*/},{key:"getHasPendingProviders",value:function getHasPendingProviders(){var hasPendingProviders=false;this.providers.forEach(function(provider){if(provider.isPending){hasPendingProviders=true;}});return hasPendingProviders;}}]);}();export default new EmbeddedMedia();/* eslint-enable extra-rules/potential-point-free */