fix(aio): switch from innerText to textContent to support older browsers

`innerText` is not supported in Firefox prior to v45. In most cases (at least
the ones we are interested in), `innerText` and `textContent` work equally well,
but `textContent` is more performant (as it doesn't require a reflow).

From [MDN][1] on the differences of `innerText` vs `textContent`:

> - [...]
> - `innerText` is aware of style and will not return the text of hidden
>   elements, whereas `textContent` will.
> - As `innerText` is aware of CSS styling, it will trigger a reflow, whereas
>   `textContent` will not.
> - [...]

[1]: https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent#Differences_from_innerText

Fixes #17585
This commit is contained in:
Georgios Kalpakas
2017-06-18 12:29:48 +03:00
committed by Hans
parent 3093c55e9e
commit 4f37f86433
13 changed files with 32 additions and 29 deletions
+3 -3
View File
@@ -108,7 +108,7 @@ export class CodeComponent implements OnChanges {
if (!this.code) {
const src = this.path ? this.path + (this.region ? '#' + this.region : '') : '';
const srcMsg = src ? ` for<br>${src}` : '.';
const srcMsg = src ? ` for\n${src}` : '.';
this.setCodeHtml(`<p class="code-missing">The code sample is missing${srcMsg}</p>`);
return;
}
@@ -129,8 +129,8 @@ export class CodeComponent implements OnChanges {
}
doCopy() {
// We take the innerText because we don't want it to be HTML encoded
const code = this.codeContainer.nativeElement.innerText;
// We take the textContent because we don't want it to be HTML encoded
const code = this.codeContainer.nativeElement.textContent.trim();
if (this.copier.copyText(code)) {
this.logger.log('Copied code to clipboard:', code);
// success snackbar alert