2019-01-26 02:19:54 +08:00
|
|
|
import React from 'react';
|
2017-06-04 10:40:14 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2019-01-26 02:19:54 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-09-26 07:45:44 +08:00
|
|
|
import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component';
|
2018-01-08 14:17:18 +08:00
|
|
|
import { styles } from './styles.scss';
|
2016-07-23 08:12:31 +08:00
|
|
|
|
2019-01-26 02:19:54 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
noLocaleSelected: {
|
|
|
|
id: 'app.submenu.closedCaptions.noLocaleSelected',
|
|
|
|
description: 'label for selected language for closed captions',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
class ClosedCaptions extends React.PureComponent {
|
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) {
|
2019-01-26 02:19:54 +08:00
|
|
|
const { fontFamily, fontSize, fontColor } = this.props;
|
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',
|
2019-01-26 02:19:54 +08:00
|
|
|
fontFamily,
|
|
|
|
fontSize,
|
|
|
|
color: fontColor,
|
2017-05-04 05:54:26 +08:00
|
|
|
};
|
|
|
|
|
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,
|
2019-01-26 02:19:54 +08:00
|
|
|
intl,
|
2017-05-04 05:54:26 +08:00
|
|
|
} = 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}>
|
2019-01-26 02:19:54 +08:00
|
|
|
<p>
|
|
|
|
{ locale || intl.formatMessage(intlMessages.noLocaleSelected) }
|
|
|
|
</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
|
|
|
|
2019-01-26 02:19:54 +08:00
|
|
|
export default injectIntl(injectWbResizeEvent(ClosedCaptions));
|
2017-09-26 07:45:44 +08:00
|
|
|
|
|
|
|
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,
|
2019-01-26 02:19:54 +08:00
|
|
|
locale: PropTypes.string,
|
2017-09-26 07:45:44 +08:00
|
|
|
fontColor: PropTypes.string.isRequired,
|
|
|
|
fontSize: PropTypes.string.isRequired,
|
|
|
|
fontFamily: PropTypes.string.isRequired,
|
2019-01-26 02:19:54 +08:00
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
2017-09-26 07:45:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
ClosedCaptions.defaultProps = {
|
2019-01-26 02:19:54 +08:00
|
|
|
locale: undefined,
|
2017-09-26 07:45:44 +08:00
|
|
|
};
|