mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-28 01:56:00 -05:00
Hide iframe & show spinner until it begins playing
This commit is contained in:
parent
cb01cb9321
commit
cf9cbdf392
2 changed files with 26 additions and 3 deletions
|
@ -40,4 +40,12 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.iframe-not-loaded {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.iframe-loaded {
|
||||||
|
visibility: visible;
|
||||||
}
|
}
|
|
@ -7,12 +7,18 @@ const classNames = require('classnames');
|
||||||
require('./video.scss');
|
require('./video.scss');
|
||||||
|
|
||||||
class Video extends React.Component {
|
class Video extends React.Component {
|
||||||
|
constructor (props) {
|
||||||
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
loaded: false
|
||||||
|
};
|
||||||
|
}
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
/**
|
/**
|
||||||
uses code snippets from
|
uses code snippets from
|
||||||
https://github.com/mrdavidjcole/wistia-player-react/blob/master/src/components/wistia_embed.js
|
https://github.com/mrdavidjcole/wistia-player-react/blob/master/src/components/wistia_embed.js
|
||||||
**/
|
**/
|
||||||
|
|
||||||
if (!document.getElementById('wistia_script')) {
|
if (!document.getElementById('wistia_script')) {
|
||||||
const wistiaScript = document.createElement('script');
|
const wistiaScript = document.createElement('script');
|
||||||
wistiaScript.id = 'wistia_script';
|
wistiaScript.id = 'wistia_script';
|
||||||
|
@ -25,18 +31,27 @@ class Video extends React.Component {
|
||||||
window._wq = window._wq || [];
|
window._wq = window._wq || [];
|
||||||
window._wq.push({
|
window._wq.push({
|
||||||
id: this.props.videoId,
|
id: this.props.videoId,
|
||||||
onReady: this.props.onLoad
|
onReady: video => {
|
||||||
|
video.bind('secondchange', s => {
|
||||||
|
if (s >= 0) {
|
||||||
|
this.setState({loaded: true});
|
||||||
|
this.props.onLoad();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
const loadedClass = this.state.loaded ? 'iframe-loaded' : 'iframe-not-loaded';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames('video-player', this.props.className)}>
|
<div className={classNames('video-player', this.props.className)}>
|
||||||
<iframe
|
<iframe
|
||||||
allowFullScreen
|
allowFullScreen
|
||||||
// allowFullScreen is legacy, can we start using allow='fullscreen'?
|
// allowFullScreen is legacy, can we start using allow='fullscreen'?
|
||||||
// allow="fullscreen"
|
// allow="fullscreen"
|
||||||
className={classNames('wistia_embed', `wistia_async_${this.props.videoId}`)}
|
className={classNames('wistia_embed', `wistia_async_${this.props.videoId}`, loadedClass)}
|
||||||
frameBorder="0" // deprecated attribute
|
frameBorder="0" // deprecated attribute
|
||||||
height={this.props.height}
|
height={this.props.height}
|
||||||
scrolling="no" // deprecated attribute
|
scrolling="no" // deprecated attribute
|
||||||
|
|
Loading…
Reference in a new issue