Add comments & remove redundant check

This commit is contained in:
David Baker 2017-06-08 14:53:21 +01:00
parent b40636a425
commit 71eb405859
2 changed files with 11 additions and 7 deletions

View file

@ -365,6 +365,11 @@ export function bodyToHtml(content, highlights, opts) {
} }
function addCodeCopyButton(safeBody) { function addCodeCopyButton(safeBody) {
// Adds 'copy' buttons to pre blocks
// Note that this only manipulates the markup to add the buttons:
// we need to add the event handlers once the nodes are in the DOM
// since we can't save functions in the markup.
// This is done in TextualBody
const el = document.createElement("div"); const el = document.createElement("div");
el.innerHTML = safeBody; el.innerHTML = safeBody;
const codeBlocks = Array.from(el.getElementsByTagName("pre")); const codeBlocks = Array.from(el.getElementsByTagName("pre"));

View file

@ -94,14 +94,13 @@ module.exports = React.createClass({
} }
}, 10); }, 10);
} }
// add event handlers to the 'copy code' buttons
const buttons = ReactDOM.findDOMNode(this).getElementsByClassName("mx_EventTile_copyButton"); const buttons = ReactDOM.findDOMNode(this).getElementsByClassName("mx_EventTile_copyButton");
if (buttons.length > 0) { for (let i = 0; i < buttons.length; i++) {
for (let i = 0; i < buttons.length; i++) { buttons[i].onclick = (e) => {
buttons[i].onclick = (e) => { const copyCode = buttons[i].parentNode.getElementsByTagName("code")[0];
const copyCode = buttons[i].parentNode.getElementsByTagName("code")[0]; this.copyToClipboard(copyCode.textContent);
this.copyToClipboard(copyCode.textContent); };
};
}
} }
} }
}, },