You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

  1. import ImmutablePropTypes from 'react-immutable-proptypes';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. const StatusContent = React.createClass({
  4. contextTypes: {
  5. router: React.PropTypes.object
  6. },
  7. propTypes: {
  8. status: ImmutablePropTypes.map.isRequired
  9. },
  10. mixins: [PureRenderMixin],
  11. componentDidMount () {
  12. const node = ReactDOM.findDOMNode(this);
  13. const links = node.querySelectorAll('a');
  14. for (var i = 0; i < links.length; ++i) {
  15. let link = links[i];
  16. let mention = this.props.status.get('mentions').find(item => link.href === item.get('url'));
  17. if (mention) {
  18. link.addEventListener('click', this.onMentionClick.bind(this, mention));
  19. } else {
  20. link.setAttribute('target', '_blank');
  21. link.setAttribute('rel', 'noopener');
  22. link.addEventListener('click', this.onNormalClick);
  23. }
  24. }
  25. },
  26. onMentionClick (mention, e) {
  27. if (e.button === 0) {
  28. e.preventDefault();
  29. this.context.router.push(`/accounts/${mention.get('id')}`);
  30. }
  31. e.stopPropagation();
  32. },
  33. onNormalClick (e) {
  34. e.stopPropagation();
  35. },
  36. render () {
  37. const content = { __html: this.props.status.get('content') };
  38. return <div className='status__content' dangerouslySetInnerHTML={content} />;
  39. },
  40. });
  41. export default StatusContent;