| OLD | NEW |
| 1 | 1 |
| 2 | 2 |
| 3 (function() { | 3 (function() { |
| 4 | 4 |
| 5 Polymer({ | 5 Polymer({ |
| 6 | 6 |
| 7 is: 'paper-input-char-counter', | 7 is: 'paper-input-char-counter', |
| 8 | 8 |
| 9 enableCustomStyleProperties: true, | 9 behaviors: [ |
| 10 | 10 Polymer.PaperInputAddonBehavior |
| 11 hostAttributes: { | 11 ], |
| 12 'add-on': '' | |
| 13 }, | |
| 14 | 12 |
| 15 properties: { | 13 properties: { |
| 16 | 14 |
| 17 /** | 15 _charCounterStr: { |
| 18 * The associated input element. | 16 type: String, |
| 19 */ | 17 value: '0' |
| 20 inputElement: { | |
| 21 type: Object | |
| 22 }, | |
| 23 | |
| 24 /** | |
| 25 * The current value of the input element. | |
| 26 */ | |
| 27 value: { | |
| 28 type: String | |
| 29 }, | |
| 30 | |
| 31 /** | |
| 32 * The character counter string. | |
| 33 */ | |
| 34 charCounter: { | |
| 35 computed: '_computeCharCounter(inputElement,value)', | |
| 36 type: String | |
| 37 } | 18 } |
| 38 | 19 |
| 39 }, | 20 }, |
| 40 | 21 |
| 41 attached: function() { | 22 update: function(state) { |
| 42 this.fire('addon-attached'); | 23 if (!state.inputElement) { |
| 43 }, | 24 return; |
| 25 } |
| 44 | 26 |
| 45 _computeCharCounter: function(inputElement,value) { | 27 state.value = state.value || ''; |
| 46 var str = value.length; | 28 |
| 47 if (inputElement.hasAttribute('maxlength')) { | 29 // Account for the textarea's new lines. |
| 48 str += '/' + inputElement.maxLength; | 30 var str = state.value.replace(/(\r\n|\n|\r)/g, '--').length; |
| 31 |
| 32 if (state.inputElement.hasAttribute('maxlength')) { |
| 33 str += '/' + state.inputElement.getAttribute('maxlength'); |
| 49 } | 34 } |
| 50 return str; | 35 this._charCounterStr = str; |
| 51 } | 36 } |
| 52 | 37 |
| 53 }); | 38 }); |
| 54 | 39 |
| 55 })(); | 40 })(); |
| 56 | 41 |
| OLD | NEW |