// ========================================================================== // Plyr controls // ========================================================================== import support from './support'; import utils from './utils'; import ui from './ui'; 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.htmlElement(range) || range.getAttribute('type') !== 'range') { return; } // Inject the stylesheet if needed if (!utils.is.htmlElement(this.elements.styleSheet)) { this.elements.styleSheet = utils.createElement('style'); this.elements.container.appendChild(this.elements.styleSheet); } const styleSheet = this.elements.styleSheet.sheet; const percentage = range.value / range.max * 100; const selector = `#${range.id}::-webkit-slider-runnable-track`; const styles = `{ background-image: linear-gradient(to right, currentColor ${percentage}%, transparent ${percentage}%) }`; // Find old rule if it exists const index = Array.from(styleSheet.rules).findIndex(rule => rule.selectorText === selector); // Remove old rule if (index !== -1) { styleSheet.deleteRule(index); } // Insert new one styleSheet.insertRule([selector, styles].join(' ')); }, // 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 = this.config.i18n[type]; 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