Add typo highlighting checkbox to the app

parent 4621c89d
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
"scripts": { "scripts": {
"buildDev": "webpack -d --devtool=source-map", "buildDev": "webpack -d --devtool=source-map",
"build": "webpack --mode=production", "build": "webpack --mode=production",
"watch": "webpack -w",
"start": "webpack-dev-server -d --hot --inline --content-base example/" "start": "webpack-dev-server -d --hot --inline --content-base example/"
}, },
"devDependencies": { "devDependencies": {
......
...@@ -19,6 +19,7 @@ class App extends Component { ...@@ -19,6 +19,7 @@ class App extends Component {
this.state = { this.state = {
correctionMode: false, correctionMode: false,
isTimeout: false, isTimeout: false,
contentEditable: false
} }
this.selectionContext = ""; this.selectionContext = "";
...@@ -26,6 +27,44 @@ class App extends Component { ...@@ -26,6 +27,44 @@ class App extends Component {
this.registerHandlers(); this.registerHandlers();
} }
setContenteditable = (e) => {
if (e.target.checked) {
this.setState({
contentEditable: true
});
alertify.success(i18n.typoHighlightingEnabled);
} else {
this.setState({
contentEditable: false
});
alertify.success(i18n.typoHighlightingDisabled);
}
}
/**
* Enables browser typo highlighting on page
*/
enableTypoHighlighting = () => {
let body = $("body");
body.attr("contenteditable", true);
body.attr("oncut", "return false");
body.attr("onpaste", "return false");
body.attr("onkeydown", "if(event.metaKey) return true; return false;");
}
/**
* Disables browser typo highlighting on page
*/
disableTypoHighlighting = () => {
let body = $("body");
body.attr("contenteditable", false);
body.attr("oncut", "return true");
body.attr("onpaste", "return true");
body.attr("onkeydown", "return true");
}
// Returns selected text or null if no // Returns selected text or null if no
// text was selected // text was selected
getSelectedText() { getSelectedText() {
...@@ -61,6 +100,8 @@ class App extends Component { ...@@ -61,6 +100,8 @@ class App extends Component {
this.typo = selection; this.typo = selection;
this.disableTypoHighlighting();
// Ctrl-Enter pressed // Ctrl-Enter pressed
this.setState({ this.setState({
correctionMode: true correctionMode: true
...@@ -75,6 +116,8 @@ class App extends Component { ...@@ -75,6 +116,8 @@ class App extends Component {
return ( return (
<TypoModal text={this.typo} context={this.selectionContext} <TypoModal text={this.typo} context={this.selectionContext}
closeCallback={this.modalClosedCallback.bind(true)} closeCallback={this.modalClosedCallback.bind(true)}
contentEditableCallback={this.setContenteditable}
contentEditable={this.state.contentEditable}
show={this.state.correctionMode}/> show={this.state.correctionMode}/>
); );
} }
...@@ -85,17 +128,22 @@ class App extends Component { ...@@ -85,17 +128,22 @@ class App extends Component {
this.setState({ this.setState({
correctionMode: false correctionMode: false
}); });
return; } else {
this.setState({
correctionMode: false,
isTimeout: true,
});
this.requestTimer = window.setTimeout(() => {
this.setState({ isTimeout: false });
}, config.requestTimeout);
} }
this.setState({ if (this.state.contentEditable) {
correctionMode: false, this.enableTypoHighlighting();
isTimeout: true, }
});
this.requestTimer = window.setTimeout(() => {
this.setState({ isTimeout: false });
}, config.requestTimeout);
} }
componentWillUnmount() { componentWillUnmount() {
......
...@@ -19,6 +19,9 @@ export const i18n = new LocalizedStrings({ ...@@ -19,6 +19,9 @@ export const i18n = new LocalizedStrings({
messageSuccess: "Благодарим за отправку опечатки. Мы уже работаем над её исправлением!", messageSuccess: "Благодарим за отправку опечатки. Мы уже работаем над её исправлением!",
errorFormContainsErrors: "Форма отправки содержит ошибки!", errorFormContainsErrors: "Форма отправки содержит ошибки!",
errorSendFailture: "Не удалось отправить исправление. Мы уже работаем над решением проблемы!", errorSendFailture: "Не удалось отправить исправление. Мы уже работаем над решением проблемы!",
typoHighlightingEnable: "Включить подсветку ошибок",
typoHighlightingEnabled: "Подсветка опечаток на странице включена",
typoHighlightingDisabled: "Подсветка опечаток на странице выключена",
}, },
en: { en: {
modalTitle: "Typo correction system Etersoft", modalTitle: "Typo correction system Etersoft",
...@@ -38,5 +41,8 @@ export const i18n = new LocalizedStrings({ ...@@ -38,5 +41,8 @@ export const i18n = new LocalizedStrings({
messageSuccess: "Thank you for a typo submitting! We are already working on this report!", messageSuccess: "Thank you for a typo submitting! We are already working on this report!",
errorFormContainsErrors: "The form contains errors!", errorFormContainsErrors: "The form contains errors!",
errorSendFailture: "Failed to send request. We are fixing a problem!", errorSendFailture: "Failed to send request. We are fixing a problem!",
typoHighlightingEnable: "Typo highlighting on page",
typoHighlightingEnabled: "Typo highlighting enabled on this page",
typoHighlightingDisabled: "Typo highlighting disabled on this page",
} }
}) })
\ No newline at end of file
import React, { Component } from 'react'; import React, { Component } from 'react';
import {Modal, Button, FormGroup, FormControl, ControlLabel, HelpBlock, Alert } from 'react-bootstrap'; import {Modal, Checkbox, Button, FormGroup, FormControl, ControlLabel, HelpBlock, Alert } from 'react-bootstrap';
import $ from 'jquery'; import $ from 'jquery';
import './Modal.css'; import './Modal.css';
...@@ -22,6 +22,7 @@ class TypoModal extends Component { ...@@ -22,6 +22,7 @@ class TypoModal extends Component {
text: this.props.text, text: this.props.text,
correct: this.props.text, correct: this.props.text,
context: this.props.context, context: this.props.context,
contentEditable: this.props.contentEditable,
language: this.getLanguage(), language: this.getLanguage(),
comment: "", comment: "",
error: "" error: ""
...@@ -32,6 +33,7 @@ class TypoModal extends Component { ...@@ -32,6 +33,7 @@ class TypoModal extends Component {
i18n.setLanguage(this.state.language); i18n.setLanguage(this.state.language);
this.closeCallback = props.closeCallback; this.closeCallback = props.closeCallback;
this.contentEditableCallback = props.contentEditableCallback;
// Bindings // Bindings
this.submitTypo = this.submitTypo.bind(this); this.submitTypo = this.submitTypo.bind(this);
...@@ -166,6 +168,14 @@ class TypoModal extends Component { ...@@ -166,6 +168,14 @@ class TypoModal extends Component {
this.persistLanguage(language); this.persistLanguage(language);
} }
onContentEditableCheckboxChanged = (e) => {
this.setState({
contentEditable: e.target.checked
});
this.contentEditableCallback(e);
}
render() { render() {
if (!this.state.show) return null; if (!this.state.show) return null;
...@@ -204,6 +214,9 @@ class TypoModal extends Component { ...@@ -204,6 +214,9 @@ class TypoModal extends Component {
</Modal.Body> </Modal.Body>
<Modal.Footer> <Modal.Footer>
<Checkbox onChange={this.onContentEditableCheckboxChanged} checked={this.state.contentEditable}>
{i18n.typoHighlightingEnable}
</Checkbox>
<LangSwitcher activeLanguage={this.state.language} onLangChanged={this.onLangChanged} languages={this.languages}></LangSwitcher> <LangSwitcher activeLanguage={this.state.language} onLangChanged={this.onLangChanged} languages={this.languages}></LangSwitcher>
<Button onClick={this.handleClose}>{i18n.close}</Button> <Button onClick={this.handleClose}>{i18n.close}</Button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment