-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
57 lines (46 loc) · 1.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
var React = require('react');
var Diaporama = require('diaporama');
var PropTypes = React.PropTypes;
function affectProps (obj, props) {
for (var k in props) {
if (k !== "onDiaporamaCreated") // blacklisting only for now. We might do whitelist instead ?
obj[k] = props[k];
}
return obj;
}
var DiaporamaElement = React.createClass({
displayName: 'DiaporamaElement',
propTypes: {
data: PropTypes.object.isRequired,
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
resolution: PropTypes.number,
paused: PropTypes.bool,
loop: PropTypes.bool,
autoplay: PropTypes.bool,
currentTime: PropTypes.number,
playbackRate: PropTypes.number,
onDiaporamaCreated: PropTypes.func // callback giving the diaporama instance. use-case: You can bind Events on the diaporama. See "diaporama" documentation.
},
componentDidMount: function () {
var opts = affectProps({}, this.props);
this.diaporama = Diaporama(this.refs.container, opts);
if (this.props.onDiaporamaCreated) {
this.props.onDiaporamaCreated(this.diaporama);
}
},
componentWillUnmount: function () {
this.diaporama.destroy();
},
componentWillReceiveProps: function (props) {
affectProps(this.diaporama, props);
},
shouldComponentUpdate: function () {
return false;
},
render: function () {
return (<div ref='container' />);
}
});
module.exports = DiaporamaElement;