OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 @license |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 7 Code distributed by Google as part of the polymer project is also |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> |
| 10 |
| 11 <link rel="import" href="../polymer/polymer.html"> |
| 12 <link rel="import" href="../paper-styles/paper-styles.html"> |
| 13 |
| 14 <!-- |
| 15 `<paper-input-char-counter>` is a character counter for use with `<paper-input-c
ontainer>`. |
| 16 --> |
| 17 <dom-module id="paper-input-char-counter"> |
| 18 |
| 19 <style> |
| 20 |
| 21 :host { |
| 22 display: inline-block; |
| 23 float: right; |
| 24 |
| 25 mixin(--paper-input-container-add-on); |
| 26 mixin(--paper-input-container-add-on-font); |
| 27 |
| 28 mixin(--paper-input-char-counter); |
| 29 } |
| 30 |
| 31 </style> |
| 32 |
| 33 <template> |
| 34 |
| 35 <span>[[charCounter]]</span> |
| 36 |
| 37 </template> |
| 38 |
| 39 </dom-module> |
| 40 |
| 41 <script> |
| 42 |
| 43 (function() { |
| 44 |
| 45 Polymer({ |
| 46 |
| 47 is: 'paper-input-char-counter', |
| 48 |
| 49 enableCustomStyleProperties: true, |
| 50 |
| 51 hostAttributes: { |
| 52 'add-on': '' |
| 53 }, |
| 54 |
| 55 properties: { |
| 56 |
| 57 /** |
| 58 * The associated input element. |
| 59 */ |
| 60 inputElement: { |
| 61 type: Object |
| 62 }, |
| 63 |
| 64 /** |
| 65 * The current value of the input element. |
| 66 */ |
| 67 value: { |
| 68 type: String |
| 69 }, |
| 70 |
| 71 /** |
| 72 * The character counter string. |
| 73 */ |
| 74 charCounter: { |
| 75 computed: '_computeCharCounter(inputElement,value)', |
| 76 type: String |
| 77 } |
| 78 |
| 79 }, |
| 80 |
| 81 attached: function() { |
| 82 this.fire('addon-attached'); |
| 83 }, |
| 84 |
| 85 _computeCharCounter: function(inputElement,value) { |
| 86 var str = value.length; |
| 87 if (inputElement.hasAttribute('maxlength')) { |
| 88 str += '/' + inputElement.maxLength; |
| 89 } |
| 90 return str; |
| 91 } |
| 92 |
| 93 }); |
| 94 |
| 95 })(); |
| 96 |
| 97 </script> |
OLD | NEW |