Skip to content

Commit aa9015b

Browse files
author
Eddie
committed
ready to go
1 parent e0ef4f2 commit aa9015b

File tree

3 files changed

+68
-22
lines changed

3 files changed

+68
-22
lines changed

src/app/modules/spell-check/spell-check.component.html

+17-12
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@
1010
<div class="b-back-drop">
1111
<div class="b-text-correction"
1212
>
13-
<span *ngFor="let keyword of corrections">
14-
<mark *ngIf="needToCorrect(keyword)" [innerHTML]="keyword" (click)="showReplacements(keyword)"></mark>
15-
<span *ngIf="!needToCorrect(keyword)" [innerHTML]="keyword"></span>
13+
<span class="s-word-container" *ngFor="let keyword of corrections">
14+
<mark *ngIf="needToCorrect(keyword) >= 0"
15+
[innerHTML]="keyword"
16+
(blur)="hideReplacements()"
17+
(click)="showReplacements($event, keyword)">
18+
</mark>
19+
<span class="correct-word" *ngIf="needToCorrect(keyword) < 0" [innerHTML]="keyword"></span>
20+
<div *ngIf="showPopover && selectedWrongWord == keyword" class="b-correct-word-list">
21+
<ul>
22+
<li
23+
*ngFor="let correctWord of correctWordList"
24+
[innerHTML]="correctWord.value"
25+
(click)="replaceWord(correctWord.value)">
26+
</li>
27+
</ul>
28+
</div>
1629
</span>
17-
<div *ngIf="showPopover" class="b-correct-word-list">
18-
<ul>
19-
<li
20-
*ngFor="let correctWord of correctWordList"
21-
[innerHTML]="correctWord.value"
22-
(click)="replaceWord(correctWord.value)">
23-
</li>
24-
</ul>
25-
</div>
30+
2631
</div>
2732
</div>
2833
</div>

src/app/modules/spell-check/spell-check.component.scss

+32-6
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,44 @@
1414
top: 0;
1515
z-index: 1;
1616
border: 1px solid transparent;
17-
overflow: auto;
17+
overflow: visible;
1818
transition: -webkit-transform 1s;
1919
transition: transform 1s;
2020
transition: transform 1s, -webkit-transform 1s;
2121
}
2222
.b-text-correction{
2323
padding: 2px;
24-
mark{
25-
cursor: pointer;
24+
.s-word-container{
25+
position: relative;
26+
mark{
27+
cursor: pointer;
28+
}
29+
span.correct-word{
30+
color: transparent;
31+
}
32+
.b-correct-word-list{
33+
position: absolute;
34+
top: 20px;
35+
left: 0;
36+
cursor: pointer;
37+
background: #FFFFFF;
38+
border: solid 1px #cccccc;
39+
font-size: 0.8rem;
40+
min-width: 100px;
41+
ul{
42+
margin: 0;
43+
padding: 0;
44+
list-style: none;
45+
li{
46+
padding: 5px 2px;
47+
&:hover{
48+
background: #EEEEEE;
49+
}
50+
}
51+
}
52+
}
2653
}
54+
2755
}
28-
.b-correct-word-list{
29-
top: 10px;
30-
}
56+
3157
}

src/app/modules/spell-check/spell-check.component.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, HostListener } from '@angular/core';
22
import { FormControl } from '@angular/forms';
33
import { Observable } from 'rxjs/Observable';
44
import { SpellCheckService } from './spell-check.service';
@@ -11,7 +11,13 @@ import 'rxjs/add/observable/fromEvent';
1111
templateUrl: './spell-check.component.html',
1212
styleUrls: ['./spell-check.component.scss']
1313
})
14+
1415
export class SpellCheckComponent implements OnInit {
16+
@HostListener('document:click', ['$event']) clickedOutside($event){
17+
// here you can hide your menu
18+
this.showPopover = false;
19+
}
20+
1521
public textData = ""
1622
showPopover = false
1723
selectedWrongWord
@@ -75,20 +81,29 @@ export class SpellCheckComponent implements OnInit {
7581
this.subscribers.push(spellCheckSub);
7682
}
7783

78-
showReplacements(word){
84+
showReplacements($event, word){
7985
this.showPopover = true;
8086
this.selectedWrongWord = word;
8187
this.correctWordList = this.wordsToBeCorrected[word];
88+
$event.preventDefault();
89+
$event.stopPropagation();
90+
}
91+
hideReplacements(){
92+
console.log('hide');
93+
this.showPopover = false;
8294
}
83-
8495
needToCorrect(word){
96+
// console.log(word);
97+
// Object.keys(this.wordsToBeCorrected).indexOf(word)
8598
return Object.keys(this.wordsToBeCorrected).indexOf(word);
8699
}
87100

88101
replaceWord(word){
102+
console.log(this.textData);
89103
this.textData = this.textData.replace(this.selectedWrongWord, word);
90104
const indexOfWord = this.corrections.indexOf(this.selectedWrongWord);
91-
this.corrections.splice(indexOfWord, 1);
105+
this.corrections = [];
106+
// this.corrections.splice(indexOfWord, 1);
92107
this.checkText(this.textData);
93108
}
94109

0 commit comments

Comments
 (0)