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.
52 lines
1.2 KiB
52 lines
1.2 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
8 years ago
|
|
||
8 years ago
|
export default class Permalink extends React.PureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static contextTypes = {
|
||
8 years ago
|
router: PropTypes.object,
|
||
8 years ago
|
};
|
||
|
|
||
|
static propTypes = {
|
||
|
className: PropTypes.string,
|
||
|
href: PropTypes.string.isRequired,
|
||
|
to: PropTypes.string.isRequired,
|
||
8 years ago
|
children: PropTypes.node,
|
||
6 years ago
|
onInterceptClick: PropTypes.func,
|
||
8 years ago
|
};
|
||
|
|
||
|
handleClick = (e) => {
|
||
6 years ago
|
if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
|
||
|
if (this.props.onInterceptClick && this.props.onInterceptClick()) {
|
||
|
e.preventDefault();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (this.context.router) {
|
||
|
e.preventDefault();
|
||
2 years ago
|
let state = { ...this.context.router.history.location.state };
|
||
6 years ago
|
state.mastodonBackSteps = (state.mastodonBackSteps || 0) + 1;
|
||
|
this.context.router.history.push(this.props.to, state);
|
||
6 years ago
|
}
|
||
8 years ago
|
}
|
||
2 years ago
|
};
|
||
8 years ago
|
|
||
|
render () {
|
||
7 years ago
|
const {
|
||
|
children,
|
||
|
className,
|
||
|
href,
|
||
|
to,
|
||
6 years ago
|
onInterceptClick,
|
||
7 years ago
|
...other
|
||
|
} = this.props;
|
||
8 years ago
|
|
||
8 years ago
|
return (
|
||
7 years ago
|
<a target='_blank' href={href} onClick={this.handleClick} {...other} className={`permalink${className ? ' ' + className : ''}`}>
|
||
8 years ago
|
{children}
|
||
|
</a>
|
||
|
);
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
}
|