2015-11-09 17:46:49 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import AppConstants from '../../constants/application_constants';
|
|
|
|
|
|
|
|
import { InjectInHeadUtils } from '../../utils/inject_utils';
|
|
|
|
|
|
|
|
let FacebookShareButton = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
type: React.PropTypes.string
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps() {
|
|
|
|
return {
|
|
|
|
type: 'button'
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
/**
|
|
|
|
* Ideally we would only use FB.XFBML.parse() on the component that we're
|
|
|
|
* mounting, but doing this when we first load the FB sdk causes unpredictable behaviour.
|
|
|
|
* The button sometimes doesn't get initialized, likely because FB hasn't properly
|
|
|
|
* been initialized yet.
|
|
|
|
*
|
|
|
|
* To circumvent this, we always have the sdk parse the entire DOM on the initial load
|
|
|
|
* (see FacebookHandler) and then use FB.XFBML.parse() on the mounting component later.
|
|
|
|
*/
|
2015-11-23 19:02:28 +01:00
|
|
|
|
|
|
|
InjectInHeadUtils
|
|
|
|
.inject(AppConstants.facebook.sdkUrl)
|
|
|
|
.then(() => { FB.XFBML.parse(this.refs.fbShareButton.getDOMNode().parentElement) });
|
|
|
|
},
|
|
|
|
|
|
|
|
shouldComponentUpdate(nextProps) {
|
|
|
|
return this.props.type !== nextProps.type;
|
2015-11-09 17:46:49 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<span
|
|
|
|
ref="fbShareButton"
|
2015-11-09 19:01:27 +01:00
|
|
|
className="fb-share-button btn btn-ascribe-social"
|
2015-11-09 17:46:49 +01:00
|
|
|
data-layout={this.props.type}>
|
2015-11-13 13:33:27 +01:00
|
|
|
</span>
|
2015-11-09 17:46:49 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default FacebookShareButton;
|