OLD | NEW |
1 Polymer({ | 1 Polymer({ |
2 is: 'paper-input-char-counter', | 2 is: 'paper-input-char-counter', |
3 | 3 |
4 behaviors: [ | 4 behaviors: [ |
5 Polymer.PaperInputAddonBehavior | 5 Polymer.PaperInputAddonBehavior |
6 ], | 6 ], |
7 | 7 |
8 properties: { | 8 properties: { |
9 _charCounterStr: { | 9 _charCounterStr: { |
10 type: String, | 10 type: String, |
(...skipping 12 matching lines...) Expand all Loading... |
23 * value: The input value. | 23 * value: The input value. |
24 * invalid: True if the input value is invalid. | 24 * invalid: True if the input value is invalid. |
25 */ | 25 */ |
26 update: function(state) { | 26 update: function(state) { |
27 if (!state.inputElement) { | 27 if (!state.inputElement) { |
28 return; | 28 return; |
29 } | 29 } |
30 | 30 |
31 state.value = state.value || ''; | 31 state.value = state.value || ''; |
32 | 32 |
33 // Account for the textarea's new lines. | 33 var counter = state.value.length.toString(); |
34 var str = state.value.replace(/(\r\n|\n|\r)/g, '--').length.toString(); | |
35 | 34 |
36 if (state.inputElement.hasAttribute('maxlength')) { | 35 if (state.inputElement.hasAttribute('maxlength')) { |
37 str += '/' + state.inputElement.getAttribute('maxlength'); | 36 counter += '/' + state.inputElement.getAttribute('maxlength'); |
38 } | 37 } |
39 this._charCounterStr = str; | 38 |
| 39 this._charCounterStr = counter; |
40 } | 40 } |
41 }); | 41 }); |
OLD | NEW |