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() {
|
componentDidMount() {
|
||||||
UserStore.listen(this.onChange);
|
UserStore.listen(this.onChange);
|
||||||
UserActions.fetchCurrentUser();
|
UserActions.fetchCurrentUser.defer();
|
||||||
|
|
||||||
window.addEventListener('resize', this.handleResize);
|
window.addEventListener('resize', this.handleResize);
|
||||||
window.dispatchEvent(new Event('resize'));
|
window.dispatchEvent(new Event('resize'));
|
||||||
|
@ -8,7 +8,6 @@ import { InjectInHeadUtils } from '../../utils/inject_utils';
|
|||||||
|
|
||||||
let FacebookShareButton = React.createClass({
|
let FacebookShareButton = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
url: React.PropTypes.string,
|
|
||||||
type: 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
|
* 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.
|
* (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);
|
InjectInHeadUtils
|
||||||
} else {
|
.inject(AppConstants.facebook.sdkUrl)
|
||||||
// Parse() searches the children of the element we give it, not the element itself.
|
.then(() => { FB.XFBML.parse(this.refs.fbShareButton.getDOMNode().parentElement) });
|
||||||
FB.XFBML.parse(this.refs.fbShareButton.getDOMNode().parentElement);
|
},
|
||||||
}
|
|
||||||
|
shouldComponentUpdate(nextProps) {
|
||||||
|
return this.props.type !== nextProps.type;
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -41,7 +42,6 @@ let FacebookShareButton = React.createClass({
|
|||||||
<span
|
<span
|
||||||
ref="fbShareButton"
|
ref="fbShareButton"
|
||||||
className="fb-share-button btn btn-ascribe-social"
|
className="fb-share-button btn btn-ascribe-social"
|
||||||
data-href={this.props.url}
|
|
||||||
data-layout={this.props.type}>
|
data-layout={this.props.type}>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
@ -12,16 +12,16 @@ let mapTag = {
|
|||||||
css: 'link'
|
css: 'link'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let tags = {};
|
||||||
|
|
||||||
function injectTag(tag, src) {
|
function injectTag(tag, src) {
|
||||||
return Q.Promise((resolve, reject) => {
|
if(!tags[src]) {
|
||||||
if (isPresent(tag, src)) {
|
tags[src] = Q.Promise((resolve, reject) => {
|
||||||
resolve();
|
|
||||||
} else {
|
|
||||||
let attr = mapAttr[tag];
|
let attr = mapAttr[tag];
|
||||||
let element = document.createElement(tag);
|
let element = document.createElement(tag);
|
||||||
if (tag === 'script') {
|
if (tag === 'script') {
|
||||||
element.onload = () => resolve();
|
element.onload = resolve;
|
||||||
element.onerror = () => reject();
|
element.onerror = reject;
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
@ -30,14 +30,10 @@ function injectTag(tag, src) {
|
|||||||
if (tag === 'link') {
|
if (tag === 'link') {
|
||||||
element.rel = 'stylesheet';
|
element.rel = 'stylesheet';
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function isPresent(tag, src) {
|
return tags[src];
|
||||||
let attr = mapAttr[tag];
|
|
||||||
let query = `head > ${tag}[${attr}="${src}"]`;
|
|
||||||
return document.querySelector(query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function injectStylesheet(src) {
|
function injectStylesheet(src) {
|
||||||
@ -65,7 +61,6 @@ export const InjectInHeadUtils = {
|
|||||||
* you don't want to embed everything inside the build file.
|
* you don't want to embed everything inside the build file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
isPresent,
|
|
||||||
injectStylesheet,
|
injectStylesheet,
|
||||||
injectScript,
|
injectScript,
|
||||||
inject
|
inject
|
||||||
|
Loading…
Reference in New Issue
Block a user