2016-12-23 16:26:22 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Modal from 'react-modal';
|
|
|
|
import styles from '../styles';
|
2017-02-16 02:49:40 +08:00
|
|
|
import cx from 'classnames';
|
|
|
|
import BaseMenu from '../base/component';
|
|
|
|
import Toggle from '/imports/ui/components/switch/component';
|
|
|
|
import Checkbox from '/imports/ui/components/checkbox/component';
|
2017-03-09 22:34:33 +08:00
|
|
|
import { GithubPicker } from 'react-color';
|
2017-04-11 04:27:29 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2016-12-23 16:26:22 +08:00
|
|
|
|
|
|
|
//an array of font-families
|
2017-02-16 02:49:40 +08:00
|
|
|
const FONT_FAMILIES = ['Arial', 'Calibri', 'Time New Roman', 'Sans-serif'];
|
|
|
|
|
2016-12-23 16:26:22 +08:00
|
|
|
//an array of different font-sizes
|
2017-02-16 02:49:40 +08:00
|
|
|
const FONT_SIZES = ['12px', '14px', '18px', '24px', '32px', '42px'];
|
|
|
|
|
2016-12-23 16:26:22 +08:00
|
|
|
//an array of colors for both background and text
|
2017-02-16 02:49:40 +08:00
|
|
|
const COLORS = [
|
|
|
|
'#000000', '#7A7A7A', '#FF0000', '#FF8800',
|
|
|
|
'#88FF00', '#FFFFFF', '#00FFFF', '#0000FF',
|
|
|
|
'#8800FF', '#FF00FF',
|
|
|
|
];
|
2016-12-23 16:26:22 +08:00
|
|
|
|
2017-04-11 04:27:29 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
closedCaptionsLabel: {
|
|
|
|
id: 'app.submenu.closedCaptions.closedCaptionsLabel',
|
|
|
|
description: 'Closed Captions label',
|
|
|
|
},
|
|
|
|
takeOwnershipLabel: {
|
|
|
|
id: 'app.submenu.closedCaptions.takeOwnershipLabel',
|
|
|
|
description: 'Take ownership label',
|
|
|
|
},
|
|
|
|
languageLabel: {
|
|
|
|
id: 'app.submenu.closedCaptions.languageLabel',
|
|
|
|
description: 'Language label',
|
|
|
|
},
|
|
|
|
localeOptionLabel: {
|
|
|
|
id: 'app.submenu.closedCaptions.localeOptionLabel',
|
|
|
|
description: 'Label for active locales',
|
|
|
|
},
|
|
|
|
noLocaleOptionLabel: {
|
|
|
|
id: 'app.submenu.closedCaptions.noLocaleOptionLabel',
|
|
|
|
description: 'Label for no active locales',
|
|
|
|
},
|
|
|
|
fontFamilyLabel: {
|
|
|
|
id: 'app.submenu.closedCaptions.fontFamilyLabel',
|
|
|
|
description: 'Label for type of Font family',
|
|
|
|
},
|
|
|
|
fontFamilyOptionLabel: {
|
|
|
|
id: 'app.submenu.closedCaptions.fontFamilyOptionLabel',
|
|
|
|
description: 'Font-family default choice option',
|
|
|
|
},
|
|
|
|
fontSizeLabel: {
|
|
|
|
id: 'app.submenu.closedCaptions.fontSizeLabel',
|
|
|
|
description: 'Font size label',
|
|
|
|
},
|
|
|
|
fontSizeOptionLabel: {
|
|
|
|
id: 'app.submenu.closedCaptions.fontSizeOptionLabel',
|
|
|
|
description: 'Choose Font size default option label',
|
|
|
|
},
|
|
|
|
backgroundColorLabel: {
|
|
|
|
id: 'app.submenu.closedCaptions.backgroundColorLabel',
|
|
|
|
description: 'Background color label',
|
|
|
|
},
|
|
|
|
fontColorLabel: {
|
|
|
|
id: 'app.submenu.closedCaptions.fontColorLabel',
|
|
|
|
description: 'Font color label',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
class ClosedCaptionsMenu extends BaseMenu {
|
2016-12-23 16:26:22 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2017-02-16 02:49:40 +08:00
|
|
|
settingsName: 'cc',
|
2017-02-22 04:29:36 +08:00
|
|
|
settings: {
|
|
|
|
backgroundColor: props.settings ? props.settings.backgroundColor : '#f3f6f9',
|
|
|
|
fontColor: props.settings ? props.settings.fontColor : '#000000',
|
2017-04-06 19:46:15 +08:00
|
|
|
enabled: props.settings ? props.settings.enabled : false,
|
2017-02-22 04:29:36 +08:00
|
|
|
fontFamily: props.settings ? props.settings.fontFamily : 'Calibri',
|
|
|
|
fontSize: props.settings ? props.settings.fontSize : -1,
|
|
|
|
locale: props.settings ? props.settings.locale : -1,
|
|
|
|
takeOwnership: props.settings ? props.settings.takeOwnership : false,
|
|
|
|
},
|
2017-02-16 02:49:40 +08:00
|
|
|
};
|
2016-12-23 16:26:22 +08:00
|
|
|
}
|
|
|
|
|
2017-02-16 02:49:40 +08:00
|
|
|
getPreviewStyle() {
|
|
|
|
return {
|
2017-02-25 04:19:53 +08:00
|
|
|
fontFamily: this.state.settings.fontFamily,
|
|
|
|
fontSize: this.state.settings.fontSize,
|
|
|
|
color: this.state.settings.fontColor,
|
2017-02-16 02:49:40 +08:00
|
|
|
};
|
2016-12-23 16:26:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//clickhandler, opens a selected color picker (supports both of them)
|
|
|
|
handleColorPickerClick(fieldname) {
|
|
|
|
let obj = {};
|
|
|
|
obj[fieldname] = !this.state[fieldname];
|
|
|
|
this.setState(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
//closes color pickers
|
|
|
|
handleCloseColorPicker() {
|
2017-02-16 02:49:40 +08:00
|
|
|
this.setState({
|
|
|
|
displayBackgroundColorPicker: false,
|
|
|
|
displayFontColorPicker:false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSelectChange(fieldname, options, e) {
|
|
|
|
let obj = this.state;
|
2017-02-22 04:29:36 +08:00
|
|
|
obj.settings[fieldname] = options[e.target.value];
|
2017-02-16 02:49:40 +08:00
|
|
|
this.setState(obj);
|
2017-02-22 04:29:36 +08:00
|
|
|
this.handleUpdateSettings('cc', obj.settings);
|
2016-12-23 16:26:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handleColorChange(fieldname, color) {
|
2017-02-22 04:29:36 +08:00
|
|
|
let obj = this.state;
|
|
|
|
obj.settings[fieldname] = color.hex;
|
2017-02-16 02:49:40 +08:00
|
|
|
|
2016-12-23 16:26:22 +08:00
|
|
|
this.setState(obj);
|
2017-02-22 04:29:36 +08:00
|
|
|
this.handleUpdateSettings('cc', obj.settings);
|
2017-03-09 22:34:33 +08:00
|
|
|
this.handleCloseColorPicker();
|
2016-12-23 16:26:22 +08:00
|
|
|
}
|
|
|
|
|
2017-02-16 02:49:40 +08:00
|
|
|
render() {
|
2017-02-22 04:29:36 +08:00
|
|
|
const {
|
|
|
|
locales,
|
2017-04-11 04:27:29 +08:00
|
|
|
intl
|
2017-02-22 04:29:36 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2016-12-23 16:26:22 +08:00
|
|
|
return (
|
2017-02-16 02:49:40 +08:00
|
|
|
<div className={styles.tabContent}>
|
|
|
|
<div className={styles.header}>
|
2017-04-11 04:27:29 +08:00
|
|
|
<h3 className={styles.title}>{intl.formatMessage(intlMessages.closedCaptionsLabel)}</h3>
|
2016-12-23 16:26:22 +08:00
|
|
|
</div>
|
2017-02-16 02:49:40 +08:00
|
|
|
<div className={styles.form}>
|
|
|
|
<div className={styles.row}>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={styles.formElement}>
|
|
|
|
<label className={styles.label}>
|
2017-04-11 04:27:29 +08:00
|
|
|
{intl.formatMessage(intlMessages.closedCaptionsLabel)}
|
2017-02-16 02:49:40 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={cx(styles.formElement, styles.pullContentRight)}>
|
|
|
|
<Toggle
|
|
|
|
icons={false}
|
2017-04-06 19:46:15 +08:00
|
|
|
defaultChecked={this.state.settings.enabled}
|
|
|
|
onChange={() => this.handleToggle('enabled')} />
|
2017-02-16 02:49:40 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={cx(styles.row, styles.spacedLeft)}>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={styles.formElement}>
|
|
|
|
<label className={styles.label}>
|
2017-04-11 04:27:29 +08:00
|
|
|
{intl.formatMessage(intlMessages.takeOwnershipLabel)}
|
2017-02-16 02:49:40 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={cx(styles.formElement, styles.pullContentRight)}>
|
|
|
|
<Checkbox
|
|
|
|
onChange={() => this.handleToggle('takeOwnership')}
|
2017-02-22 04:29:36 +08:00
|
|
|
checked={this.state.settings.takeOwnership}/>
|
2017-02-16 02:49:40 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={cx(styles.row, styles.spacedLeft)}>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={styles.formElement}>
|
|
|
|
<label className={styles.label}>
|
2017-04-11 04:27:29 +08:00
|
|
|
{intl.formatMessage(intlMessages.languageLabel)}
|
2017-02-16 02:49:40 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={cx(styles.formElement, styles.pullContentRight)}>
|
|
|
|
<select
|
2017-02-22 04:29:36 +08:00
|
|
|
defaultValue={locales ? locales.indexOf(this.state.settings.locale) : -1}
|
2017-02-16 02:49:40 +08:00
|
|
|
className={styles.select}
|
|
|
|
onChange={this.handleSelectChange.bind(this, 'locale', this.props.locales)}>
|
|
|
|
<option>
|
|
|
|
{ this.props.locales &&
|
|
|
|
this.props.locales.length ?
|
2017-04-11 04:27:29 +08:00
|
|
|
intl.formatMessage(intlMessages.localeOptionLabel) :
|
|
|
|
intl.formatMessage(intlMessages.noLocaleOptionLabel) }
|
2017-02-16 02:49:40 +08:00
|
|
|
</option>
|
2016-12-23 16:26:22 +08:00
|
|
|
{this.props.locales ? this.props.locales.map((locale, index) =>
|
2017-02-16 02:49:40 +08:00
|
|
|
<option key={index} value={index}>
|
|
|
|
{locale}
|
|
|
|
</option>
|
|
|
|
) : null }
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-12-23 16:26:22 +08:00
|
|
|
</div>
|
|
|
|
|
2017-02-16 02:49:40 +08:00
|
|
|
<div className={cx(styles.row, styles.spacedLeft)}>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={styles.formElement}>
|
|
|
|
<label className={styles.label}>
|
2017-04-11 04:27:29 +08:00
|
|
|
{intl.formatMessage(intlMessages.fontFamilyLabel)}
|
2017-02-16 02:49:40 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={cx(styles.formElement, styles.pullContentRight)}>
|
|
|
|
<select
|
2017-02-22 04:29:36 +08:00
|
|
|
defaultValue={FONT_FAMILIES.indexOf(this.state.settings.fontFamily)}
|
2017-02-16 02:49:40 +08:00
|
|
|
onChange={this.handleSelectChange.bind(this, 'fontFamily', FONT_FAMILIES)}
|
|
|
|
className={styles.select}>
|
2017-04-11 04:27:29 +08:00
|
|
|
<option value='-1' disabled>{intl.formatMessage(intlMessages.fontFamilyOptionLabel)}</option>
|
2017-02-16 02:49:40 +08:00
|
|
|
{
|
|
|
|
FONT_FAMILIES.map((family, index) =>
|
|
|
|
<option key={index} value={index}>
|
|
|
|
{family}
|
|
|
|
</option>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-12-23 16:26:22 +08:00
|
|
|
</div>
|
|
|
|
|
2017-02-16 02:49:40 +08:00
|
|
|
<div className={cx(styles.row, styles.spacedLeft)}>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={styles.formElement}>
|
|
|
|
<label className={styles.label}>
|
2017-04-11 04:27:29 +08:00
|
|
|
{intl.formatMessage(intlMessages.fontSizeLabel)}
|
2017-02-16 02:49:40 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={cx(styles.formElement, styles.pullContentRight)}>
|
|
|
|
<select
|
2017-02-22 04:29:36 +08:00
|
|
|
defaultValue={FONT_SIZES.indexOf(this.state.settings.fontSize)}
|
2017-02-16 02:49:40 +08:00
|
|
|
onChange={this.handleSelectChange.bind(this, 'fontSize', FONT_SIZES)}
|
|
|
|
className={styles.select}>
|
2017-04-11 04:27:29 +08:00
|
|
|
<option value='-1' disabled>{intl.formatMessage(intlMessages.fontSizeOptionLabel)}</option>
|
2017-02-16 02:49:40 +08:00
|
|
|
{
|
|
|
|
FONT_SIZES.map((size, index) =>
|
|
|
|
<option key={index} value={index}>
|
|
|
|
{size}
|
|
|
|
</option>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-12-23 16:26:22 +08:00
|
|
|
</div>
|
|
|
|
|
2017-02-16 02:49:40 +08:00
|
|
|
<div className={cx(styles.row, styles.spacedLeft)}>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={styles.formElement}>
|
|
|
|
<label className={styles.label}>
|
2017-04-11 04:27:29 +08:00
|
|
|
{intl.formatMessage(intlMessages.backgroundColorLabel)}
|
2017-02-16 02:49:40 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
2016-12-23 16:26:22 +08:00
|
|
|
</div>
|
2017-02-16 02:49:40 +08:00
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={cx(styles.formElement, styles.pullContentRight)}>
|
2016-12-23 16:26:22 +08:00
|
|
|
<div
|
2017-02-16 02:49:40 +08:00
|
|
|
tabIndex='12'
|
|
|
|
className={ styles.swatch }
|
|
|
|
onClick={ this.handleColorPickerClick.bind(this, 'displayBackgroundColorPicker') }>
|
|
|
|
<div
|
|
|
|
className={styles.swatchInner}
|
2017-02-22 04:29:36 +08:00
|
|
|
style={ { background: this.state.settings.backgroundColor } }>
|
2017-02-16 02:49:40 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
{ this.state.displayBackgroundColorPicker ?
|
|
|
|
<div className={styles.colorPickerPopover}>
|
|
|
|
<div
|
|
|
|
className={styles.colorPickerOverlay}
|
|
|
|
onClick={ this.handleCloseColorPicker.bind(this) }
|
|
|
|
>
|
|
|
|
</div>
|
2017-03-09 22:34:33 +08:00
|
|
|
<GithubPicker
|
2017-02-16 02:49:40 +08:00
|
|
|
onChange={this.handleColorChange.bind(this, 'backgroundColor')}
|
2017-02-25 04:19:53 +08:00
|
|
|
color={this.state.settings.backgroundColor}
|
2017-02-16 02:49:40 +08:00
|
|
|
colors={COLORS}
|
|
|
|
width={'140px'}
|
|
|
|
triangle={'top-right'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
: null }
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-12-23 16:26:22 +08:00
|
|
|
</div>
|
|
|
|
|
2017-02-16 02:49:40 +08:00
|
|
|
<div className={cx(styles.row, styles.spacedLeft)}>
|
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={styles.formElement}>
|
|
|
|
<label className={styles.label}>
|
2017-04-11 04:27:29 +08:00
|
|
|
{intl.formatMessage(intlMessages.fontColorLabel)}
|
2017-02-16 02:49:40 +08:00
|
|
|
</label>
|
|
|
|
</div>
|
2016-12-23 16:26:22 +08:00
|
|
|
</div>
|
2017-02-16 02:49:40 +08:00
|
|
|
<div className={styles.col}>
|
|
|
|
<div className={cx(styles.formElement, styles.pullContentRight)}>
|
2016-12-23 16:26:22 +08:00
|
|
|
<div
|
2017-02-16 02:49:40 +08:00
|
|
|
tabIndex='12'
|
|
|
|
className={ styles.swatch }
|
|
|
|
onClick={ this.handleColorPickerClick.bind(this, 'displayFontColorPicker') }>
|
|
|
|
<div
|
|
|
|
className={styles.swatchInner}
|
2017-02-22 04:29:36 +08:00
|
|
|
style={ { background: this.state.settings.fontColor } }>
|
2017-02-16 02:49:40 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
{ this.state.displayFontColorPicker ?
|
|
|
|
<div className={styles.colorPickerPopover}>
|
|
|
|
<div
|
|
|
|
className={styles.colorPickerOverlay}
|
|
|
|
onClick={ this.handleCloseColorPicker.bind(this) }
|
|
|
|
>
|
|
|
|
</div>
|
2017-03-09 22:34:33 +08:00
|
|
|
<GithubPicker
|
2017-02-16 02:49:40 +08:00
|
|
|
onChange={this.handleColorChange.bind(this, 'fontColor')}
|
2017-02-25 04:19:53 +08:00
|
|
|
color={this.state.settings.fontColor}
|
2017-02-16 02:49:40 +08:00
|
|
|
colors={COLORS}
|
|
|
|
width={'140px'}
|
|
|
|
triangle={'top-right'}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
: null }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div
|
|
|
|
className={cx(styles.ccPreviewBox, styles.spacedLeft)}
|
|
|
|
role='presentation'
|
2017-02-25 04:19:53 +08:00
|
|
|
style={ { background: this.state.settings.backgroundColor } }>
|
2017-02-16 02:49:40 +08:00
|
|
|
<span style={this.getPreviewStyle()}>
|
|
|
|
Etiam porta sem malesuada magna mollis euis-mod.
|
|
|
|
Donec ullamcorper nulla non metus auctor fringilla.
|
|
|
|
</span>
|
2016-12-23 16:26:22 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2017-04-11 04:27:29 +08:00
|
|
|
|
|
|
|
export default injectIntl(ClosedCaptionsMenu);
|