Skip to content

Commit

Permalink
add hasLiterial prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Rouhollah committed May 17, 2021
1 parent a9d6c13 commit faca2c1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## ngx-truncate-text
This module is for shortening the text and also includes some useful features for text manipulation.
#### see [demo on stackblitz.](https://stackblitz.com/edit/ngx-truncate-text?file=src/app/app.component.html)
#### see [demo on stackblitz.](https://stackblitz.com/edit/ngx-truncate-text?file=src/app/app.component.html) in developing ...
### install:
```
npm i ngx-truncate-text
Expand Down Expand Up @@ -34,9 +34,12 @@ and then use it in html (simplest use) :
|number|Number of characters to display|number|1.0.0
|completeWord|It prevents word break when shortening text on a part of the word.|boolean|1.1.0+
|hashtag|finds hashtag in text (any language, zero-width non-joiner is considered.)|boolean|2.0.0+
hasLiteral|If you want to see the text as it is (including "\ r", "\ n", "\ t"), use this feature |boolean|2.1.0+

<br>
<span style="color:yellow"> Note:</span> default color for toggle button is <span style="color:#ff00ff">#ff00ff</span> and cursor style is pointer , if you want to use custom style, use the builtin `.toggleText` class.
<span style="color:yellow"> Note:</span>

- default color for toggle button is <span style="color:#ff00ff">#ff00ff</span> and cursor style is pointer , if you want to use custom style, use the builtin `.toggleText` class.

```
.toggleText{
Expand All @@ -45,6 +48,4 @@ and then use it in html (simplest use) :
font-style: italic;
}
```
#### latest version is 2.0.0

#### in developing ...
- default color for hashtags is <span style="color:#1b95e0">#1b95e0</span> (from twitter), if you want to use custom style, use the builtin .hashtag class..
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-truncate-text",
"version": "2.0.0",
"version": "2.1.0",
"author": {
"name":"Rouhollah Torshizi",
"email":"[email protected]"
Expand Down
22 changes: 16 additions & 6 deletions src/lib/ngx-truncate-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class NgxTruncateTextDirective implements AfterViewInit {
@Input() number: number;
@Input() completeWord: boolean;
@Input() hashtag: boolean;
@Input() hasLiteral: boolean;
target: string;
replace = false;
text: string;
Expand All @@ -31,6 +32,7 @@ export class NgxTruncateTextDirective implements AfterViewInit {


fill(text) {
if (!this.hasLiteral) text = text.replace(/(\r\n\t|\n|\r\t)/gm, ' ');
this.text = text;
let toggling = false;
let remainText: string = "";
Expand All @@ -49,9 +51,11 @@ export class NgxTruncateTextDirective implements AfterViewInit {
this.renderer.listen(span, 'click', (event) => this.replace === true ? this.showFullText(event) : this.hideSomeText(event));
this.element.appendChild(span);
} else {
this.element.innerHTML = this.hashtag ? this.trunService.findHashtag(text) : text;
this.element.innerHTML = this.hashtag ? this.trunService.findHashtag(text) : text;
}

//اعمال شود این کلاس قرار داده می شود html در \n برای اینکه کاراکتر های
if (this.hasLiteral)
this.element.style.whiteSpace = 'pre-line';
}

/*
Expand All @@ -60,14 +64,17 @@ export class NgxTruncateTextDirective implements AfterViewInit {
*/
showFullText(mouseDown: MouseEvent) {
const span = this.renderer.createElement('span');
span.innerHTML = " "+this.less;
span.innerHTML = " " + this.less;
this.renderer.setStyle(span, 'color', '#ff00ff');
this.renderer.setStyle(span, 'cursor', 'pointer');

this.renderer.addClass(span, 'toggleText');

this.element.innerHTML = this.hashtag ? this.trunService.findHashtag(this.text) : this.text ;

this.element.innerHTML = this.hashtag ? this.trunService.findHashtag(this.text) : this.text;
//اعمال شود این کلاس قرار داده می شود html در \n برای اینکه کاراکتر های
if (this.hasLiteral)
this.element.style.whiteSpace = 'pre-line';

this.renderer.listen(span, 'click', (event) => this.hideSomeText(event));
this.element.appendChild(span);
// جلوگیری از کلیک روی عنصر پدر
Expand All @@ -88,7 +95,10 @@ export class NgxTruncateTextDirective implements AfterViewInit {
this.renderer.addClass(span, 'toggleText');
span.innerHTML = this.more;
this.element.innerHTML = remainText + ' ... ';

//اعمال شود این کلاس قرار داده میشود html در n \برای اینکه کاراکتر های
if (this.hasLiteral)
this.element.style.whiteSpace = 'pre-line';

this.renderer.listen(span, 'click', (event) => this.showFullText(event));
this.element.appendChild(span);
// جلوگیری از کلیک روی عنصر پدر
Expand Down

0 comments on commit faca2c1

Please sign in to comment.