Skip to content

Commit

Permalink
Merge 80ad17e into 233f43e
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-feng committed Feb 7, 2017
2 parents 233f43e + 80ad17e commit 6537b60
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions webapp/components/user_settings/custom_theme_chooser.jsx
Expand Up @@ -156,17 +156,35 @@ class CustomThemeChooser extends React.Component {
this.props.updateTheme(theme);
}

getColors(text) {
const colorsText = text.split(', ');
return colorsText.map((colorText) => {
const keyValue = colorText.split(': ');
const color = keyValue[1] || colorText;
if (Utils.isHexColor(color)) {
return color;
} else if (keyValue[0] === 'Code Theme') {
return keyValue[1];
}
return '#FFF';
});
}

pasteBoxChange(e) {
const text = e.target.value;
let text = '';

if (window.clipboardData && window.clipboardData.getData) { // IE
text = window.clipboardData.getData('Text');
} else {
text = e.clipboardData.getData('Text');//e.clipboardData.getData('text/plain');
}

if (text.length === 0) {
return;
}

// theme vectors are currently represented as a number of hex color codes followed by the code theme

const colors = text.split(',');

const colors = this.getColors(text);
const theme = {type: 'custom'};
let index = 0;
Constants.THEME_ELEMENTS.forEach((element) => {
Expand All @@ -182,6 +200,10 @@ class CustomThemeChooser extends React.Component {
this.props.updateTheme(theme);
}

onChangeHandle(e) {
e.stopPropagation();
}

toggleContent(e) {
e.stopPropagation();
if ($(e.target).hasClass('theme-elements__header')) {
Expand Down Expand Up @@ -291,7 +313,7 @@ class CustomThemeChooser extends React.Component {
</div>
);

colors += theme[element.id] + ',';
colors += formatMessage(messages[element.id]) + ': ' + theme[element.id] + ', ';
} else if (element.group === 'sidebarElements') {
sidebarElements.push(
<div
Expand All @@ -313,7 +335,7 @@ class CustomThemeChooser extends React.Component {
</div>
);

colors += theme[element.id] + ',';
colors += formatMessage(messages[element.id]) + ': ' + theme[element.id] + ', ';
} else {
linkAndButtonElements.push(
<div
Expand All @@ -335,11 +357,11 @@ class CustomThemeChooser extends React.Component {
</div>
);

colors += theme[element.id] + ',';
colors += formatMessage(messages[element.id]) + ': ' + theme[element.id] + ', ';
}
});

colors += theme.codeTheme;
colors += 'Code Theme: ' + theme.codeTheme;

const pasteBox = (
<div className='col-sm-12'>
Expand All @@ -349,11 +371,11 @@ class CustomThemeChooser extends React.Component {
defaultMessage='Copy and paste to share theme colors:'
/>
</label>
<input
type='text'
<textarea
className='form-control'
value={colors}
onChange={this.pasteBoxChange}
onPaste={this.pasteBoxChange}
onChange={this.onChangeHandle}
/>
</div>
);
Expand Down

0 comments on commit 6537b60

Please sign in to comment.