Don't show copy button if there is no <code>
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
64974eb3ee
commit
c76cc33ebf
1 changed files with 3 additions and 1 deletions
|
@ -161,6 +161,9 @@ export default class TextualBody extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_addCodeCopyButton(div) {
|
_addCodeCopyButton(div) {
|
||||||
|
const copyCode = div.getElementsByTagName("code")[0];
|
||||||
|
// If there isn't any code element don't show the copy button
|
||||||
|
if (!copyCode) return;
|
||||||
const button = document.createElement("span");
|
const button = document.createElement("span");
|
||||||
button.className = "mx_EventTile_button mx_EventTile_copyButton ";
|
button.className = "mx_EventTile_button mx_EventTile_copyButton ";
|
||||||
|
|
||||||
|
@ -170,7 +173,6 @@ export default class TextualBody extends React.Component {
|
||||||
if (expansionButtonExists.length > 0) button.className += "mx_EventTile_buttonBottom";
|
if (expansionButtonExists.length > 0) button.className += "mx_EventTile_buttonBottom";
|
||||||
|
|
||||||
button.onclick = async () => {
|
button.onclick = async () => {
|
||||||
const copyCode = button.parentNode.getElementsByTagName("code")[0];
|
|
||||||
const successful = await copyPlaintext(copyCode.textContent);
|
const successful = await copyPlaintext(copyCode.textContent);
|
||||||
|
|
||||||
const buttonRect = button.getBoundingClientRect();
|
const buttonRect = button.getBoundingClientRect();
|
||||||
|
|
Loading…
Reference in a new issue