Skip to content

Commit 87c4787

Browse files
awilfoxRaphael Krusenbaum
andcommitted
js: Add volume status element to volume slider
This fixes mediaelement/mediaelement#2950 and mediaelement/mediaelement#2976, and is a full backport of mediaelement/mediaelement#2988. Co-authored-by: Raphael Krusenbaum <rkrusenb-git@noreply.materna.group> Ref: ADA-667
1 parent 4e1b004 commit 87c4787

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

app/assets/javascripts/mediaelement-and-player.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,7 +3037,7 @@ Object.assign(_player2.default.prototype, {
30373037
mute = _document2.default.createElement('div');
30383038

30393039
mute.className = t.options.classPrefix + 'button ' + t.options.classPrefix + 'volume-button ' + t.options.classPrefix + 'mute';
3040-
mute.innerHTML = mode === 'horizontal' ? (0, _generate.generateControlButton)(t.id, muteText, muteText, '' + t.media.options.iconSprite, ['icon-mute', 'icon-unmute'], '' + t.options.classPrefix, '', t.options.classPrefix + 'horizontal-volume-slider') : (0, _generate.generateControlButton)(t.id, muteText, muteText, '' + t.media.options.iconSprite, ['icon-mute', 'icon-unmute'], '' + t.options.classPrefix, '', t.options.classPrefix + 'volume-slider') + ('<a class="' + t.options.classPrefix + 'volume-slider" ') + ('aria-label="' + _i18n2.default.t('mejs.volume-slider') + '" aria-valuemin="0" aria-valuemax="100" role="slider" ') + 'aria-orientation="vertical">' + ('<span class="' + t.options.classPrefix + 'offscreen" id="' + t.options.classPrefix + 'volume-slider">' + volumeControlText + '</span>') + ('<div class="' + t.options.classPrefix + 'volume-total">') + ('<div class="' + t.options.classPrefix + 'volume-current"></div>') + ('<div class="' + t.options.classPrefix + 'volume-handle"></div>') + '</div>' + '</a>';
3040+
mute.innerHTML = mode === 'horizontal' ? (0, _generate.generateControlButton)(t.id, muteText, muteText, '' + t.media.options.iconSprite, ['icon-mute', 'icon-unmute'], '' + t.options.classPrefix, '', t.id + '_volume-slider') : (0, _generate.generateControlButton)(t.id, muteText, muteText, '' + t.media.options.iconSprite, ['icon-mute', 'icon-unmute'], '' + t.options.classPrefix, '', t.id + '_volume-slider') + ('<a class="' + t.options.classPrefix + 'volume-slider" ') + ('aria-label="' + _i18n2.default.t('mejs.volume-slider') + '" aria-valuemin="0" aria-valuemax="100" role="slider" ') + 'aria-orientation="vertical">' + ('<span class="' + t.options.classPrefix + 'offscreen" id="' + t.id + '_volume-slider">' + volumeControlText + '</span>') + ('<div class="' + t.options.classPrefix + 'volume-total">') + ('<div class="' + t.options.classPrefix + 'volume-current"></div>') + ('<div class="' + t.options.classPrefix + 'volume-handle"></div>') + '</div>' + '</a>' + ('<span class="' + t.options.classPrefix + 'offscreen ' + t.options.classPrefix + 'volume-status" role="status">') + '</span>';
30413041

30423042
t.addControlElement(mute, 'volume');
30433043

@@ -3115,9 +3115,14 @@ Object.assign(_player2.default.prototype, {
31153115
mouseIsOver = false,
31163116
modified = false,
31173117
updateVolumeSlider = function updateVolumeSlider() {
3118-
var volume = Math.floor(media.volume * 100);
3118+
const volume = Math.floor(media.volume * 100);
31193119
volumeSlider.setAttribute('aria-valuenow', volume);
31203120
volumeSlider.setAttribute('aria-valuetext', volume + '%');
3121+
3122+
const statusRegion = mute.querySelector('.' + t.options.classPrefix + 'volume-status');
3123+
if (statusRegion) {
3124+
statusRegion.innerHTML = 'Volume ' + volume + '%';
3125+
}
31213126
};
31223127

31233128
var volumeSlider = mode === 'vertical' ? t.getElement(t.container).querySelector('.' + t.options.classPrefix + 'volume-slider') : t.getElement(t.container).querySelector('.' + t.options.classPrefix + 'horizontal-volume-slider'),
@@ -3228,6 +3233,7 @@ Object.assign(_player2.default.prototype, {
32283233
mute.addEventListener('focusin', function () {
32293234
volumeSlider.style.display = 'block';
32303235
mouseIsOver = true;
3236+
setTimeout(updateVolumeSlider, 0);
32313237
});
32323238

32333239
mute.addEventListener('focusout', function (e) {

0 commit comments

Comments
 (0)