| 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 |
| 11 <link rel="import" href="../polymer/polymer.html"> | 11 <link rel="import" href="../polymer/polymer.html"> |
| 12 | 12 |
| 13 <!-- | 13 <!-- |
| 14 `iron-collapse` creates a collapsible block of content. By default, the content | 14 `iron-collapse` creates a collapsible block of content. By default, the content |
| 15 will be collapsed. Use `opened` or `toggle()` to show/hide the content. | 15 will be collapsed. Use `opened` or `toggle()` to show/hide the content. |
| 16 | 16 |
| 17 <button on-click="{{toggle}}">toggle collapse</button> | 17 <button on-click="toggle">toggle collapse</button> |
| 18 | 18 |
| 19 <iron-collapse id="collapse"> | 19 <iron-collapse id="collapse"> |
| 20 <div>Content goes here...</div> | 20 <div>Content goes here...</div> |
| 21 </iron-collapse> | 21 </iron-collapse> |
| 22 | 22 |
| 23 ... | 23 ... |
| 24 | 24 |
| 25 toggle: function() { | 25 toggle: function() { |
| 26 this.$.collapse.toggle(); | 26 this.$.collapse.toggle(); |
| 27 } | 27 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 49 @element iron-collapse | 49 @element iron-collapse |
| 50 --> | 50 --> |
| 51 | 51 |
| 52 <dom-module id="iron-collapse"> | 52 <dom-module id="iron-collapse"> |
| 53 | 53 |
| 54 <style> | 54 <style> |
| 55 | 55 |
| 56 :host { | 56 :host { |
| 57 display: block; | 57 display: block; |
| 58 transition-duration: 300ms; | 58 transition-duration: 300ms; |
| 59 overflow: auto; |
| 59 } | 60 } |
| 60 | 61 |
| 61 :host(.iron-collapse-closed) { | 62 :host(.iron-collapse-closed) { |
| 62 display: none; | 63 display: none; |
| 63 } | 64 } |
| 64 | 65 |
| 65 :host(:not(.iron-collapse-opened)) { | |
| 66 overflow: hidden; | |
| 67 } | |
| 68 | |
| 69 </style> | 66 </style> |
| 70 | 67 |
| 71 <template> | 68 <template> |
| 72 | 69 |
| 73 <content></content> | 70 <content></content> |
| 74 | 71 |
| 75 </template> | 72 </template> |
| 76 | 73 |
| 77 </dom-module> | 74 </dom-module> |
| 78 | 75 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 98 /** | 95 /** |
| 99 * Set opened to true to show the collapse element and to false to hide it
. | 96 * Set opened to true to show the collapse element and to false to hide it
. |
| 100 * | 97 * |
| 101 * @attribute opened | 98 * @attribute opened |
| 102 */ | 99 */ |
| 103 opened: { | 100 opened: { |
| 104 type: Boolean, | 101 type: Boolean, |
| 105 value: false, | 102 value: false, |
| 106 notify: true, | 103 notify: true, |
| 107 observer: '_openedChanged' | 104 observer: '_openedChanged' |
| 108 } | 105 }, |
| 106 |
| 107 /** |
| 108 * Set noAnimation to true to disable animations |
| 109 * |
| 110 * @attribute noAnimation |
| 111 */ |
| 112 noAnimation: { |
| 113 type: Boolean |
| 114 }, |
| 109 | 115 |
| 110 }, | 116 }, |
| 111 | 117 |
| 112 hostAttributes: { | 118 hostAttributes: { |
| 113 role: 'group', | 119 role: 'group', |
| 120 'aria-hidden': 'true', |
| 114 'aria-expanded': 'false' | 121 'aria-expanded': 'false' |
| 115 }, | 122 }, |
| 116 | 123 |
| 117 listeners: { | 124 listeners: { |
| 118 transitionend: '_transitionEnd' | 125 transitionend: '_transitionEnd' |
| 119 }, | 126 }, |
| 120 | 127 |
| 121 ready: function() { | 128 attached: function() { |
| 122 // Avoid transition at the beginning e.g. page loads and enable | 129 // It will take care of setting correct classes and styles. |
| 123 // transitions only after the element is rendered and ready. | 130 this._transitionEnd(); |
| 124 this._enableTransition = true; | |
| 125 }, | 131 }, |
| 126 | 132 |
| 127 /** | 133 /** |
| 128 * Toggle the opened state. | 134 * Toggle the opened state. |
| 129 * | 135 * |
| 130 * @method toggle | 136 * @method toggle |
| 131 */ | 137 */ |
| 132 toggle: function() { | 138 toggle: function() { |
| 133 this.opened = !this.opened; | 139 this.opened = !this.opened; |
| 134 }, | 140 }, |
| 135 | 141 |
| 136 show: function() { | 142 show: function() { |
| 137 this.toggleClass('iron-collapse-closed', false); | 143 this.opened = true; |
| 138 this.updateSize('auto', false); | |
| 139 var s = this._calcSize(); | |
| 140 this.updateSize('0px', false); | |
| 141 // force layout to ensure transition will go | |
| 142 this.offsetHeight; | |
| 143 this.updateSize(s, true); | |
| 144 }, | 144 }, |
| 145 | 145 |
| 146 hide: function() { | 146 hide: function() { |
| 147 this.toggleClass('iron-collapse-opened', false); | 147 this.opened = false; |
| 148 this.updateSize(this._calcSize(), false); | |
| 149 // force layout to ensure transition will go | |
| 150 this.offsetHeight; | |
| 151 this.updateSize('0px', true); | |
| 152 }, | 148 }, |
| 153 | 149 |
| 154 updateSize: function(size, animated) { | 150 updateSize: function(size, animated) { |
| 155 this.enableTransition(animated); | 151 // No change! |
| 156 var s = this.style; | 152 if (this.style[this.dimension] === size) { |
| 157 var nochange = s[this.dimension] === size; | 153 return; |
| 158 s[this.dimension] = size; | |
| 159 if (animated && nochange) { | |
| 160 this._transitionEnd(); | |
| 161 } | 154 } |
| 155 |
| 156 this._updateTransition(false); |
| 157 // If we can animate, must do some prep work. |
| 158 if (animated && !this.noAnimation) { |
| 159 // Animation will start at the current size. |
| 160 var startSize = this._calcSize(); |
| 161 // For `auto` we must calculate what is the final size for the animation
. |
| 162 // After the transition is done, _transitionEnd will set the size back t
o `auto`. |
| 163 if (size === 'auto') { |
| 164 this.style[this.dimension] = size; |
| 165 size = this._calcSize(); |
| 166 } |
| 167 // Go to startSize without animation. |
| 168 this.style[this.dimension] = startSize; |
| 169 // Force layout to ensure transition will go. Set offsetHeight to itself |
| 170 // so that compilers won't remove it. |
| 171 this.offsetHeight = this.offsetHeight; |
| 172 // Enable animation. |
| 173 this._updateTransition(true); |
| 174 } |
| 175 // Set the final size. |
| 176 this.style[this.dimension] = size; |
| 162 }, | 177 }, |
| 163 | 178 |
| 179 /** |
| 180 * enableTransition() is deprecated, but left over so it doesn't break exist
ing code. |
| 181 * Please use `noAnimation` property instead. |
| 182 * |
| 183 * @method enableTransition |
| 184 * @deprecated since version 1.0.4 |
| 185 */ |
| 164 enableTransition: function(enabled) { | 186 enableTransition: function(enabled) { |
| 165 this.style.transitionDuration = (enabled && this._enableTransition) ? '' :
'0s'; | 187 console.warn('`enableTransition()` is deprecated, use `noAnimation` instea
d.'); |
| 188 this.noAnimation = !enabled; |
| 189 }, |
| 190 |
| 191 _updateTransition: function(enabled) { |
| 192 this.style.transitionDuration = (enabled && !this.noAnimation) ? '' : '0s'
; |
| 166 }, | 193 }, |
| 167 | 194 |
| 168 _horizontalChanged: function() { | 195 _horizontalChanged: function() { |
| 169 this.dimension = this.horizontal ? 'width' : 'height'; | 196 this.dimension = this.horizontal ? 'width' : 'height'; |
| 170 this.style.transitionProperty = this.dimension; | 197 this.style.transitionProperty = this.dimension; |
| 171 }, | 198 }, |
| 172 | 199 |
| 173 _openedChanged: function() { | 200 _openedChanged: function() { |
| 174 this[this.opened ? 'show' : 'hide'](); | 201 this.setAttribute('aria-expanded', this.opened); |
| 175 this.setAttribute('aria-expanded', this.opened ? 'true' : 'false'); | 202 this.setAttribute('aria-hidden', !this.opened); |
| 176 | 203 |
| 204 this.toggleClass('iron-collapse-closed', false); |
| 205 this.toggleClass('iron-collapse-opened', false); |
| 206 this.updateSize(this.opened ? 'auto' : '0px', true); |
| 207 |
| 208 // Focus the current collapse. |
| 209 if (this.opened) { |
| 210 this.focus(); |
| 211 } |
| 212 if (this.noAnimation) { |
| 213 this._transitionEnd(); |
| 214 } |
| 177 }, | 215 }, |
| 178 | 216 |
| 179 _transitionEnd: function() { | 217 _transitionEnd: function() { |
| 180 if (this.opened) { | 218 if (this.opened) { |
| 181 this.updateSize('auto', false); | 219 this.style[this.dimension] = 'auto'; |
| 182 } | 220 } |
| 183 this.toggleClass('iron-collapse-closed', !this.opened); | 221 this.toggleClass('iron-collapse-closed', !this.opened); |
| 184 this.toggleClass('iron-collapse-opened', this.opened); | 222 this.toggleClass('iron-collapse-opened', this.opened); |
| 185 this.enableTransition(false); | 223 this._updateTransition(false); |
| 186 }, | 224 }, |
| 187 | 225 |
| 188 _calcSize: function() { | 226 _calcSize: function() { |
| 189 return this.getBoundingClientRect()[this.dimension] + 'px'; | 227 return this.getBoundingClientRect()[this.dimension] + 'px'; |
| 190 }, | 228 } |
| 191 | |
| 192 | 229 |
| 193 }); | 230 }); |
| 194 | 231 |
| 195 </script> | 232 </script> |
| OLD | NEW |