| OLD | NEW |
| (Empty) |
| 1 | |
| 2 | |
| 3 Polymer('paper-autogrow-textarea',{ | |
| 4 | |
| 5 publish: { | |
| 6 | |
| 7 /** | |
| 8 * The textarea that should auto grow. | |
| 9 * | |
| 10 * @attribute target | |
| 11 * @type HTMLTextAreaElement | |
| 12 * @default null | |
| 13 */ | |
| 14 target: null, | |
| 15 | |
| 16 /** | |
| 17 * The initial number of rows. | |
| 18 * | |
| 19 * @attribute rows | |
| 20 * @type number | |
| 21 * @default 1 | |
| 22 */ | |
| 23 rows: 1, | |
| 24 | |
| 25 /** | |
| 26 * The maximum number of rows this element can grow to until it | |
| 27 * scrolls. 0 means no maximum. | |
| 28 * | |
| 29 * @attribute maxRows | |
| 30 * @type number | |
| 31 * @default 0 | |
| 32 */ | |
| 33 maxRows: 0 | |
| 34 }, | |
| 35 | |
| 36 tokens: null, | |
| 37 | |
| 38 observe: { | |
| 39 rows: 'updateCached', | |
| 40 maxRows: 'updateCached' | |
| 41 }, | |
| 42 | |
| 43 constrain: function(tokens) { | |
| 44 var _tokens; | |
| 45 tokens = tokens || ['']; | |
| 46 // Enforce the min and max heights for a multiline input to avoid measurem
ent | |
| 47 if (this.maxRows > 0 && tokens.length > this.maxRows) { | |
| 48 _tokens = tokens.slice(0, this.maxRows); | |
| 49 } else { | |
| 50 _tokens = tokens.slice(0); | |
| 51 } | |
| 52 while (this.rows > 0 && _tokens.length < this.rows) { | |
| 53 _tokens.push(''); | |
| 54 } | |
| 55 return _tokens.join('<br>') + ' '; | |
| 56 }, | |
| 57 | |
| 58 valueForMirror: function(input) { | |
| 59 this.tokens = (input && input.value) ? input.value.replace(/&/gm, '&')
.replace(/"/gm, '"').replace(/'/gm, ''').replace(/</gm, '<').replace
(/>/gm, '>').split('\n') : ['']; | |
| 60 return this.constrain(this.tokens); | |
| 61 }, | |
| 62 | |
| 63 /** | |
| 64 * Sizes this element to fit the input value. This function is automatically
called | |
| 65 * when the user types in new input, but you must call this function if the
value | |
| 66 * is updated imperatively. | |
| 67 * | |
| 68 * @method update | |
| 69 * @param Element The input | |
| 70 */ | |
| 71 update: function(input) { | |
| 72 this.$.mirror.innerHTML = this.valueForMirror(input); | |
| 73 }, | |
| 74 | |
| 75 updateCached: function() { | |
| 76 this.$.mirror.innerHTML = this.constrain(this.tokens); | |
| 77 }, | |
| 78 | |
| 79 inputAction: function(e) { | |
| 80 this.update(e.target); | |
| 81 } | |
| 82 | |
| 83 }); | |
| 84 | |
| OLD | NEW |