| 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/color.html"> | |
| 13 <link rel="import" href="../iron-flex-layout/iron-flex-layout.html"> | |
| 14 | |
| 15 <!-- | |
| 16 Element providing material design circular spinner. | |
| 17 | |
| 18 <paper-spinner active></paper-spinner> | |
| 19 | |
| 20 The default spinner cycles between four layers of colors; by default they are | |
| 21 blue, red, yellow and green. It can be customized so that it uses one color only | |
| 22 by setting all the layer colors to the same value. | |
| 23 | |
| 24 ### Accessibility | |
| 25 | |
| 26 Alt attribute should be set to provide adequate context for accessibility. If no
t provided, | |
| 27 it defaults to 'loading'. | |
| 28 Empty alt can be provided to mark the element as decorative if alternative conte
nt is provided | |
| 29 in another form (e.g. a text block following the spinner). | |
| 30 | |
| 31 <paper-spinner alt="Loading contacts list" active></paper-spinner> | |
| 32 | |
| 33 ### Styling | |
| 34 | |
| 35 The following custom properties and mixins are available for styling: | |
| 36 | |
| 37 Custom property | Description | Default | |
| 38 ----------------|-------------|---------- | |
| 39 `--paper-spinner-layer-1-color` | Color of the first spinner rotation | `--googl
e-blue-500` | |
| 40 `--paper-spinner-layer-2-color` | Color of the second spinner rotation | `--goog
le-red-500` | |
| 41 `--paper-spinner-layer-3-color` | Color of the third spinner rotation | `--googl
e-yellow-500` | |
| 42 `--paper-spinner-layer-4-color` | Color of the fourth spinner rotation | `--goog
le-green-500` | |
| 43 | |
| 44 @group Paper Elements | |
| 45 @element paper-spinner | |
| 46 @hero hero.svg | |
| 47 @demo demo/index.html | |
| 48 --> | |
| 49 | |
| 50 <dom-module id="paper-spinner"> | |
| 51 | |
| 52 <link rel="import" type="css" href="paper-spinner.css"> | |
| 53 | |
| 54 <template> | |
| 55 | |
| 56 <div id="spinnerContainer" class-name="[[_spinnerContainerClassName]]"> | |
| 57 <div class="spinner-layer layer-1"> | |
| 58 <div class="circle-clipper left"> | |
| 59 <div class="circle"></div> | |
| 60 </div><div class="gap-patch"> | |
| 61 <div class="circle"></div> | |
| 62 </div><div class="circle-clipper right"> | |
| 63 <div class="circle"></div> | |
| 64 </div> | |
| 65 </div> | |
| 66 | |
| 67 <div class="spinner-layer layer-2"> | |
| 68 <div class="circle-clipper left"> | |
| 69 <div class="circle"></div> | |
| 70 </div><div class="gap-patch"> | |
| 71 <div class="circle"></div> | |
| 72 </div><div class="circle-clipper right"> | |
| 73 <div class="circle"></div> | |
| 74 </div> | |
| 75 </div> | |
| 76 | |
| 77 <div class="spinner-layer layer-3"> | |
| 78 <div class="circle-clipper left"> | |
| 79 <div class="circle"></div> | |
| 80 </div><div class="gap-patch"> | |
| 81 <div class="circle"></div> | |
| 82 </div><div class="circle-clipper right"> | |
| 83 <div class="circle"></div> | |
| 84 </div> | |
| 85 </div> | |
| 86 | |
| 87 <div class="spinner-layer layer-4"> | |
| 88 <div class="circle-clipper left"> | |
| 89 <div class="circle"></div> | |
| 90 </div><div class="gap-patch"> | |
| 91 <div class="circle"></div> | |
| 92 </div><div class="circle-clipper right"> | |
| 93 <div class="circle"></div> | |
| 94 </div> | |
| 95 </div> | |
| 96 </div> | |
| 97 | |
| 98 </template> | |
| 99 | |
| 100 <script> | |
| 101 | |
| 102 (function() { | |
| 103 | |
| 104 'use strict'; | |
| 105 | |
| 106 function classNames(obj) { | |
| 107 var classNames = []; | |
| 108 for (var key in obj) { | |
| 109 if (obj.hasOwnProperty(key) && obj[key]) { | |
| 110 classNames.push(key); | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 return classNames.join(' '); | |
| 115 } | |
| 116 | |
| 117 Polymer({ | |
| 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 | |
| 220 </script> | |
| 221 | |
| 222 </dom-module> | |
| OLD | NEW |