Skip to content

Commit 6820c52

Browse files
authored
Merge pull request #252 from mediaelement/fix/display-quality-icon-after-quality-change
Quality icon remains visible after quality change
2 parents 4b4b579 + 0a70d8a commit 6820c52

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/a11y/a11y.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Object.assign(mejs.MepDefaults, {
5656
* The path where the icon sprite is located
5757
* @type {String}
5858
*/
59-
iconSpritePath: 'mejs-a11y-icons.svg',
59+
iconSpritePathA11y: 'mejs-a11y-icons.svg',
6060
});
6161

6262

@@ -97,13 +97,13 @@ Object.assign(MediaElementPlayer.prototype, {
9797
* @private
9898
* @param {String} id - ID of the MediaElement player
9999
* @param {String} classPrefix - Prefix for the class attribute
100-
* @param {String} iconSpritePath - Path to the SVG sprite containing icons
100+
* @param {String} iconSpritePathA11y - Path to the SVG sprite containing icons
101101
* @param {String} iconId - Specific ID of the icon within the SVG sprite
102102
* @returns {String} The complete HTML string for the SVG element
103103
*/
104-
_generateIconHtml(id, classPrefix, iconSpritePath, iconId) {
104+
_generateIconHtml(id, classPrefix, iconSpritePathA11y, iconId) {
105105
return `<svg xmlns="http://www.w3.org/2000/svg" id="${id}" class="${classPrefix}${iconId}" aria-hidden="true" focusable="false">
106-
<use xlink:href="${iconSpritePath}#${iconId}"></use></svg>`;
106+
<use xlink:href="${iconSpritePathA11y}#${iconId}"></use></svg>`;
107107
},
108108

109109
/**
@@ -113,7 +113,7 @@ Object.assign(MediaElementPlayer.prototype, {
113113
*/
114114
_createAudioDescription() {
115115
const t = this;
116-
const iconHtml = t._generateIconHtml(t.id, t.options.classPrefix, t.options.iconSpritePath, 'icon-audio');
116+
const iconHtml = t._generateIconHtml(t.id, t.options.classPrefix, t.options.iconSpritePathA11y, 'icon-audio');
117117
const audioDescriptionTitle = mejs.i18n.t('mejs.a11y-audio-description');
118118
const audioDescriptionButton = document.createElement('div');
119119
audioDescriptionButton.className = `${t.options.classPrefix}button ${t.options.classPrefix}audio-description-button`;
@@ -136,7 +136,7 @@ Object.assign(MediaElementPlayer.prototype, {
136136
*/
137137
_createVideoDescription() {
138138
const t = this;
139-
const iconHtml = t._generateIconHtml(t.id, t.options.classPrefix, t.options.iconSpritePath, 'icon-video');
139+
const iconHtml = t._generateIconHtml(t.id, t.options.classPrefix, t.options.iconSpritePathA11y, 'icon-video');
140140
const videoDescriptionTitle = mejs.i18n.t('mejs.a11y-video-description');
141141
const videoDescriptionButton = document.createElement('div');
142142
videoDescriptionButton.className = `${t.options.classPrefix}button ${t.options.classPrefix}video-description-button`;

src/quality/quality.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Object.assign(mejs.MepDefaults, {
4040
* The path where the icon file is located
4141
* @type {String}
4242
*/
43-
iconPath: 'mejs-quality.svg',
43+
iconPathQuality: 'mejs-quality.svg',
4444
});
4545

4646
Object.assign(MediaElementPlayer.prototype, {
@@ -130,6 +130,7 @@ Object.assign(MediaElementPlayer.prototype, {
130130

131131
t.generateQualityButton(t, player, media, qualityMap, currentQuality);
132132
},
133+
133134
generateQualityButton (t, player, media, qualityMap, currentQuality) {
134135
t.cleanquality(player);
135136

@@ -157,11 +158,11 @@ Object.assign(MediaElementPlayer.prototype, {
157158
// Get initial quality
158159
const generateId = Math.floor(Math.random() * 100);
159160
const iconHtml = `<svg xmlns="http://www.w3.org/2000/svg" id="${generateId}" class="${t.options.classPrefix}" aria-hidden="true" focusable="false">
160-
<use xlink:href="${t.options.iconPath}#default-icon"></use></svg>`;
161+
<use xlink:href="${t.options.iconPathQuality}#default-icon"></use></svg>`;
161162
player.qualitiesContainer = document.createElement('div');
162163
player.qualitiesContainer.className = `${t.options.classPrefix}button ${t.options.classPrefix}qualities-button`;
163164
player.qualitiesContainer.innerHTML = `<button type="button" title="${qualityTitle}" aria-label="${qualityTitle}" aria-controls="qualitieslist-${generateId}" aria-expanded="false">
164-
${t.options.iconPath ? iconHtml : defaultValue}</button>` +
165+
${t.options.iconPathQuality ? iconHtml : defaultValue}</button>` +
165166
`<div class="${t.options.classPrefix}qualities-selector ${t.options.classPrefix}offscreen">` +
166167
`<ul class="${t.options.classPrefix}qualities-selector-list" id="qualitieslist-${generateId}" tabindex="-1"></ul></div>`;
167168

@@ -436,7 +437,6 @@ Object.assign(MediaElementPlayer.prototype, {
436437
const
437438
newQuality = self.value
438439
;
439-
440440
const formerSelected = player.qualitiesContainer.querySelectorAll(`.${t.options.classPrefix}qualities-selected`);
441441
for (let i = 0, total = formerSelected.length; i < total; i++) {
442442
mejs.Utils.removeClass(formerSelected[i], `${t.options.classPrefix}qualities-selected`);
@@ -450,7 +450,10 @@ Object.assign(MediaElementPlayer.prototype, {
450450
currentSelected[j].parentElement.querySelector('input').classList.add(`${t.options.classPrefix}qualities-selected-input`);
451451
}
452452

453-
player.qualitiesContainer.querySelector('button').innerHTML = newQuality;
453+
if (!t.options.iconPathQuality) {
454+
player.qualitiesContainer.querySelector('button').innerHTML = newQuality;
455+
}
456+
454457
return newQuality;
455458
},
456459

0 commit comments

Comments
 (0)