Skip to content

Commit

Permalink
Merge branch 'mosch-patch-1'
Browse files Browse the repository at this point in the history
* mosch-patch-1:
  Update README.md
  fixed syntax errors
  fixed reference to id
  Added auto-detection for "from" attribute
  • Loading branch information
pedronauck committed Jan 30, 2015
2 parents 5b37c46 + 87eb6f3 commit 793467a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Installing this component is very easy and it has just one dependency: [React](h
$ bower install --save react-video
```

- Or if you want to [download the lastest release](https://github.com/pedronauck/react-video/archive/v1.2.0.zip) and put in your website, it will work too!
- Or if you want to [download the lastest release](https://github.com/pedronauck/react-video/archive/v1.3.0.zip) and put in your website, it will work too!

**NOTICE:** You need just one thing to make the component work. Put the [base component style](./dist/react-video.css) at the `<header>` tag. If you don't wanna use the `.css` extension, you can get the `.styl` or `.scss` extension at the folder `./lib`.

Expand Down Expand Up @@ -86,7 +86,7 @@ For more details, check out the API below.

Property | Type | Default | Required | Description
-------- | ---- | ------- | -------- |-----------
from | `String` | none | yes | Video source: `youtube` or `vimeo`
from | `String` | none | no | Video source: `youtube` or `vimeo`. Leave empty and the service will be detected for you by looking a the id.
videoId | `String` | none | yes | The video ID

## Contributing
Expand Down
16 changes: 11 additions & 5 deletions lib/react-video.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var Spinner = require('./components/spinner');
module.exports = React.createClass({
displayName: 'Video',
propTypes: {
from: React.PropTypes.oneOf(['youtube', 'vimeo']).isRequired,
from: React.PropTypes.oneOf(['youtube', 'vimeo']),
videoId: React.PropTypes.string.isRequired
},
getDefaultProps() {
Expand All @@ -22,9 +22,15 @@ module.exports = React.createClass({
showingVideo: false
};
},
isYoutube() {
return this.props.from === 'youtube' || isNaN(this.props.id);
},
isVimeo() {
return this.props.from === 'vimeo' || !isNaN(this.props.id);
},
componentDidMount() {
this.props.from === 'youtube' && this.fetchYoutubeData();
this.props.from === 'vimeo' && this.fetchVimeoData();
this.isYoutube() && this.fetchYoutubeData();
this.isVimeo() && this.fetchVimeoData();
},
render() {
return (
Expand Down Expand Up @@ -68,10 +74,10 @@ module.exports = React.createClass({
ev.preventDefault();
},
getIframeUrl() {
if (this.props.from === 'youtube') {
if (this.isYoutube()) {
return `//youtube.com/embed/${this.props.videoId}?autoplay=1`
}
else if (this.props.from === 'vimeo') {
else if (this.isVimeo()) {
return `//player.vimeo.com/video/${this.props.videoId}?autoplay=1`
}
},
Expand Down

0 comments on commit 793467a

Please sign in to comment.