2017-06-04 10:40:14 +08:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2016-07-23 08:12:31 +08:00
|
|
|
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) {
|
2017-06-03 03:25:02 +08:00
|
|
|
const text = caption.captions;
|
2017-05-04 05:54:26 +08:00
|
|
|
const captionStyles = {
|
|
|
|
whiteSpace: 'pre-wrap',
|
|
|
|
wordWrap: 'break-word',
|
|
|
|
fontFamily: this.props.fontFamily,
|
|
|
|
fontSize: this.props.fontSize,
|
|
|
|
color: this.props.fontColor,
|
|
|
|
};
|
|
|
|
|
2016-07-27 07:05:22 +08:00
|
|
|
return (
|
2016-08-20 12:23:46 +08:00
|
|
|
<span
|
2017-05-04 05:54:26 +08:00
|
|
|
style={captionStyles}
|
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
|
|
|
|
2017-03-24 05:52:36 +08:00
|
|
|
componentDidMount() {
|
2017-09-07 03:36:52 +08:00
|
|
|
// to let the whiteboard know that the presentation area's size has changed
|
2017-03-24 05:52:36 +08:00
|
|
|
window.dispatchEvent(new Event('resize'));
|
|
|
|
}
|
2016-12-24 03:29:03 +08:00
|
|
|
|
2017-03-24 05:52:36 +08:00
|
|
|
componentWillUnmount() {
|
2017-09-07 03:36:52 +08:00
|
|
|
// to let the whiteboard know that the presentation area's size has changed
|
2017-03-24 05:52:36 +08:00
|
|
|
window.dispatchEvent(new Event('resize'));
|
2016-12-24 03:29:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUpdate() {
|
2017-06-04 07:58:27 +08:00
|
|
|
const node = findDOMNode(this.ccScrollArea);
|
2017-05-04 05:54:26 +08:00
|
|
|
|
2016-12-24 03:29:03 +08:00
|
|
|
// 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) {
|
2017-06-04 07:58:27 +08:00
|
|
|
const node = findDOMNode(this.ccScrollArea);
|
2017-05-04 05:54:26 +08:00
|
|
|
node.scrollTop = node.scrollHeight;
|
2016-12-24 03:29:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 07:05:22 +08:00
|
|
|
render() {
|
2017-05-04 05:54:26 +08:00
|
|
|
const {
|
|
|
|
locale,
|
|
|
|
captions,
|
|
|
|
backgroundColor,
|
|
|
|
} = this.props;
|
|
|
|
|
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-06-03 03:25:02 +08:00
|
|
|
<p> {locale || 'Locale is not selected'} </p>
|
2016-12-21 07:54:39 +08:00
|
|
|
</div>
|
2016-12-23 16:26:22 +08:00
|
|
|
<div
|
2017-06-04 07:58:27 +08:00
|
|
|
ref={(ref) => { this.ccScrollArea = ref; }}
|
2016-12-23 16:26:22 +08:00
|
|
|
className={styles.frame}
|
2017-06-03 03:25:02 +08:00
|
|
|
style={{ background: backgroundColor }}
|
|
|
|
>
|
|
|
|
{captions[locale] ? captions[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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|