From 05a986334d482ecd37af40c4769700fe54fdcb46 Mon Sep 17 00:00:00 2001 From: David Baker Date: Sun, 10 Sep 2017 15:58:17 +0100 Subject: [PATCH] Separate function to add code copy button For neatness and also so it can show up separately in the profiler. --- src/components/views/messages/TextualBody.js | 24 ++++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index 3937780c2a..a58422e840 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -114,16 +114,7 @@ module.exports = React.createClass({ }, 10); } - // 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); - }); + this._addCodeCopyButton(); } }, @@ -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) { this.setState({ widgetHidden: true }); // FIXME: persist this somewhere smarter than local storage