|
145 | 145 | ---------------------------------
|
146 | 146 |
|
147 | 147 | @element core-layout
|
148 |
| -
|
149 |
| ---> |
150 |
| -<-- |
151 |
| - If true, the host element of the core-layout element becomes a |
152 |
| - flexbox. Apply additional layout classes to the host element to customize |
153 |
| - its styling. |
154 |
| - |
155 |
| - @attribute host |
156 |
| - @type boolean |
157 |
| - @default false |
158 | 148 | -->
|
| 149 | + |
159 | 150 | <link rel="import" href="../polymer/polymer.html">
|
160 | 151 |
|
161 | 152 | <polymer-element name="core-layout" attributes="flow justify align isContainer">
|
162 |
| - |
163 |
| - <template> |
164 |
| - |
165 |
| - <link no-shim rel="stylesheet" href="core-layout.css"> |
166 |
| - <link no-shim rel="stylesheet" href="core-layout-host.css"> |
167 |
| - |
168 |
| - </template> |
169 |
| - |
170 |
| - <script> |
171 |
| - |
172 |
| - (function() { |
173 |
| - |
174 |
| - Polymer('core-layout', { |
175 |
| - |
176 |
| - isContainer: false, |
177 |
| - /** |
178 |
| - * Controls how the element lays out or flows. Set to `h` for a |
179 |
| - * horizontal flow or `v` for a vertical flow. |
180 |
| - * |
181 |
| - * @attribute flow |
182 |
| - * @type string h|v |
183 |
| - * @default '' |
184 |
| - */ |
185 |
| - flow: '', |
186 |
| - /** |
187 |
| - * Controls how the items are aligned in the flow direction. For |
188 |
| - * example for a flow of `h`, this controls how each item is aligned |
189 |
| - * horizontally. |
190 |
| - * |
191 |
| - * @attribute justify |
192 |
| - * @type string start|center|end|between |
193 |
| - * @default '' |
194 |
| - */ |
195 |
| - justify: '', |
196 |
| - /** |
197 |
| - * Controls how the items are aligned in cross-flow direction. For |
198 |
| - * example for a flow of `h`, this controls how each item is aligned |
199 |
| - * vertically. |
200 |
| - * |
201 |
| - * @attribute align |
202 |
| - * @type string start|center|end |
203 |
| - * @default '' |
204 |
| - */ |
205 |
| - align: '', |
206 |
| - /** |
207 |
| - * Controls whether or not the items layout in reverse order. |
208 |
| - * |
209 |
| - * @attribute reverse |
210 |
| - * @type boolean |
211 |
| - * @default false |
212 |
| - */ |
213 |
| - reverse: false, |
214 |
| - layoutPrefix: 'core-', |
215 |
| - |
216 |
| - // NOTE: include template so that styles are loaded, but remove |
217 |
| - // so that we can decide dynamically what part to include |
218 |
| - registerCallback: function(polymerElement) { |
219 |
| - var template = polymerElement.querySelector('template'); |
220 |
| - this.styles = template.content.querySelectorAll('style').array(); |
221 |
| - this.styles.forEach(function(s) { |
222 |
| - s.removeAttribute('no-shim'); |
223 |
| - }) |
224 |
| - }, |
225 |
| - |
226 |
| - fetchTemplate: function() { |
227 |
| - return null; |
228 |
| - }, |
229 |
| - |
230 |
| - attached: function() { |
231 |
| - this.installScopeStyle(this.styles[0]); |
232 |
| - if (this.children.length) { |
233 |
| - this.isContainer = true; |
234 |
| - } |
235 |
| - var container = this.isContainer ? this : this.parentNode; |
236 |
| - // detect if laying out a shadowRoot host. |
237 |
| - var forHost = container instanceof ShadowRoot; |
238 |
| - if (forHost) { |
239 |
| - this.installScopeStyle(this.styles[1], 'host'); |
240 |
| - container = container.host || document.body; |
241 |
| - } |
242 |
| - this.layoutContainer = container; |
243 |
| - }, |
244 |
| - |
245 |
| - detached: function() { |
246 |
| - this.layoutContainer = null; |
247 |
| - }, |
248 |
| - |
249 |
| - layoutContainerChanged: function(old) { |
250 |
| - this.style.display = this.layoutContainer === this ? null : 'none'; |
251 |
| - this.flowChanged(); |
252 |
| - this.alignChanged(); |
253 |
| - this.justifyChanged(); |
254 |
| - }, |
255 |
| - setLayoutAttribute: function(name, value) { |
256 |
| - if (this.layoutContainer && name) { |
257 |
| - if (value) { |
258 |
| - this.layoutContainer.setAttribute(this.layoutPrefix + name, value); |
259 |
| - } else { |
260 |
| - this.layoutContainer.removeAttribute(name); |
261 |
| - } |
| 153 | +<template> |
| 154 | + |
| 155 | + <link no-shim rel="stylesheet" href="core-layout.css"> |
| 156 | + <link no-shim rel="stylesheet" href="core-layout-host.css"> |
| 157 | + |
| 158 | +</template> |
| 159 | +<script> |
| 160 | + |
| 161 | + Polymer('core-layout', { |
| 162 | + /** |
| 163 | + * If true, the host element of the core-layout element becomes a |
| 164 | + * flexbox. Apply additional layout classes to the host element to customize |
| 165 | + * its styling. |
| 166 | + * |
| 167 | + * @attribute host |
| 168 | + * @type boolean |
| 169 | + * @default false |
| 170 | + */ |
| 171 | + |
| 172 | + /** |
| 173 | + * Controls how the element lays out or flows. Set to `h` for a |
| 174 | + * horizontal flow or `v` for a vertical flow. |
| 175 | + * |
| 176 | + * @attribute flow |
| 177 | + * @type string h|v |
| 178 | + * @default '' |
| 179 | + */ |
| 180 | + flow: '', |
| 181 | + |
| 182 | + /** |
| 183 | + * Controls how the items are aligned in the flow direction. For |
| 184 | + * example for a flow of `h`, this controls how each item is aligned |
| 185 | + * horizontally. |
| 186 | + * |
| 187 | + * @attribute justify |
| 188 | + * @type string start|center|end|between |
| 189 | + * @default '' |
| 190 | + */ |
| 191 | + justify: '', |
| 192 | + |
| 193 | + /** |
| 194 | + * Controls how the items are aligned in cross-flow direction. For |
| 195 | + * example for a flow of `h`, this controls how each item is aligned |
| 196 | + * vertically. |
| 197 | + * |
| 198 | + * @attribute align |
| 199 | + * @type string start|center|end |
| 200 | + * @default '' |
| 201 | + */ |
| 202 | + align: '', |
| 203 | + |
| 204 | + /** |
| 205 | + * Controls whether or not the items layout in reverse order. |
| 206 | + * |
| 207 | + * @attribute reverse |
| 208 | + * @type boolean |
| 209 | + * @default false |
| 210 | + */ |
| 211 | + reverse: false, |
| 212 | + |
| 213 | + isContainer: false, |
| 214 | + |
| 215 | + layoutPrefix: 'core-', |
| 216 | + |
| 217 | + // NOTE: include template so that styles are loaded, but remove |
| 218 | + // so that we can decide dynamically what part to include |
| 219 | + registerCallback: function(polymerElement) { |
| 220 | + var template = polymerElement.querySelector('template'); |
| 221 | + this.styles = template.content.querySelectorAll('style').array(); |
| 222 | + this.styles.forEach(function(s) { |
| 223 | + s.removeAttribute('no-shim'); |
| 224 | + }) |
| 225 | + }, |
| 226 | + |
| 227 | + fetchTemplate: function() { |
| 228 | + return null; |
| 229 | + }, |
| 230 | + |
| 231 | + attached: function() { |
| 232 | + this.installScopeStyle(this.styles[0]); |
| 233 | + if (this.children.length) { |
| 234 | + this.isContainer = true; |
| 235 | + } |
| 236 | + var container = this.isContainer ? this : this.parentNode; |
| 237 | + // detect if laying out a shadowRoot host. |
| 238 | + var forHost = container instanceof ShadowRoot; |
| 239 | + if (forHost) { |
| 240 | + this.installScopeStyle(this.styles[1], 'host'); |
| 241 | + container = container.host || document.body; |
| 242 | + } |
| 243 | + this.layoutContainer = container; |
| 244 | + }, |
| 245 | + |
| 246 | + detached: function() { |
| 247 | + this.layoutContainer = null; |
| 248 | + }, |
| 249 | + |
| 250 | + layoutContainerChanged: function(old) { |
| 251 | + this.style.display = this.layoutContainer === this ? null : 'none'; |
| 252 | + this.flowChanged(); |
| 253 | + this.alignChanged(); |
| 254 | + this.justifyChanged(); |
| 255 | + }, |
| 256 | + |
| 257 | + setLayoutAttribute: function(name, value) { |
| 258 | + if (this.layoutContainer && name) { |
| 259 | + if (value) { |
| 260 | + this.layoutContainer.setAttribute(this.layoutPrefix + name, value); |
| 261 | + } else { |
| 262 | + this.layoutContainer.removeAttribute(name); |
262 | 263 | }
|
263 |
| - }, |
264 |
| - |
265 |
| - flowChanged: function() { |
266 |
| - this.setLayoutAttribute('flow', this.flow || 'h'); |
267 |
| - }, |
| 264 | + } |
| 265 | + }, |
268 | 266 |
|
269 |
| - alignChanged: function() { |
270 |
| - this.setLayoutAttribute('align', this.align); |
271 |
| - }, |
| 267 | + flowChanged: function() { |
| 268 | + this.setLayoutAttribute('flow', this.flow || 'h'); |
| 269 | + }, |
272 | 270 |
|
273 |
| - justifyChanged: function() { |
274 |
| - this.setLayoutAttribute('justify', this.justify); |
275 |
| - } |
| 271 | + alignChanged: function() { |
| 272 | + this.setLayoutAttribute('align', this.align); |
| 273 | + }, |
276 | 274 |
|
277 |
| - }); |
| 275 | + justifyChanged: function() { |
| 276 | + this.setLayoutAttribute('justify', this.justify); |
| 277 | + } |
278 | 278 |
|
279 |
| - })(); |
280 |
| - </script> |
| 279 | + }); |
281 | 280 |
|
| 281 | +</script> |
282 | 282 | </polymer-element>
|
0 commit comments