The code powering m.abunchtell.com https://m.abunchtell.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

71 linhas
2.0 KiB

  1. import ImmutablePropTypes from 'react-immutable-proptypes';
  2. import PureRenderMixin from 'react-addons-pure-render-mixin';
  3. import emojione from 'emojione';
  4. emojione.imageType = 'png';
  5. emojione.sprites = false;
  6. emojione.imagePathPNG = '/emoji/';
  7. const StatusContent = React.createClass({
  8. contextTypes: {
  9. router: React.PropTypes.object
  10. },
  11. propTypes: {
  12. status: ImmutablePropTypes.map.isRequired,
  13. onClick: React.PropTypes.func
  14. },
  15. mixins: [PureRenderMixin],
  16. componentDidMount () {
  17. const node = ReactDOM.findDOMNode(this);
  18. const links = node.querySelectorAll('a');
  19. for (var i = 0; i < links.length; ++i) {
  20. let link = links[i];
  21. let mention = this.props.status.get('mentions').find(item => link.href === item.get('url'));
  22. if (mention) {
  23. link.addEventListener('click', this.onMentionClick.bind(this, mention), false);
  24. } else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
  25. link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false);
  26. } else {
  27. link.setAttribute('target', '_blank');
  28. link.setAttribute('rel', 'noopener');
  29. }
  30. link.addEventListener('click', this.onNormalClick, false);
  31. }
  32. },
  33. onMentionClick (mention, e) {
  34. if (e.button === 0) {
  35. e.preventDefault();
  36. this.context.router.push(`/accounts/${mention.get('id')}`);
  37. }
  38. },
  39. onHashtagClick (hashtag, e) {
  40. hashtag = hashtag.replace(/^#/, '').toLowerCase();
  41. if (e.button === 0) {
  42. e.preventDefault();
  43. this.context.router.push(`/statuses/tag/${hashtag}`);
  44. }
  45. },
  46. onNormalClick (e) {
  47. e.stopPropagation();
  48. },
  49. render () {
  50. const content = { __html: emojione.unicodeToImage(this.props.status.get('content')) };
  51. return <div className='status__content' style={{ cursor: 'pointer' }} dangerouslySetInnerHTML={content} onClick={this.props.onClick} />;
  52. },
  53. });
  54. export default StatusContent;