2017-09-26 07:45:44 +08:00
|
|
|
import React, { Component } from 'react';
|
2017-06-04 10:40:14 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-09-26 07:45:44 +08:00
|
|
|
import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component';
|
2016-07-23 08:12:31 +08:00
|
|
|
import styles from './styles.scss';
|
|
|
|
|
2017-09-26 07:45:44 +08:00
|
|
|
class ClosedCaptions extends Component {
|
2016-07-23 08:12:31 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2016-12-24 03:29:03 +08:00
|
|
|
|
|
|
|
this.shouldScrollBottom = false;
|
2016-07-23 08:12:31 +08:00
|
|
|
}
|
|
|
|
|
2017-09-26 07:45:44 +08:00
|
|
|
componentWillUpdate() {
|
|
|
|
const node = this.refCCScrollArea;
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
this.refCCScrollArea.scrollTop = this.refCCScrollArea.scrollHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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-09-26 07:45:44 +08:00
|
|
|
<p> {locale} </p>
|
2016-12-21 07:54:39 +08:00
|
|
|
</div>
|
2016-12-23 16:26:22 +08:00
|
|
|
<div
|
2017-09-26 07:45:44 +08:00
|
|
|
ref={(ref) => { this.refCCScrollArea = 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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 07:45:44 +08:00
|
|
|
|
|
|
|
export default injectWbResizeEvent(ClosedCaptions);
|
|
|
|
|
|
|
|
ClosedCaptions.propTypes = {
|
|
|
|
backgroundColor: PropTypes.string.isRequired,
|
|
|
|
captions: PropTypes.arrayOf(
|
|
|
|
PropTypes.shape({
|
|
|
|
ownerId: PropTypes.string.isRequired,
|
|
|
|
captions: PropTypes.arrayOf(
|
|
|
|
PropTypes.shape({
|
|
|
|
captions: PropTypes.string.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
).isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
).isRequired,
|
|
|
|
locale: PropTypes.string.isRequired,
|
|
|
|
fontColor: PropTypes.string.isRequired,
|
|
|
|
fontSize: PropTypes.string.isRequired,
|
|
|
|
fontFamily: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
ClosedCaptions.defaultProps = {
|
|
|
|
locale: 'Locale is not selected',
|
|
|
|
};
|