Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
retypos-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eterfund
retypos-server
Commits
c22a217f
You need to sign in or sign up before continuing.
Commit
c22a217f
authored
May 23, 2018
by
Георгий Попов
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Задача 12794] Добавил выделение в тексте опечатки
parent
c7de9f7a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
3 deletions
+51
-3
index.jsx
cp/javascript/src/components/Typo/index.jsx
+45
-3
style.css
cp/javascript/src/components/Typo/style.css
+6
-0
No files found.
cp/javascript/src/components/Typo/index.jsx
View file @
c22a217f
...
@@ -11,9 +11,12 @@ export default class Typo extends Component {
...
@@ -11,9 +11,12 @@ export default class Typo extends Component {
this
.
toggleDeclineTooltip
=
this
.
toggleDeclineTooltip
.
bind
(
this
);
this
.
toggleDeclineTooltip
=
this
.
toggleDeclineTooltip
.
bind
(
this
);
this
.
toggleAcceptTooltip
=
this
.
toggleAcceptTooltip
.
bind
(
this
);
this
.
toggleAcceptTooltip
=
this
.
toggleAcceptTooltip
.
bind
(
this
);
this
.
typo
=
props
.
typo
;
this
.
state
=
{
this
.
state
=
{
acceptTooltipOpen
:
false
,
acceptTooltipOpen
:
false
,
declineTooltipOpen
:
false
declineTooltipOpen
:
false
,
textHighlighted
:
false
,
};
};
}
}
...
@@ -39,8 +42,41 @@ export default class Typo extends Component {
...
@@ -39,8 +42,41 @@ export default class Typo extends Component {
})
})
}
}
_escapeHtml
(
text
)
{
const
map
=
{
'&'
:
'&'
,
'<'
:
'<'
,
'>'
:
'>'
,
'"'
:
'"'
,
"'"
:
'''
};
return
text
.
replace
(
/
[
&<>"'
]
/g
,
function
(
m
)
{
return
map
[
m
];
});
}
/**
* Выделяет опечатку в контексте
*/
_highlightTypoInContext
()
{
const
original
=
this
.
_escapeHtml
(
this
.
typo
.
originalText
);
const
corrected
=
this
.
_escapeHtml
(
this
.
typo
.
correctedText
);
const
context
=
this
.
_escapeHtml
(
this
.
typo
.
context
);
// Экранируем символы, которые мешают использовать регулярные выражения
const
escapedTypoString
=
original
.
replace
(
/
[
.*+?^${}()|[
\]\\]
/g
,
"
\\
$&"
);
let
regex
=
new
RegExp
(
escapedTypoString
,
"g"
);
this
.
typo
.
context
=
context
.
replace
(
regex
,
`<span class="typo-correction">
<del>
${
original
}
</del> ->
<span class="text-danger">
${
corrected
}
</span>
</span>`
);
}
render
()
{
render
()
{
const
{
typo
,
acceptCallback
,
declineCallback
,
show
}
=
this
.
props
;
const
typo
=
this
.
typo
;
const
{
acceptCallback
,
declineCallback
,
show
}
=
this
.
props
;
const
display
=
show
?
"d-block"
:
"d-none"
;
const
display
=
show
?
"d-block"
:
"d-none"
;
const
textColor
=
"text-white"
;
const
textColor
=
"text-white"
;
...
@@ -54,6 +90,11 @@ export default class Typo extends Component {
...
@@ -54,6 +90,11 @@ export default class Typo extends Component {
console
.
log
(
"Render hidden typo #"
+
typo
.
id
);
console
.
log
(
"Render hidden typo #"
+
typo
.
id
);
}
}
if
(
!
this
.
state
.
textHighlighted
)
{
this
.
_highlightTypoInContext
();
this
.
state
.
textHighlighted
=
true
;
}
return
(
return
(
<
Card
className=
{
className
}
>
<
Card
className=
{
className
}
>
<
CardHeader
>
<
CardHeader
>
...
@@ -65,7 +106,8 @@ export default class Typo extends Component {
...
@@ -65,7 +106,8 @@ export default class Typo extends Component {
<
CardBody
>
<
CardBody
>
<
CardTitle
><
del
>
{
typo
.
originalText
}
</
del
>
-
>
{
typo
.
correctedText
}
</
CardTitle
>
<
CardTitle
><
del
>
{
typo
.
originalText
}
</
del
>
-
>
{
typo
.
correctedText
}
</
CardTitle
>
<
CardText
>
{
typo
.
context
}
</
CardText
>
<
CardText
dangerouslySetInnerHTML=
{
{
__html
:
this
.
typo
.
context
}
}
/>
<
div
className=
"card-buttons"
>
<
div
className=
"card-buttons"
>
<
div
className=
"buttons-wrapper"
>
<
div
className=
"buttons-wrapper"
>
...
...
cp/javascript/src/components/Typo/style.css
View file @
c22a217f
...
@@ -29,4 +29,9 @@
...
@@ -29,4 +29,9 @@
.TypoCard
.card-text
{
.TypoCard
.card-text
{
min-height
:
100px
;
min-height
:
100px
;
}
.typo-correction
{
cursor
:
pointer
;
text-decoration
:
underline
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment