| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 @license | 2 @license |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 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 | 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 | 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 | 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 | 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 | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> | 9 --> |
| 10 <link rel="import" href="../polymer/polymer.html"> | 10 <link rel="import" href="../polymer/polymer.html"> |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 * Bind this to the `<input is="iron-input">`'s `name` property. | 194 * Bind this to the `<input is="iron-input">`'s `name` property. |
| 195 */ | 195 */ |
| 196 name: { | 196 name: { |
| 197 type: String | 197 type: String |
| 198 }, | 198 }, |
| 199 | 199 |
| 200 /** | 200 /** |
| 201 * A placeholder string in addition to the label. If this is set, the labe
l will always float. | 201 * A placeholder string in addition to the label. If this is set, the labe
l will always float. |
| 202 */ | 202 */ |
| 203 placeholder: { | 203 placeholder: { |
| 204 type: String | 204 type: String, |
| 205 // need to set a default so _computeAlwaysFloatLabel is run |
| 206 value: '' |
| 205 }, | 207 }, |
| 206 | 208 |
| 207 /** | 209 /** |
| 208 * Bind this to the `<input is="iron-input">`'s `readonly` property. | 210 * Bind this to the `<input is="iron-input">`'s `readonly` property. |
| 209 */ | 211 */ |
| 210 readonly: { | 212 readonly: { |
| 211 type: Boolean, | 213 type: Boolean, |
| 212 value: false | 214 value: false |
| 213 }, | 215 }, |
| 214 | 216 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } else { | 259 } else { |
| 258 var id = 'paper-input-add-on-' + Math.floor((Math.random() * 100000)); | 260 var id = 'paper-input-add-on-' + Math.floor((Math.random() * 100000)); |
| 259 target.id = id; | 261 target.id = id; |
| 260 this._ariaDescribedBy = this._appendStringWithSpace(this._ariaDescribedB
y, id); | 262 this._ariaDescribedBy = this._appendStringWithSpace(this._ariaDescribedB
y, id); |
| 261 } | 263 } |
| 262 }, | 264 }, |
| 263 | 265 |
| 264 /** | 266 /** |
| 265 * Validates the input element and sets an error style if needed. | 267 * Validates the input element and sets an error style if needed. |
| 266 */ | 268 */ |
| 267 validate: function () { | 269 validate: function() { |
| 268 return this.inputElement.validate(); | 270 return this.inputElement.validate(); |
| 269 }, | 271 }, |
| 270 | 272 |
| 273 /** |
| 274 * Restores the cursor to its original position after updating the value. |
| 275 * @param {string} newValue The value that should be saved. |
| 276 */ |
| 277 updateValueAndPreserveCaret: function(newValue) { |
| 278 // Not all elements might have selection, and even if they have the |
| 279 // right properties, accessing them might throw an exception (like for |
| 280 // <input type=number>) |
| 281 try { |
| 282 var start = this.inputElement.selectionStart; |
| 283 this.value = newValue; |
| 284 |
| 285 // The cursor automatically jumps to the end after re-setting the value, |
| 286 // so restore it to its original position. |
| 287 this.inputElement.selectionStart = start; |
| 288 this.inputElement.selectionEnd = start; |
| 289 } catch (e) { |
| 290 // Just set the value and give up on the caret. |
| 291 this.value = newValue; |
| 292 } |
| 293 }, |
| 294 |
| 271 _computeAlwaysFloatLabel: function(alwaysFloatLabel, placeholder) { | 295 _computeAlwaysFloatLabel: function(alwaysFloatLabel, placeholder) { |
| 272 return placeholder || alwaysFloatLabel; | 296 return placeholder || alwaysFloatLabel; |
| 273 }, | 297 }, |
| 274 | 298 |
| 275 _updateAriaLabelledBy: function() { | 299 _updateAriaLabelledBy: function() { |
| 276 var label = Polymer.dom(this.root).querySelector('label'); | 300 var label = Polymer.dom(this.root).querySelector('label'); |
| 277 if (!label) { | 301 if (!label) { |
| 278 this._ariaLabelledBy = ''; | 302 this._ariaLabelledBy = ''; |
| 279 return; | 303 return; |
| 280 } | 304 } |
| 281 var labelledBy; | 305 var labelledBy; |
| 282 if (label.id) { | 306 if (label.id) { |
| 283 labelledBy = label.id; | 307 labelledBy = label.id; |
| 284 } else { | 308 } else { |
| 285 labelledBy = 'paper-input-label-' + new Date().getUTCMilliseconds(); | 309 labelledBy = 'paper-input-label-' + new Date().getUTCMilliseconds(); |
| 286 label.id = labelledBy; | 310 label.id = labelledBy; |
| 287 } | 311 } |
| 288 this._ariaLabelledBy = labelledBy; | 312 this._ariaLabelledBy = labelledBy; |
| 289 } | 313 } |
| 290 | 314 |
| 291 }; | 315 }; |
| 292 | 316 |
| 293 </script> | 317 </script> |
| OLD | NEW |