mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +01:00
Fix bug in FB button component & simplify injectHead util
This commit is contained in:
parent
bccfc0906f
commit
e4cafd4bc3
@ -41,7 +41,7 @@ let AclButtonList = React.createClass({
|
||||
|
||||
componentDidMount() {
|
||||
UserStore.listen(this.onChange);
|
||||
UserActions.fetchCurrentUser();
|
||||
UserActions.fetchCurrentUser.defer();
|
||||
|
||||
window.addEventListener('resize', this.handleResize);
|
||||
window.dispatchEvent(new Event('resize'));
|
||||
|
@ -8,7 +8,6 @@ import { InjectInHeadUtils } from '../../utils/inject_utils';
|
||||
|
||||
let FacebookShareButton = React.createClass({
|
||||
propTypes: {
|
||||
url: React.PropTypes.string,
|
||||
type: React.PropTypes.string
|
||||
},
|
||||
|
||||
@ -28,12 +27,14 @@ let FacebookShareButton = React.createClass({
|
||||
* 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);
|
||||
}
|
||||
|
||||
InjectInHeadUtils
|
||||
.inject(AppConstants.facebook.sdkUrl)
|
||||
.then(() => { FB.XFBML.parse(this.refs.fbShareButton.getDOMNode().parentElement) });
|
||||
},
|
||||
|
||||
shouldComponentUpdate(nextProps) {
|
||||
return this.props.type !== nextProps.type;
|
||||
},
|
||||
|
||||
render() {
|
||||
@ -41,7 +42,6 @@ let FacebookShareButton = React.createClass({
|
||||
<span
|
||||
ref="fbShareButton"
|
||||
className="fb-share-button btn btn-ascribe-social"
|
||||
data-href={this.props.url}
|
||||
data-layout={this.props.type}>
|
||||
</span>
|
||||
);
|
||||
|
@ -12,16 +12,16 @@ let mapTag = {
|
||||
css: 'link'
|
||||
};
|
||||
|
||||
let tags = {};
|
||||
|
||||
function injectTag(tag, src) {
|
||||
return Q.Promise((resolve, reject) => {
|
||||
if (isPresent(tag, src)) {
|
||||
resolve();
|
||||
} else {
|
||||
if(!tags[src]) {
|
||||
tags[src] = Q.Promise((resolve, reject) => {
|
||||
let attr = mapAttr[tag];
|
||||
let element = document.createElement(tag);
|
||||
if (tag === 'script') {
|
||||
element.onload = () => resolve();
|
||||
element.onerror = () => reject();
|
||||
element.onload = resolve;
|
||||
element.onerror = reject;
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
@ -30,14 +30,10 @@ function injectTag(tag, src) {
|
||||
if (tag === 'link') {
|
||||
element.rel = 'stylesheet';
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function isPresent(tag, src) {
|
||||
let attr = mapAttr[tag];
|
||||
let query = `head > ${tag}[${attr}="${src}"]`;
|
||||
return document.querySelector(query);
|
||||
return tags[src];
|
||||
}
|
||||
|
||||
function injectStylesheet(src) {
|
||||
@ -65,7 +61,6 @@ export const InjectInHeadUtils = {
|
||||
* you don't want to embed everything inside the build file.
|
||||
*/
|
||||
|
||||
isPresent,
|
||||
injectStylesheet,
|
||||
injectScript,
|
||||
inject
|
||||
|
Loading…
Reference in New Issue
Block a user