| OLD | NEW |
| (Empty) |
| 1 | |
| 2 | |
| 3 (function() { | |
| 4 | |
| 5 'use strict'; | |
| 6 | |
| 7 function classNames(obj) { | |
| 8 var classNames = []; | |
| 9 for (var key in obj) { | |
| 10 if (obj.hasOwnProperty(key) && obj[key]) { | |
| 11 classNames.push(key); | |
| 12 } | |
| 13 } | |
| 14 | |
| 15 return classNames.join(' '); | |
| 16 } | |
| 17 | |
| 18 Polymer({ | |
| 19 | |
| 20 is: 'paper-spinner', | |
| 21 | |
| 22 listeners: { | |
| 23 'animationend': 'reset', | |
| 24 'webkitAnimationEnd': 'reset' | |
| 25 }, | |
| 26 | |
| 27 properties: { | |
| 28 | |
| 29 /** | |
| 30 * Displays the spinner. | |
| 31 * | |
| 32 * @attribute active | |
| 33 * @type boolean | |
| 34 * @default false | |
| 35 */ | |
| 36 active: { | |
| 37 observer: '_activeChanged', | |
| 38 type: Boolean, | |
| 39 value: false | |
| 40 }, | |
| 41 | |
| 42 /** | |
| 43 * Alternative text content for accessibility support. | |
| 44 * If alt is present, it will add an aria-label whose content matches
alt when active. | |
| 45 * If alt is not present, it will default to 'loading' as the alt valu
e. | |
| 46 * | |
| 47 * @attribute alt | |
| 48 * @type string | |
| 49 * @default 'loading' | |
| 50 */ | |
| 51 alt: { | |
| 52 observer: '_altChanged', | |
| 53 type: String, | |
| 54 value: 'loading' | |
| 55 }, | |
| 56 | |
| 57 /** | |
| 58 * True when the spinner is going from active to inactive. This is rep
resented by a fade | |
| 59 * to 0% opacity to the user. | |
| 60 */ | |
| 61 _coolingDown: { | |
| 62 type: Boolean, | |
| 63 value: false | |
| 64 }, | |
| 65 | |
| 66 _spinnerContainerClassName: { | |
| 67 type: String, | |
| 68 computed: '_computeSpinnerContainerClassName(active, _coolingDown)' | |
| 69 } | |
| 70 | |
| 71 }, | |
| 72 | |
| 73 _computeSpinnerContainerClassName: function(active, _coolingDown) { | |
| 74 return classNames({ | |
| 75 active: active || _coolingDown, | |
| 76 cooldown: _coolingDown | |
| 77 }); | |
| 78 }, | |
| 79 | |
| 80 ready: function() { | |
| 81 // Allow user-provided `aria-label` take preference to any other text
alternative. | |
| 82 if (this.hasAttribute('aria-label')) { | |
| 83 this.alt = this.getAttribute('aria-label'); | |
| 84 } else { | |
| 85 this.setAttribute('aria-label', this.alt); | |
| 86 } | |
| 87 | |
| 88 if (!this.active) { | |
| 89 this.setAttribute('aria-hidden', 'true'); | |
| 90 } | |
| 91 }, | |
| 92 | |
| 93 _activeChanged: function() { | |
| 94 if (this.active) { | |
| 95 this.removeAttribute('aria-hidden'); | |
| 96 } else { | |
| 97 this._coolingDown = true; | |
| 98 this.setAttribute('aria-hidden', 'true'); | |
| 99 } | |
| 100 }, | |
| 101 | |
| 102 _altChanged: function() { | |
| 103 if (this.alt === '') { | |
| 104 this.setAttribute('aria-hidden', 'true'); | |
| 105 } else { | |
| 106 this.removeAttribute('aria-hidden'); | |
| 107 } | |
| 108 | |
| 109 this.setAttribute('aria-label', this.alt); | |
| 110 }, | |
| 111 | |
| 112 reset: function() { | |
| 113 this.active = false; | |
| 114 this._coolingDown = false; | |
| 115 } | |
| 116 | |
| 117 }); | |
| 118 | |
| 119 }()); | |
| 120 | |
| 121 | |
| OLD | NEW |