Separate function to add code copy button

For neatness and also so it can show up separately in the profiler.
This commit is contained in:
David Baker 2017-09-10 15:58:17 +01:00
parent 876257f4e2
commit 05a986334d

View file

@ -114,16 +114,7 @@ module.exports = React.createClass({
}, 10); }, 10);
} }
// Add 'copy' buttons to pre blocks this._addCodeCopyButton();
ReactDOM.findDOMNode(this).querySelectorAll('.mx_EventTile_body pre').forEach((p) => {
const button = document.createElement("span");
button.className = "mx_EventTile_copyButton";
button.onclick = (e) => {
const copyCode = button.parentNode.getElementsByTagName("code")[0];
this.copyToClipboard(copyCode.textContent);
};
p.appendChild(button);
});
} }
}, },
@ -260,6 +251,19 @@ module.exports = React.createClass({
} }
}, },
_addCodeCopyButton() {
// Add 'copy' buttons to pre blocks
ReactDOM.findDOMNode(this).querySelectorAll('.mx_EventTile_body pre').forEach((p) => {
const button = document.createElement("span");
button.className = "mx_EventTile_copyButton";
button.onclick = (e) => {
const copyCode = button.parentNode.getElementsByTagName("code")[0];
this.copyToClipboard(copyCode.textContent);
};
p.appendChild(button);
});
},
onCancelClick: function(event) { onCancelClick: function(event) {
this.setState({ widgetHidden: true }); this.setState({ widgetHidden: true });
// FIXME: persist this somewhere smarter than local storage // FIXME: persist this somewhere smarter than local storage