-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/remove innerhtml #7337
Fix/remove innerhtml #7337
Changes from 7 commits
c0fbfbf
8cebce9
cf4b38e
48267e1
7931e9d
d06bc7f
dac0cdd
e85c076
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,14 +28,12 @@ class CustomControlSpacer extends Spacer { | |
* The element that was created. | ||
*/ | ||
createEl() { | ||
const el = super.createEl({ | ||
className: this.buildCSSClass() | ||
return super.createEl('div', { | ||
className: this.buildCSSClass(), | ||
// No-flex/table-cell mode requires there be some content | ||
// in the cell to fill the remaining space of the table. | ||
textContent: '\u00a0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this isn't coming through here. Comparing videojs-preview to this branch's preview, I see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I found the issue here, the |
||
}); | ||
|
||
// No-flex/table-cell mode requires there be some content | ||
// in the cell to fill the remaining space of the table. | ||
el.innerHTML = '\u00a0'; | ||
return el; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,12 @@ class Spacer extends Component { | |
* @return {Element} | ||
* The element that was created. | ||
*/ | ||
createEl() { | ||
return super.createEl('div', { | ||
className: this.buildCSSClass() | ||
}); | ||
createEl(tag = 'div', props = {}, attributes = {}) { | ||
if (!props.className) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pass props along |
||
props.className = this.buildCSSClass(); | ||
} | ||
|
||
return super.createEl(tag, props, attributes); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ | |
*/ | ||
import TextTrackMenuItem from './text-track-menu-item.js'; | ||
import Component from '../../component.js'; | ||
import {assign} from '../../utils/obj'; | ||
import document from 'global/document'; | ||
import {createEl} from '../../utils/dom.js'; | ||
|
||
/** | ||
* SubsCapsMenuItem has an [cc] icon to distinguish captions from subtitles | ||
|
@@ -14,20 +15,33 @@ import {assign} from '../../utils/obj'; | |
class SubsCapsMenuItem extends TextTrackMenuItem { | ||
|
||
createEl(type, props, attrs) { | ||
let innerHTML = `<span class="vjs-menu-item-text">${this.localize(this.options_.label)}`; | ||
const el = super.createEl(type, props, attrs); | ||
|
||
if (this.options_.track.kind === 'captions') { | ||
innerHTML += ` | ||
<span aria-hidden="true" class="vjs-icon-placeholder"></span> | ||
<span class="vjs-control-text"> ${this.localize('Captions')}</span> | ||
`; | ||
while (el.firstChild) { | ||
el.removeChild(el.firstChild); | ||
} | ||
|
||
innerHTML += '</span>'; | ||
const parentSpan = createEl('span', { | ||
className: 'vjs-menu-item-text' | ||
}); | ||
|
||
parentSpan.appendChild(document.createTextNode(this.localize(this.options_.label))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like there we can do the same as for the audio track menu item. Instead of removing all children, we grab the span that's created and append to it, since it seems like it gets created as we want. |
||
|
||
if (this.options_.track.kind === 'captions') { | ||
parentSpan.appendChild(createEl('span', { | ||
className: 'vjs-icon-placeholder' | ||
}, { | ||
'aria-hidden': true | ||
})); | ||
parentSpan.appendChild(createEl('span', { | ||
className: 'vjs-control-text', | ||
// space added as the text will visually flow with the | ||
// label | ||
textContent: ` ${this.localize('Captions')}` | ||
})); | ||
} | ||
|
||
const el = super.createEl(type, assign({ | ||
innerHTML | ||
}, props), attrs); | ||
el.appendChild(parentSpan); | ||
|
||
return el; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,15 +18,24 @@ class TimeDivider extends Component { | |
* The element that was created. | ||
*/ | ||
createEl() { | ||
return super.createEl('div', { | ||
className: 'vjs-time-control vjs-time-divider', | ||
innerHTML: '<div><span>/</span></div>' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
const el = super.createEl('div', { | ||
className: 'vjs-time-control vjs-time-divider' | ||
}, { | ||
// this element and its contents can be hidden from assistive techs since | ||
// it is made extraneous by the announcement of the control text | ||
// for the current time and duration displays | ||
'aria-hidden': true | ||
}); | ||
|
||
const div = super.createEl('div'); | ||
const span = super.createEl('span', { | ||
textContent: '/' | ||
}); | ||
|
||
div.appendChild(span); | ||
el.appendChild(div); | ||
|
||
return el; | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import Component from '../component.js'; | |
import {assign} from '../utils/obj'; | ||
import {MenuKeys} from './menu-keys.js'; | ||
import keycode from 'keycode'; | ||
import {createEl} from '../utils/dom.js'; | ||
|
||
/** | ||
* The component for a menu item. `<li>` | ||
|
@@ -63,11 +64,21 @@ class MenuItem extends ClickableComponent { | |
// The control is textual, not just an icon | ||
this.nonIconControl = true; | ||
|
||
return super.createEl('li', assign({ | ||
const el = super.createEl('li', assign({ | ||
className: 'vjs-menu-item', | ||
innerHTML: `<span class="vjs-menu-item-text">${this.localize(this.options_.label)}</span>`, | ||
tabIndex: -1 | ||
}, props), attrs); | ||
|
||
while (el.firstChild) { | ||
el.removeChild(el.firstChild); | ||
} | ||
|
||
el.appendChild(createEl('span', { | ||
className: 'vjs-menu-item-text', | ||
textContent: this.localize(this.options_.label) | ||
})); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to do less work, we potentially can replace the first child with this new span and potentially do less work el.replaceChild(createEl('span', {
className: 'vjs-menu-item-text',
textContent: this.localize(this.options_.label)
}, el.firstChild) Based on the output of ClickableComponent and the expected output of MenuItem, that's the only change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, we leave as is, but we should create an issue for this to do a follow-up refactor where we look and see where we can reduce the amount of work we're doing when creating components. |
||
|
||
return el; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here we want to use
Dom.createEl
otherwise, we get a filled outli
element and end up with the label inserted into the DOM twice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, looking at
el
, maybe what we need to do here is to get the span that gets created and append to it?So, not removing stuff from el on line 51/52, then
parentSpan = el.querySelector('.vjs-menu-item-text');