mirror of https://github.com/vector-im/riot-web
parent
a640e943f7
commit
dd6171a39e
|
@ -365,11 +365,11 @@ export function bodyToHtml(content, highlights, opts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addCodeCopyButton(safeBody) {
|
function addCodeCopyButton(safeBody) {
|
||||||
var el = document.createElement("div");
|
const el = document.createElement("div");
|
||||||
el.innerHTML = safeBody;
|
el.innerHTML = safeBody;
|
||||||
var codeBlocks = Array.from(el.getElementsByTagName("pre"));
|
const codeBlocks = Array.from(el.getElementsByTagName("pre"));
|
||||||
codeBlocks.forEach(p => {
|
codeBlocks.forEach(p => {
|
||||||
var button = document.createElement("span");
|
const button = document.createElement("span");
|
||||||
button.className = "mx_EventTile_copyButton";
|
button.className = "mx_EventTile_copyButton";
|
||||||
p.appendChild(button);
|
p.appendChild(button);
|
||||||
});
|
});
|
||||||
|
|
|
@ -95,17 +95,12 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
const buttons = ReactDOM.findDOMNode(this).getElementsByClassName("mx_EventTile_copyButton");
|
const buttons = ReactDOM.findDOMNode(this).getElementsByClassName("mx_EventTile_copyButton");
|
||||||
if (buttons.length > 0) {
|
if (buttons.length > 0) {
|
||||||
// Do this asynchronously: parsing code takes time and we don't
|
for (let i = 0; i < buttons.length; i++) {
|
||||||
// need to block the DOM update on it.
|
buttons[i].onclick = (e) => {
|
||||||
setTimeout(() => {
|
const copyCode = buttons[i].parentNode.getElementsByTagName("code")[0];
|
||||||
if (this._unmounted) return;
|
this.copyToClipboard(copyCode.textContent);
|
||||||
for (let i = 0; i < buttons.length; i++) {
|
};
|
||||||
buttons[i].onclick = (e) => {
|
}
|
||||||
const copyCode = buttons[i].parentNode.getElementsByTagName("code")[0];
|
|
||||||
this.copyToClipboard(copyCode.textContent);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}, 10);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue