diff options
author | Chocobozzz <me@florianbigard.com> | 2020-05-29 16:16:24 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-10 14:02:41 +0200 |
commit | 5fb2e2888ce032c638e4b75d07458642f0833e52 (patch) | |
tree | 8830d873569316889b8134027e9a43b198cca38f /client/src/app/shared/angular | |
parent | 62e7be634bc189f942ae51cb4b080079ab503ff0 (diff) | |
download | PeerTube-5fb2e2888ce032c638e4b75d07458642f0833e52.tar.gz PeerTube-5fb2e2888ce032c638e4b75d07458642f0833e52.tar.zst PeerTube-5fb2e2888ce032c638e4b75d07458642f0833e52.zip |
First implem global search
Diffstat (limited to 'client/src/app/shared/angular')
-rw-r--r-- | client/src/app/shared/angular/highlight.pipe.ts | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/client/src/app/shared/angular/highlight.pipe.ts b/client/src/app/shared/angular/highlight.pipe.ts index fb6042280..50ee5c1bd 100644 --- a/client/src/app/shared/angular/highlight.pipe.ts +++ b/client/src/app/shared/angular/highlight.pipe.ts | |||
@@ -11,19 +11,17 @@ export class HighlightPipe implements PipeTransform { | |||
11 | /* use this for global search */ | 11 | /* use this for global search */ |
12 | static MULTI_MATCH = 'Multi-Match' | 12 | static MULTI_MATCH = 'Multi-Match' |
13 | 13 | ||
14 | // tslint:disable-next-line:no-empty | ||
15 | constructor () {} | ||
16 | |||
17 | transform ( | 14 | transform ( |
18 | contentString: string = null, | 15 | contentString: string = null, |
19 | stringToHighlight: string = null, | 16 | stringToHighlight: string = null, |
20 | option = 'Single-And-StartsWith-Match', | 17 | option = 'Single-And-StartsWith-Match', |
21 | caseSensitive = false, | 18 | caseSensitive = false, |
22 | highlightStyleName = 'search-highlight' | 19 | highlightStyleName = 'search-highlight' |
23 | ): SafeHtml { | 20 | ): SafeHtml { |
24 | if (stringToHighlight && contentString && option) { | 21 | if (stringToHighlight && contentString && option) { |
25 | let regex: any = '' | 22 | let regex: any = '' |
26 | const caseFlag: string = !caseSensitive ? 'i' : '' | 23 | const caseFlag: string = !caseSensitive ? 'i' : '' |
24 | |||
27 | switch (option) { | 25 | switch (option) { |
28 | case 'Single-Match': { | 26 | case 'Single-Match': { |
29 | regex = new RegExp(stringToHighlight, caseFlag) | 27 | regex = new RegExp(stringToHighlight, caseFlag) |
@@ -42,10 +40,12 @@ export class HighlightPipe implements PipeTransform { | |||
42 | regex = new RegExp(stringToHighlight, 'gi') | 40 | regex = new RegExp(stringToHighlight, 'gi') |
43 | } | 41 | } |
44 | } | 42 | } |
43 | |||
45 | const replaced = contentString.replace( | 44 | const replaced = contentString.replace( |
46 | regex, | 45 | regex, |
47 | (match) => `<span class="${highlightStyleName}">${match}</span>` | 46 | (match) => `<span class="${highlightStyleName}">${match}</span>` |
48 | ) | 47 | ) |
48 | |||
49 | return replaced | 49 | return replaced |
50 | } else { | 50 | } else { |
51 | return contentString | 51 | return contentString |