File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ ( function ( ) {
2
+ 'use strict' ;
3
+
4
+ angular . module ( 'app.filters' ) . filter ( 'truncateCharacters' , function ( ) {
5
+ return function ( input , chars , breakOnWord ) {
6
+ if ( isNaN ( chars ) ) {
7
+ return input ;
8
+ }
9
+ if ( chars <= 0 ) {
10
+ return '' ;
11
+ }
12
+ if ( input && input . length > chars ) {
13
+ input = input . substring ( 0 , chars ) ;
14
+
15
+ if ( ! breakOnWord ) {
16
+ var lastspace = input . lastIndexOf ( ' ' ) ;
17
+ // Get last space
18
+ if ( lastspace !== - 1 ) {
19
+ input = input . substr ( 0 , lastspace ) ;
20
+ }
21
+ } else {
22
+ while ( input . charAt ( input . length - 1 ) === ' ' ) {
23
+ input = input . substr ( 0 , input . length - 1 ) ;
24
+ }
25
+ }
26
+ return input + '...' ;
27
+ }
28
+ return input ;
29
+ } ;
30
+ } ) ;
31
+ } ) ( ) ;
Original file line number Diff line number Diff line change
1
+ ( function ( ) {
2
+ 'use strict' ;
3
+
4
+ angular . module ( 'app.filters' ) . filter ( 'truncateWords' , function ( ) {
5
+ return function ( input , words ) {
6
+ if ( isNaN ( words ) ) {
7
+ return input ;
8
+ }
9
+ if ( words <= 0 ) {
10
+ return '' ;
11
+ }
12
+ if ( input ) {
13
+ var inputWords = input . split ( / \s + / ) ;
14
+ if ( inputWords . length > words ) {
15
+ input = inputWords . slice ( 0 , words ) . join ( ' ' ) + '...' ;
16
+ }
17
+ }
18
+ return input ;
19
+ } ;
20
+ } ) ;
21
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments