| OLD | NEW |
| 1 | 1 |
| 2 | 2 |
| 3 (function() { | 3 Polymer({ |
| 4 | 4 |
| 5 'use strict'; | 5 is: 'paper-spinner', |
| 6 | 6 |
| 7 function classNames(obj) { | 7 listeners: { |
| 8 var classNames = []; | 8 'animationend': 'reset', |
| 9 for (var key in obj) { | 9 'webkitAnimationEnd': 'reset' |
| 10 if (obj.hasOwnProperty(key) && obj[key]) { | 10 }, |
| 11 classNames.push(key); | 11 |
| 12 } | 12 properties: { |
| 13 |
| 14 /** |
| 15 * Displays the spinner. |
| 16 * |
| 17 * @attribute active |
| 18 * @type boolean |
| 19 * @default false |
| 20 */ |
| 21 active: { |
| 22 type: Boolean, |
| 23 value: false, |
| 24 reflectToAttribute: true, |
| 25 observer: '_activeChanged' |
| 26 }, |
| 27 |
| 28 /** |
| 29 * Alternative text content for accessibility support. |
| 30 * If alt is present, it will add an aria-label whose content matches al
t when active. |
| 31 * If alt is not present, it will default to 'loading' as the alt value. |
| 32 * |
| 33 * @attribute alt |
| 34 * @type string |
| 35 * @default 'loading' |
| 36 */ |
| 37 alt: { |
| 38 type: String, |
| 39 value: 'loading', |
| 40 observer: '_altChanged' |
| 41 }, |
| 42 |
| 43 /** |
| 44 * True when the spinner is going from active to inactive. This is repre
sented by a fade |
| 45 * to 0% opacity to the user. |
| 46 */ |
| 47 _coolingDown: { |
| 48 type: Boolean, |
| 49 value: false |
| 50 }, |
| 51 |
| 52 _spinnerContainerClassName: { |
| 53 type: String, |
| 54 computed: '_computeSpinnerContainerClassName(active, _coolingDown)' |
| 13 } | 55 } |
| 14 | 56 |
| 15 return classNames.join(' '); | 57 }, |
| 58 |
| 59 _computeSpinnerContainerClassName: function(active, coolingDown) { |
| 60 return [ |
| 61 active || coolingDown ? 'active' : '', |
| 62 coolingDown ? 'cooldown' : '' |
| 63 ].join(' '); |
| 64 }, |
| 65 |
| 66 _activeChanged: function(active, old) { |
| 67 this._setAriaHidden(!active); |
| 68 if (!active && old) { |
| 69 this._coolingDown = true; |
| 70 } |
| 71 }, |
| 72 |
| 73 _altChanged: function(alt) { |
| 74 // user-provided `aria-label` takes precedence over prototype default |
| 75 if (alt === this.getPropertyInfo('alt').value) { |
| 76 this.alt = this.getAttribute('aria-label') || alt; |
| 77 } else { |
| 78 this._setAriaHidden(alt===''); |
| 79 this.setAttribute('aria-label', alt); |
| 80 } |
| 81 }, |
| 82 |
| 83 _setAriaHidden: function(hidden) { |
| 84 var attr = 'aria-hidden'; |
| 85 if (hidden) { |
| 86 this.setAttribute(attr, 'true'); |
| 87 } else { |
| 88 this.removeAttribute(attr); |
| 89 } |
| 90 }, |
| 91 |
| 92 reset: function() { |
| 93 this.active = false; |
| 94 this._coolingDown = false; |
| 16 } | 95 } |
| 17 | 96 |
| 18 Polymer({ | 97 }); |
| 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 | 98 |
| 121 | 99 |
| OLD | NEW |