| 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 | 10 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 </div><div class="circle-clipper right"> | 92 </div><div class="circle-clipper right"> |
| 93 <div class="circle"></div> | 93 <div class="circle"></div> |
| 94 </div> | 94 </div> |
| 95 </div> | 95 </div> |
| 96 </div> | 96 </div> |
| 97 | 97 |
| 98 </template> | 98 </template> |
| 99 | 99 |
| 100 <script> | 100 <script> |
| 101 | 101 |
| 102 (function() { | 102 Polymer({ |
| 103 | 103 |
| 104 'use strict'; | 104 is: 'paper-spinner', |
| 105 | 105 |
| 106 function classNames(obj) { | 106 listeners: { |
| 107 var classNames = []; | 107 'animationend': 'reset', |
| 108 for (var key in obj) { | 108 'webkitAnimationEnd': 'reset' |
| 109 if (obj.hasOwnProperty(key) && obj[key]) { | 109 }, |
| 110 classNames.push(key); | 110 |
| 111 } | 111 properties: { |
| 112 |
| 113 /** |
| 114 * Displays the spinner. |
| 115 * |
| 116 * @attribute active |
| 117 * @type boolean |
| 118 * @default false |
| 119 */ |
| 120 active: { |
| 121 type: Boolean, |
| 122 value: false, |
| 123 reflectToAttribute: true, |
| 124 observer: '_activeChanged' |
| 125 }, |
| 126 |
| 127 /** |
| 128 * Alternative text content for accessibility support. |
| 129 * If alt is present, it will add an aria-label whose content matches al
t when active. |
| 130 * If alt is not present, it will default to 'loading' as the alt value. |
| 131 * |
| 132 * @attribute alt |
| 133 * @type string |
| 134 * @default 'loading' |
| 135 */ |
| 136 alt: { |
| 137 type: String, |
| 138 value: 'loading', |
| 139 observer: '_altChanged' |
| 140 }, |
| 141 |
| 142 /** |
| 143 * True when the spinner is going from active to inactive. This is repre
sented by a fade |
| 144 * to 0% opacity to the user. |
| 145 */ |
| 146 _coolingDown: { |
| 147 type: Boolean, |
| 148 value: false |
| 149 }, |
| 150 |
| 151 _spinnerContainerClassName: { |
| 152 type: String, |
| 153 computed: '_computeSpinnerContainerClassName(active, _coolingDown)' |
| 112 } | 154 } |
| 113 | 155 |
| 114 return classNames.join(' '); | 156 }, |
| 157 |
| 158 _computeSpinnerContainerClassName: function(active, coolingDown) { |
| 159 return [ |
| 160 active || coolingDown ? 'active' : '', |
| 161 coolingDown ? 'cooldown' : '' |
| 162 ].join(' '); |
| 163 }, |
| 164 |
| 165 _activeChanged: function(active, old) { |
| 166 this._setAriaHidden(!active); |
| 167 if (!active && old) { |
| 168 this._coolingDown = true; |
| 169 } |
| 170 }, |
| 171 |
| 172 _altChanged: function(alt) { |
| 173 // user-provided `aria-label` takes precedence over prototype default |
| 174 if (alt === this.getPropertyInfo('alt').value) { |
| 175 this.alt = this.getAttribute('aria-label') || alt; |
| 176 } else { |
| 177 this._setAriaHidden(alt===''); |
| 178 this.setAttribute('aria-label', alt); |
| 179 } |
| 180 }, |
| 181 |
| 182 _setAriaHidden: function(hidden) { |
| 183 var attr = 'aria-hidden'; |
| 184 if (hidden) { |
| 185 this.setAttribute(attr, 'true'); |
| 186 } else { |
| 187 this.removeAttribute(attr); |
| 188 } |
| 189 }, |
| 190 |
| 191 reset: function() { |
| 192 this.active = false; |
| 193 this._coolingDown = false; |
| 115 } | 194 } |
| 116 | 195 |
| 117 Polymer({ | 196 }); |
| 118 | |
| 119 is: 'paper-spinner', | |
| 120 | |
| 121 listeners: { | |
| 122 'animationend': 'reset', | |
| 123 'webkitAnimationEnd': 'reset' | |
| 124 }, | |
| 125 | |
| 126 properties: { | |
| 127 | |
| 128 /** | |
| 129 * Displays the spinner. | |
| 130 * | |
| 131 * @attribute active | |
| 132 * @type boolean | |
| 133 * @default false | |
| 134 */ | |
| 135 active: { | |
| 136 observer: '_activeChanged', | |
| 137 type: Boolean, | |
| 138 value: false | |
| 139 }, | |
| 140 | |
| 141 /** | |
| 142 * Alternative text content for accessibility support. | |
| 143 * If alt is present, it will add an aria-label whose content matches
alt when active. | |
| 144 * If alt is not present, it will default to 'loading' as the alt valu
e. | |
| 145 * | |
| 146 * @attribute alt | |
| 147 * @type string | |
| 148 * @default 'loading' | |
| 149 */ | |
| 150 alt: { | |
| 151 observer: '_altChanged', | |
| 152 type: String, | |
| 153 value: 'loading' | |
| 154 }, | |
| 155 | |
| 156 /** | |
| 157 * True when the spinner is going from active to inactive. This is rep
resented by a fade | |
| 158 * to 0% opacity to the user. | |
| 159 */ | |
| 160 _coolingDown: { | |
| 161 type: Boolean, | |
| 162 value: false | |
| 163 }, | |
| 164 | |
| 165 _spinnerContainerClassName: { | |
| 166 type: String, | |
| 167 computed: '_computeSpinnerContainerClassName(active, _coolingDown)' | |
| 168 } | |
| 169 | |
| 170 }, | |
| 171 | |
| 172 _computeSpinnerContainerClassName: function(active, _coolingDown) { | |
| 173 return classNames({ | |
| 174 active: active || _coolingDown, | |
| 175 cooldown: _coolingDown | |
| 176 }); | |
| 177 }, | |
| 178 | |
| 179 ready: function() { | |
| 180 // Allow user-provided `aria-label` take preference to any other text
alternative. | |
| 181 if (this.hasAttribute('aria-label')) { | |
| 182 this.alt = this.getAttribute('aria-label'); | |
| 183 } else { | |
| 184 this.setAttribute('aria-label', this.alt); | |
| 185 } | |
| 186 | |
| 187 if (!this.active) { | |
| 188 this.setAttribute('aria-hidden', 'true'); | |
| 189 } | |
| 190 }, | |
| 191 | |
| 192 _activeChanged: function() { | |
| 193 if (this.active) { | |
| 194 this.removeAttribute('aria-hidden'); | |
| 195 } else { | |
| 196 this._coolingDown = true; | |
| 197 this.setAttribute('aria-hidden', 'true'); | |
| 198 } | |
| 199 }, | |
| 200 | |
| 201 _altChanged: function() { | |
| 202 if (this.alt === '') { | |
| 203 this.setAttribute('aria-hidden', 'true'); | |
| 204 } else { | |
| 205 this.removeAttribute('aria-hidden'); | |
| 206 } | |
| 207 | |
| 208 this.setAttribute('aria-label', this.alt); | |
| 209 }, | |
| 210 | |
| 211 reset: function() { | |
| 212 this.active = false; | |
| 213 this._coolingDown = false; | |
| 214 } | |
| 215 | |
| 216 }); | |
| 217 | |
| 218 }()); | |
| 219 | 197 |
| 220 </script> | 198 </script> |
| 221 | 199 |
| 222 </dom-module> | 200 </dom-module> |
| OLD | NEW |