From e85c076f66a0863f3d7272b51694efd81a19019c Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Tue, 27 Jul 2021 14:22:47 -0400 Subject: [PATCH] do less work --- .../audio-track-controls/audio-track-menu-item.js | 14 +------------- .../text-track-controls/subs-caps-menu-item.js | 14 +------------- src/js/menu/menu-item.js | 9 +++------ 3 files changed, 5 insertions(+), 32 deletions(-) diff --git a/src/js/control-bar/audio-track-controls/audio-track-menu-item.js b/src/js/control-bar/audio-track-controls/audio-track-menu-item.js index 72cf6450bf..e8820a53be 100644 --- a/src/js/control-bar/audio-track-controls/audio-track-menu-item.js +++ b/src/js/control-bar/audio-track-controls/audio-track-menu-item.js @@ -3,7 +3,6 @@ */ import MenuItem from '../../menu/menu-item.js'; import Component from '../../component.js'; -import document from 'global/document'; /** * An {@link AudioTrack} {@link MenuItem} @@ -47,16 +46,7 @@ class AudioTrackMenuItem extends MenuItem { createEl(type, props, attrs) { const el = super.createEl(type, props, attrs); - - while (el.firstChild) { - el.removeChild(el.firstChild); - } - - const parentSpan = super.createEl('span', { - className: 'vjs-menu-item-text' - }); - - parentSpan.appendChild(document.createTextNode(this.localize(this.options_.label))); + const parentSpan = el.querySelector('.vjs-menu-item-text'); if (this.options_.track.kind === 'main-desc') { parentSpan.appendChild(super.createEl('span', { @@ -70,8 +60,6 @@ class AudioTrackMenuItem extends MenuItem { })); } - el.appendChild(parentSpan); - return el; } diff --git a/src/js/control-bar/text-track-controls/subs-caps-menu-item.js b/src/js/control-bar/text-track-controls/subs-caps-menu-item.js index 6fea7056ef..fde8f89608 100644 --- a/src/js/control-bar/text-track-controls/subs-caps-menu-item.js +++ b/src/js/control-bar/text-track-controls/subs-caps-menu-item.js @@ -3,7 +3,6 @@ */ import TextTrackMenuItem from './text-track-menu-item.js'; import Component from '../../component.js'; -import document from 'global/document'; import {createEl} from '../../utils/dom.js'; /** @@ -16,16 +15,7 @@ class SubsCapsMenuItem extends TextTrackMenuItem { createEl(type, props, attrs) { const el = super.createEl(type, props, attrs); - - while (el.firstChild) { - el.removeChild(el.firstChild); - } - - const parentSpan = createEl('span', { - className: 'vjs-menu-item-text' - }); - - parentSpan.appendChild(document.createTextNode(this.localize(this.options_.label))); + const parentSpan = el.querySelector('.vjs-menu-item-text'); if (this.options_.track.kind === 'captions') { parentSpan.appendChild(createEl('span', { @@ -41,8 +31,6 @@ class SubsCapsMenuItem extends TextTrackMenuItem { })); } - el.appendChild(parentSpan); - return el; } } diff --git a/src/js/menu/menu-item.js b/src/js/menu/menu-item.js index 845802f096..f8b660f2b9 100644 --- a/src/js/menu/menu-item.js +++ b/src/js/menu/menu-item.js @@ -69,14 +69,11 @@ class MenuItem extends ClickableComponent { tabIndex: -1 }, props), attrs); - while (el.firstChild) { - el.removeChild(el.firstChild); - } - - el.appendChild(createEl('span', { + // swap icon with menu item text. + el.replaceChild(createEl('span', { className: 'vjs-menu-item-text', textContent: this.localize(this.options_.label) - })); + }), el.querySelector('.vjs-icon-placeholder')); return el; }