// ========================================================================== // Plyr controls // ========================================================================== import support from './support'; import utils from './utils'; import ui from './ui'; import i18n from './i18n'; import captions from './captions'; // Sniff out the browser const browser = utils.getBrowser(); const controls = { // Webkit polyfill for lower fill range updateRangeFill(target) { // WebKit only if (!browser.isWebkit) { return; } // Get range from event if event passed const range = utils.is.event(target) ? target.target : target; // Needs to be a valid if (!utils.is.element(range) || range.getAttribute('type') !== 'range') { return; } // Set CSS custom property range.style.setProperty('--value', `${range.value / range.max * 100}%`); }, // Get icon URL getIconUrl() { return { url: this.config.iconUrl, absolute: this.config.iconUrl.indexOf('http') === 0 || (browser.isIE && !window.svg4everybody), }; }, // Create icon createIcon(type, attributes) { const namespace = 'http://www.w3.org/2000/svg'; const iconUrl = controls.getIconUrl.call(this); const iconPath = `${!iconUrl.absolute ? iconUrl.url : ''}#${this.config.iconPrefix}`; // Create const icon = document.createElementNS(namespace, 'svg'); utils.setAttributes( icon, utils.extend(attributes, { role: 'presentation', }), ); // Create the to reference sprite const use = document.createElementNS(namespace, 'use'); const path = `${iconPath}-${type}`; // Set `href` attributes // https://github.com/sampotts/plyr/issues/460 // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xlink:href if ('href' in use) { use.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path); } else { use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', path); } // Add to icon.appendChild(use); return icon; }, // Create hidden text label createLabel(type, attr) { let text = i18n.get(type, this.config); const attributes = Object.assign({}, attr); switch (type) { case 'pip': text = 'PIP'; break; case 'airplay': text = 'AirPlay'; break; default: break; } if ('class' in attributes) { attributes.class += ` ${this.config.classNames.hidden}`; } else { attributes.class = this.config.classNames.hidden; } return utils.createElement('span', attributes, text); }, // Create a badge createBadge(text) { if (utils.is.empty(text)) { return null; } const badge = utils.createElement('span', { class: this.config.classNames.menu.value, }); badge.appendChild( utils.createElement( 'span', { class: this.config.classNames.menu.badge, }, text, ), ); return badge; }, // Create a