|
106 | 106 | }
|
107 | 107 | }
|
108 | 108 | else { // character type
|
| 109 | + var maxLimit = (base.options.twoCharCarriageReturn) ? |
| 110 | + base.options.max - base.twoCharCarriageReturnCount($text) |
| 111 | + : base.options.max; |
| 112 | + |
109 | 113 | if (base.options.countSpaces) { // if spaces should be counted
|
110 |
| - trimmedString = $text.substring(0, base.options.max); |
| 114 | + trimmedString = $text.substring(0, maxLimit); |
111 | 115 | }
|
112 | 116 | else {
|
113 | 117 | var charArray = $text.split(''),
|
114 | 118 | totalCharacters = charArray.length,
|
115 | 119 | charCount = 0,
|
116 | 120 | i = 0;
|
117 | 121 |
|
118 |
| - while (charCount < base.options.max && i < totalCharacters) { |
| 122 | + while (charCount < maxLimit && i < totalCharacters) { |
119 | 123 | if (charArray[i] !== ' ') charCount++;
|
120 | 124 | trimmedString += charArray[i++];
|
121 | 125 | }
|
|
162 | 166 |
|
163 | 167 | // count carriage returns/newlines as 2 characters
|
164 | 168 | if (base.options.twoCharCarriageReturn) {
|
165 |
| - var carriageReturns = text.match(/(\r\n|\n|\r)/g); |
166 |
| - |
167 |
| - if (carriageReturns !== null) { |
168 |
| - carriageReturnsCount = carriageReturns.length; |
169 |
| - } |
| 169 | + carriageReturnsCount = base.twoCharCarriageReturnCount(text); |
170 | 170 | }
|
171 | 171 |
|
172 | 172 | if (base.options.countSpaces) { // if need to count spaces
|
|
194 | 194 | return textCount;
|
195 | 195 | };
|
196 | 196 |
|
| 197 | + base.twoCharCarriageReturnCount = function(text) { |
| 198 | + var carriageReturns = text.match(/(\r\n|\n|\r)/g), |
| 199 | + carriageReturnsCount = 0; |
| 200 | + |
| 201 | + if (carriageReturns !== null) { |
| 202 | + carriageReturnsCount = carriageReturns.length; |
| 203 | + } |
| 204 | + |
| 205 | + return carriageReturnsCount; |
| 206 | + }; |
| 207 | + |
197 | 208 | base.setCount = function(count) {
|
198 | 209 | base.$text_counter.text(count);
|
199 | 210 | };
|
|
0 commit comments