-
-
Notifications
You must be signed in to change notification settings - Fork 827
Added button that copies code to clipboard #1040
Conversation
Can one of the admins verify this patch? |
}; | ||
} | ||
}, 10); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like the right approach, although I don't understand why you're adding the onclick handlers asynchronously afterwards here. You've also copied the comment from the block above, but it's not relevant to this block and quite misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a while to realise that of course you can't add the onclick handlers here because you're just using it to parse, manipulate and re-generate the HTML markup. I'm going to add a comment to make it a bit easier to understand what's going on here, but otherwise this looks good.
src/HtmlUtils.js
Outdated
@@ -363,6 +364,18 @@ export function bodyToHtml(content, highlights, opts) { | |||
return <span className={className} dangerouslySetInnerHTML={{ __html: safeBody }} />; | |||
} | |||
|
|||
function addCodeCopyButton(safeBody) { | |||
var el = document.createElement("div"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should never we writing var
in new code
Signed-off-by: Oliver Hunt <oliver@hunt.bz>
Signed-off-by: Oliver Hunt <oliver@hunt.bz>
@@ -80,6 +93,15 @@ module.exports = React.createClass({ | |||
} | |||
}, 10); | |||
} | |||
const buttons = ReactDOM.findDOMNode(this).getElementsByClassName("mx_EventTile_copyButton"); | |||
if (buttons.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this check is now redundant, since if the length is 0, the for loop will just run zero times.
Needs element-hq/element-web#4204
See issue element-hq/element-web#1974