mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-02-17 00:21:20 -05:00
Merge pull request #170 from rschamp/bugfix/GH-148
Handle relaunch requests from the iframe
This commit is contained in:
commit
b1c73d8168
1 changed files with 17 additions and 3 deletions
|
@ -13,13 +13,27 @@ var Registration = React.createClass({
|
||||||
},
|
},
|
||||||
onMessage: function (e) {
|
onMessage: function (e) {
|
||||||
if (e.origin != window.location.origin) return;
|
if (e.origin != window.location.origin) return;
|
||||||
|
if (e.source != this.refs.registrationIframe.contentWindow) return;
|
||||||
if (e.data == 'registration-done') this.props.onRegistrationDone();
|
if (e.data == 'registration-done') this.props.onRegistrationDone();
|
||||||
|
if (e.data == 'registration-relaunch') {
|
||||||
|
this.refs.registrationIframe.contentWindow.location.reload();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
toggleMessageListener: function (present) {
|
||||||
|
if (present) {
|
||||||
|
window.addEventListener('message', this.onMessage);
|
||||||
|
} else {
|
||||||
|
window.removeEventListener('message', this.onMessage);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
componentDidMount: function () {
|
componentDidMount: function () {
|
||||||
window.addEventListener('message', this.onMessage);
|
if (this.props.isOpen) this.toggleMessageListener(true);
|
||||||
|
},
|
||||||
|
componentDidUpdate: function (prevProps) {
|
||||||
|
this.toggleMessageListener(this.props.isOpen && !prevProps.isOpen);
|
||||||
},
|
},
|
||||||
componentWillUnmount: function () {
|
componentWillUnmount: function () {
|
||||||
window.removeEventListener('message', this.onMessage);
|
this.toggleMessageListener(false);
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
var frameProps = {
|
var frameProps = {
|
||||||
|
@ -32,7 +46,7 @@ var Registration = React.createClass({
|
||||||
onRequestClose={this.props.onRequestClose}
|
onRequestClose={this.props.onRequestClose}
|
||||||
className="registration"
|
className="registration"
|
||||||
style={{content:frameProps}}>
|
style={{content:frameProps}}>
|
||||||
<iframe src="/accounts/standalone-registration/" {...frameProps} />
|
<iframe ref="registrationIframe" src="/accounts/standalone-registration/" {...frameProps} />
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue