Using the “href” attribute on SVG if supported, using hasAttribute

This commit is contained in:
Sam Potts
2017-11-07 09:58:37 +11:00
parent 84505da84b
commit e2c7491ccd
5 changed files with 20 additions and 10 deletions

11
src/js/controls.js vendored
View File

@ -73,7 +73,16 @@ const controls = {
// Create the <use> to reference sprite
const use = document.createElementNS(namespace, 'use');
use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', `${iconPath}-${type}`);
const path = `${iconPath}-${type}`;
// If the new `href` attribute is supported, use that
// https://github.com/sampotts/plyr/issues/460
// https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/xlink:href
if ('href' in use) {
use.setAttribute('href', path);
} else {
use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', path);
}
// Add <use> to <svg>
icon.appendChild(use);