mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 01:25:17 +01:00
Add Facebook Share button
This commit is contained in:
parent
7c73b7fac7
commit
d972da935a
@ -30,6 +30,7 @@ import GoogleAnalyticsHandler from './third_party/ga';
|
||||
import RavenHandler from './third_party/raven';
|
||||
import IntercomHandler from './third_party/intercom';
|
||||
import NotificationsHandler from './third_party/notifications';
|
||||
import FacebookHandler from './third_party/facebook';
|
||||
/* eslint-enable */
|
||||
|
||||
initLogging();
|
||||
|
@ -7,6 +7,8 @@ import Glyphicon from 'react-bootstrap/lib/Glyphicon';
|
||||
|
||||
import MediaPlayer from './../ascribe_media/media_player';
|
||||
|
||||
import FacebookShareButton from '../ascribe_social_share/facebook_share_button';
|
||||
|
||||
import CollapsibleButton from './../ascribe_collapsible/collapsible_button';
|
||||
|
||||
import AclProxy from '../acl_proxy';
|
||||
@ -95,6 +97,7 @@ let MediaContainer = React.createClass({
|
||||
Download <Glyphicon glyph="cloud-download"/>
|
||||
</Button>
|
||||
</AclProxy>
|
||||
<FacebookShareButton />
|
||||
{embed}
|
||||
</p>
|
||||
</div>
|
||||
|
52
js/components/ascribe_social_share/facebook_share_button.js
Normal file
52
js/components/ascribe_social_share/facebook_share_button.js
Normal file
@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import AppConstants from '../../constants/application_constants';
|
||||
|
||||
import { InjectInHeadUtils } from '../../utils/inject_utils';
|
||||
|
||||
let FacebookShareButton = React.createClass({
|
||||
propTypes: {
|
||||
url: React.PropTypes.string,
|
||||
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.
|
||||
*/
|
||||
if (!InjectInHeadUtils.isPresent('script', AppConstants.facebook.sdkUrl)) {
|
||||
InjectInHeadUtils.inject(AppConstants.facebook.sdkUrl);
|
||||
} else {
|
||||
// Parse() searches the children of the element we give it, not the element itself.
|
||||
FB.XFBML.parse(this.refs.fbShareButton.getDOMNode().parentElement);
|
||||
}
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<span
|
||||
ref="fbShareButton"
|
||||
style={{width: '56px', height: '24px'}}
|
||||
className="fb-share-button btn btn-xs"
|
||||
data-href={this.props.url}
|
||||
data-layout={this.props.type}>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export default FacebookShareButton;
|
@ -75,6 +75,10 @@ let constants = {
|
||||
'raven': {
|
||||
'url': 'https://0955da3388c64ab29bd32c2a429f9ef4@app.getsentry.com/48351'
|
||||
},
|
||||
'facebook': {
|
||||
'appId': '420813844732240',
|
||||
'sdkUrl': '//connect.facebook.net/en_US/sdk.js'
|
||||
},
|
||||
'copyrightAssociations': ['ARS', 'DACS', 'Bildkunst', 'Pictoright', 'SODRAC', 'Copyright Agency/Viscopy', 'SAVA',
|
||||
'Bildrecht GmbH', 'SABAM', 'AUTVIS', 'CREAIMAGEN', 'SONECA', 'Copydan', 'EAU', 'Kuvasto', 'GCA', 'HUNGART',
|
||||
'IVARO', 'SIAE', 'JASPAR-SPDA', 'AKKA/LAA', 'LATGA-A', 'SOMAAP', 'ARTEGESTION', 'CARIER', 'BONO', 'APSAV',
|
||||
|
30
js/third_party/facebook.js
vendored
Normal file
30
js/third_party/facebook.js
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
import { altThirdParty } from '../alt';
|
||||
import EventActions from '../actions/event_actions';
|
||||
|
||||
import AppConstants from '../constants/application_constants'
|
||||
|
||||
class FacebookHandler {
|
||||
constructor() {
|
||||
this.bindActions(EventActions);
|
||||
}
|
||||
|
||||
onApplicationWillBoot(settings) {
|
||||
// Callback function that FB's sdk will call when it's finished loading
|
||||
// See https://developers.facebook.com/docs/javascript/quickstart/v2.5
|
||||
window.fbAsyncInit = () => {
|
||||
FB.init({
|
||||
appId: AppConstants.facebook.appId,
|
||||
// Force FB to parse everything on first load to make sure all the XFBML components are initialized.
|
||||
// If we don't do this, we can run into issues with components on the first load who are not be
|
||||
// initialized.
|
||||
xfbml: true,
|
||||
version: 'v2.5',
|
||||
cookie: false
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default altThirdParty.createStore(FacebookHandler, 'FacebookHandler');
|
Loading…
Reference in New Issue
Block a user