mirror of
https://github.com/wassname/talk.git
synced 2026-06-29 23:43:19 +08:00
ef172cabfc
* host pym locally * host pym. fix some permalink styles * get url from parent document * reset copy dialog timeout * use pym.parentUrl instead of depending on the parent document * use a simpler method to find the url * add some horrible setInterval code * add some awesome polling * merge master * bail out of comment look up after 10 seconds * re-update permalink attrs * re-add my listeners to article.ejs * allow for overriding the talk db name in an environment var
76 lines
2.2 KiB
JavaScript
76 lines
2.2 KiB
JavaScript
import React, {PropTypes} from 'react';
|
|
import I18n from 'coral-framework/modules/i18n/i18n';
|
|
import translations from './translations';
|
|
import onClickOutside from 'react-onclickoutside';
|
|
const name = 'coral-plugin-permalinks';
|
|
|
|
const lang = new I18n(translations);
|
|
|
|
class PermalinkButton extends React.Component {
|
|
|
|
static propTypes = {
|
|
articleURL: PropTypes.string.isRequired,
|
|
commentId: PropTypes.string.isRequired
|
|
}
|
|
|
|
constructor (props) {
|
|
super(props);
|
|
this.state = {popoverOpen: false, copySuccessful: null, copyFailure: null};
|
|
this.toggle = this.toggle.bind(this);
|
|
this.copyPermalink = this.copyPermalink.bind(this);
|
|
}
|
|
|
|
toggle () {
|
|
this.setState({popoverOpen: !this.state.popoverOpen});
|
|
}
|
|
|
|
handleClickOutside () {
|
|
this.setState({popoverOpen: false});
|
|
}
|
|
|
|
copyPermalink () {
|
|
this.permalinkInput.select();
|
|
try {
|
|
document.execCommand('copy');
|
|
this.setState({copySuccessful: true});
|
|
} catch (err) {
|
|
this.setState({copyFailure: true});
|
|
}
|
|
|
|
setTimeout(() => {
|
|
this.setState({copyFailure: null, copySuccessful: null});
|
|
}, 4500);
|
|
}
|
|
|
|
render () {
|
|
return (
|
|
<div className={`${name}-container`}>
|
|
<button onClick={this.toggle} className={`${name}-button`}>
|
|
<i className={`${name}-icon material-icons`} aria-hidden={true}>link</i>
|
|
{lang.t('permalink.permalink')}
|
|
</button>
|
|
<div
|
|
className={`${name}-popover ${this.state.popoverOpen ? 'active' : ''}`}>
|
|
<input
|
|
className={`${name}-copy-field`}
|
|
type='text'
|
|
ref={input => this.permalinkInput = input}
|
|
value={`${this.props.articleURL}#${this.props.commentId}`}
|
|
onChange={() => {}} />
|
|
<button className={`${name}-copy-button`} onClick={this.copyPermalink}>Copy</button>
|
|
{
|
|
this.state.copySuccessful ? <p className={`${name}-copied-text`}>copied to clipboard</p> : null
|
|
}
|
|
{
|
|
this.state.copyFailure
|
|
? <p className={`${name}-copied-error`}>copying to clipboard not supported in this browser. Use Cmd + C.</p>
|
|
: null
|
|
}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default onClickOutside(PermalinkButton);
|