mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-24 08:08:18 -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%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.iframe-not-loaded {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.iframe-loaded {
|
||||
visibility: visible;
|
||||
}
|
|
@ -7,12 +7,18 @@ const classNames = require('classnames');
|
|||
require('./video.scss');
|
||||
|
||||
class Video extends React.Component {
|
||||
constructor (props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
loaded: false
|
||||
};
|
||||
}
|
||||
componentDidMount () {
|
||||
/**
|
||||
uses code snippets from
|
||||
https://github.com/mrdavidjcole/wistia-player-react/blob/master/src/components/wistia_embed.js
|
||||
**/
|
||||
|
||||
if (!document.getElementById('wistia_script')) {
|
||||
const wistiaScript = document.createElement('script');
|
||||
wistiaScript.id = 'wistia_script';
|
||||
|
@ -25,18 +31,27 @@ class Video extends React.Component {
|
|||
window._wq = window._wq || [];
|
||||
window._wq.push({
|
||||
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 () {
|
||||
const loadedClass = this.state.loaded ? 'iframe-loaded' : 'iframe-not-loaded';
|
||||
|
||||
return (
|
||||
<div className={classNames('video-player', this.props.className)}>
|
||||
<iframe
|
||||
allowFullScreen
|
||||
// allowFullScreen is legacy, can we start using 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
|
||||
height={this.props.height}
|
||||
scrolling="no" // deprecated attribute
|
||||
|
|
Loading…
Reference in a new issue