OLD | NEW |
(Empty) | |
| 1 |
| 2 |
| 3 (function() { |
| 4 |
| 5 Polymer('core-layout', { |
| 6 |
| 7 isContainer: false, |
| 8 /** |
| 9 * Controls if the element lays out vertically or not. |
| 10 * |
| 11 * @attribute vertical |
| 12 * @type boolean |
| 13 * @default false |
| 14 */ |
| 15 vertical: false, |
| 16 /** |
| 17 * Controls how the items are aligned in the main-axis direction. For |
| 18 * example for a horizontal layout, this controls how each item is aligned |
| 19 * horizontally. |
| 20 * |
| 21 * @attribute justify |
| 22 * @type string start|center|end|between |
| 23 * @default '' |
| 24 */ |
| 25 justify: '', |
| 26 /** |
| 27 * Controls how the items are aligned in cross-axis direction. For |
| 28 * example for a horizontal layout, this controls how each item is aligned |
| 29 * vertically. |
| 30 * |
| 31 * @attribute align |
| 32 * @type string start|center|end |
| 33 * @default '' |
| 34 */ |
| 35 align: '', |
| 36 /** |
| 37 * Controls whether or not the items layout in reverse order. |
| 38 * |
| 39 * @attribute reverse |
| 40 * @type boolean |
| 41 * @default false |
| 42 */ |
| 43 reverse: false, |
| 44 layoutPrefix: 'core-', |
| 45 |
| 46 // NOTE: include template so that styles are loaded, but remove |
| 47 // so that we can decide dynamically what part to include |
| 48 registerCallback: function(polymerElement) { |
| 49 var template = polymerElement.querySelector('template'); |
| 50 this.styles = template.content.querySelectorAll('style').array(); |
| 51 this.styles.forEach(function(s) { |
| 52 s.removeAttribute('no-shim'); |
| 53 }) |
| 54 }, |
| 55 |
| 56 fetchTemplate: function() { |
| 57 return null; |
| 58 }, |
| 59 |
| 60 attached: function() { |
| 61 this.installScopeStyle(this.styles[0]); |
| 62 if (this.children.length) { |
| 63 this.isContainer = true; |
| 64 } |
| 65 var container = this.isContainer ? this : this.parentNode; |
| 66 // detect if laying out a shadowRoot host. |
| 67 var forHost = container instanceof ShadowRoot; |
| 68 if (forHost) { |
| 69 this.installScopeStyle(this.styles[1], 'host'); |
| 70 container = container.host || document.body; |
| 71 } |
| 72 this.layoutContainer = container; |
| 73 }, |
| 74 |
| 75 detached: function() { |
| 76 this.layoutContainer = null; |
| 77 }, |
| 78 |
| 79 layoutContainerChanged: function(old) { |
| 80 this.style.display = this.layoutContainer === this ? null : 'none'; |
| 81 this.verticalChanged(); |
| 82 this.alignChanged(); |
| 83 this.justifyChanged(); |
| 84 }, |
| 85 |
| 86 setLayoutClass: function(prefix, old, newValue) { |
| 87 if (this.layoutContainer) { |
| 88 prefix = this.layoutPrefix + prefix; |
| 89 if (old) { |
| 90 this.layoutContainer.classList.remove(prefix + old); |
| 91 } |
| 92 if (newValue) { |
| 93 this.layoutContainer.classList.add(prefix + newValue); |
| 94 } |
| 95 } |
| 96 }, |
| 97 |
| 98 verticalChanged: function(old) { |
| 99 old = old ? 'v' : 'h'; |
| 100 var vertical = this.vertical ? 'v' : 'h'; |
| 101 this.setLayoutClass('', old, vertical); |
| 102 }, |
| 103 |
| 104 alignChanged: function(old) { |
| 105 this.setLayoutClass('align-', old, this.align); |
| 106 }, |
| 107 |
| 108 justifyChanged: function(old) { |
| 109 this.setLayoutClass('justify-', old, this.justify); |
| 110 }, |
| 111 |
| 112 reverseChanged: function(old) { |
| 113 old = old ? 'reverse' : ''; |
| 114 var newValue = this.reverse ? 'reverse' : ''; |
| 115 this.setLayoutClass('', old, newValue); |
| 116 } |
| 117 |
| 118 }); |
| 119 |
| 120 })(); |
| 121 |
OLD | NEW |