2016-07-23 08:12:31 +08:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
import styles from './styles.scss';
|
2016-12-24 03:29:03 +08:00
|
|
|
import { findDOMNode } from 'react-dom';
|
2016-07-23 08:12:31 +08:00
|
|
|
|
|
|
|
export default class ClosedCaptions extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2016-12-24 03:29:03 +08:00
|
|
|
|
|
|
|
this.shouldScrollBottom = false;
|
2016-07-23 08:12:31 +08:00
|
|
|
}
|
|
|
|
|
2016-07-27 07:05:22 +08:00
|
|
|
renderCaptions(caption) {
|
2016-08-20 12:23:46 +08:00
|
|
|
let text = caption.captions;
|
2016-07-27 07:05:22 +08:00
|
|
|
return (
|
2016-08-20 12:23:46 +08:00
|
|
|
<span
|
2016-12-23 16:26:22 +08:00
|
|
|
style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word', fontFamily: this.props.fontFamily, fontSize: this.props.fontSize, color: this.props.fontColor }}
|
2016-08-20 12:23:46 +08:00
|
|
|
dangerouslySetInnerHTML={{ __html: text }}
|
|
|
|
key={caption.index}
|
|
|
|
/>
|
2016-07-27 07:05:22 +08:00
|
|
|
);
|
|
|
|
}
|
2016-07-23 08:12:31 +08:00
|
|
|
|
2016-12-24 03:29:03 +08:00
|
|
|
componentDidUpdate() {
|
|
|
|
const { ccScrollArea } = this.refs;
|
|
|
|
|
|
|
|
var node = findDOMNode(ccScrollArea);
|
|
|
|
node.scrollTop = node.scrollHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUpdate() {
|
|
|
|
const { ccScrollArea } = this.refs;
|
|
|
|
|
|
|
|
var node = findDOMNode(ccScrollArea);
|
|
|
|
// number 4 is for the border
|
|
|
|
// offset height includes the border, but scrollheight doesn't
|
|
|
|
this.shouldScrollBottom = node.scrollTop + node.offsetHeight - 4 === node.scrollHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
if (this.shouldScrollBottom) {
|
|
|
|
const { ccScrollArea } = this.refs;
|
|
|
|
var node = findDOMNode(ccScrollArea);
|
|
|
|
node.scrollTop = node.scrollHeight
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 07:05:22 +08:00
|
|
|
render() {
|
2016-07-23 08:12:31 +08:00
|
|
|
return (
|
2016-07-27 07:05:22 +08:00
|
|
|
<div disabled className={styles.ccbox}>
|
2016-12-21 07:54:39 +08:00
|
|
|
<div className={styles.title}>
|
2017-03-09 22:34:33 +08:00
|
|
|
<p> {this.props.locale > -1 ? this.props.locale : 'Locale is not selected'} </p>
|
2016-12-21 07:54:39 +08:00
|
|
|
</div>
|
2016-12-23 16:26:22 +08:00
|
|
|
<div
|
2016-12-24 03:29:03 +08:00
|
|
|
ref="ccScrollArea"
|
2016-12-23 16:26:22 +08:00
|
|
|
className={styles.frame}
|
|
|
|
style={{background: this.props.backgroundColor}}>
|
|
|
|
{this.props.captions[this.props.locale] ? this.props.captions[this.props.locale].captions.map((caption) => (
|
2016-12-21 07:54:39 +08:00
|
|
|
this.renderCaptions(caption)
|
|
|
|
)) : null }
|
|
|
|
</div>
|
2016-07-27 07:05:22 +08:00
|
|
|
</div>
|
2016-07-23 08:12:31 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|