| OLD | NEW |
| 1 Polymer({ | 1 Polymer({ |
| 2 | 2 |
| 3 is: 'iron-collapse', | 3 is: 'iron-collapse', |
| 4 | 4 |
| 5 behaviors: [ | 5 behaviors: [ |
| 6 Polymer.IronResizableBehavior | 6 Polymer.IronResizableBehavior |
| 7 ], | 7 ], |
| 8 | 8 |
| 9 properties: { | 9 properties: { |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * @attribute opened | 25 * @attribute opened |
| 26 */ | 26 */ |
| 27 opened: { | 27 opened: { |
| 28 type: Boolean, | 28 type: Boolean, |
| 29 value: false, | 29 value: false, |
| 30 notify: true, | 30 notify: true, |
| 31 observer: '_openedChanged' | 31 observer: '_openedChanged' |
| 32 }, | 32 }, |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * Set noAnimation to true to disable animations | 35 * Set noAnimation to true to disable animations. |
| 36 * | 36 * |
| 37 * @attribute noAnimation | 37 * @attribute noAnimation |
| 38 */ | 38 */ |
| 39 noAnimation: { | 39 noAnimation: { |
| 40 type: Boolean | 40 type: Boolean |
| 41 }, | 41 }, |
| 42 | 42 |
| 43 /** |
| 44 * Stores the desired size of the collapse body. |
| 45 * @private |
| 46 */ |
| 47 _desiredSize: { |
| 48 type: String, |
| 49 value: '' |
| 50 } |
| 43 }, | 51 }, |
| 44 | 52 |
| 45 get dimension() { | 53 get dimension() { |
| 46 return this.horizontal ? 'width' : 'height'; | 54 return this.horizontal ? 'width' : 'height'; |
| 47 }, | 55 }, |
| 48 | 56 |
| 49 /** | 57 /** |
| 50 * `maxWidth` or `maxHeight`. | 58 * `maxWidth` or `maxHeight`. |
| 51 * @private | 59 * @private |
| 52 */ | 60 */ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 hide: function() { | 101 hide: function() { |
| 94 this.opened = false; | 102 this.opened = false; |
| 95 }, | 103 }, |
| 96 | 104 |
| 97 /** | 105 /** |
| 98 * Updates the size of the element. | 106 * Updates the size of the element. |
| 99 * @param {string} size The new value for `maxWidth`/`maxHeight` as css prop
erty value, usually `auto` or `0px`. | 107 * @param {string} size The new value for `maxWidth`/`maxHeight` as css prop
erty value, usually `auto` or `0px`. |
| 100 * @param {boolean=} animated if `true` updates the size with an animation,
otherwise without. | 108 * @param {boolean=} animated if `true` updates the size with an animation,
otherwise without. |
| 101 */ | 109 */ |
| 102 updateSize: function(size, animated) { | 110 updateSize: function(size, animated) { |
| 111 // Consider 'auto' as '', to take full size. |
| 112 size = size === 'auto' ? '' : size; |
| 103 // No change! | 113 // No change! |
| 104 var curSize = this.style[this._dimensionMax]; | 114 if (this._desiredSize === size) { |
| 105 if (curSize === size || (size === 'auto' && !curSize)) { | |
| 106 return; | 115 return; |
| 107 } | 116 } |
| 108 | 117 |
| 118 this._desiredSize = size; |
| 119 |
| 109 this._updateTransition(false); | 120 this._updateTransition(false); |
| 121 var willAnimate = animated && !this.noAnimation && this._isDisplayed; |
| 110 // If we can animate, must do some prep work. | 122 // If we can animate, must do some prep work. |
| 111 if (animated && !this.noAnimation && this._isDisplayed) { | 123 if (willAnimate) { |
| 112 // Animation will start at the current size. | 124 // Animation will start at the current size. |
| 113 var startSize = this._calcSize(); | 125 var startSize = this._calcSize(); |
| 114 // For `auto` we must calculate what is the final size for the animation
. | 126 // For `auto` we must calculate what is the final size for the animation
. |
| 115 // After the transition is done, _transitionEnd will set the size back t
o `auto`. | 127 // After the transition is done, _transitionEnd will set the size back t
o `auto`. |
| 116 if (size === 'auto') { | 128 if (size === '') { |
| 117 this.style[this._dimensionMax] = ''; | 129 this.style[this._dimensionMax] = ''; |
| 118 size = this._calcSize(); | 130 size = this._calcSize(); |
| 119 } | 131 } |
| 120 // Go to startSize without animation. | 132 // Go to startSize without animation. |
| 121 this.style[this._dimensionMax] = startSize; | 133 this.style[this._dimensionMax] = startSize; |
| 122 // Force layout to ensure transition will go. Set scrollTop to itself | 134 // Force layout to ensure transition will go. Set scrollTop to itself |
| 123 // so that compilers won't remove it. | 135 // so that compilers won't remove it. |
| 124 this.scrollTop = this.scrollTop; | 136 this.scrollTop = this.scrollTop; |
| 125 // Enable animation. | 137 // Enable animation. |
| 126 this._updateTransition(true); | 138 this._updateTransition(true); |
| 139 // If final size is the same as startSize it will not animate. |
| 140 willAnimate = (size !== startSize); |
| 127 } | 141 } |
| 128 // Set the final size. | 142 // Set the final size. |
| 129 if (size === 'auto') { | 143 this.style[this._dimensionMax] = size; |
| 130 this.style[this._dimensionMax] = ''; | 144 // If it won't animate, call transitionEnd to set correct classes. |
| 131 } else { | 145 if (!willAnimate) { |
| 132 this.style[this._dimensionMax] = size; | 146 this._transitionEnd(); |
| 133 } | 147 } |
| 134 }, | 148 }, |
| 135 | 149 |
| 136 /** | 150 /** |
| 137 * enableTransition() is deprecated, but left over so it doesn't break exist
ing code. | 151 * enableTransition() is deprecated, but left over so it doesn't break exist
ing code. |
| 138 * Please use `noAnimation` property instead. | 152 * Please use `noAnimation` property instead. |
| 139 * | 153 * |
| 140 * @method enableTransition | 154 * @method enableTransition |
| 141 * @deprecated since version 1.0.4 | 155 * @deprecated since version 1.0.4 |
| 142 */ | 156 */ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 161 this.setAttribute('aria-hidden', !this.opened); | 175 this.setAttribute('aria-hidden', !this.opened); |
| 162 | 176 |
| 163 this.toggleClass('iron-collapse-closed', false); | 177 this.toggleClass('iron-collapse-closed', false); |
| 164 this.toggleClass('iron-collapse-opened', false); | 178 this.toggleClass('iron-collapse-opened', false); |
| 165 this.updateSize(this.opened ? 'auto' : '0px', true); | 179 this.updateSize(this.opened ? 'auto' : '0px', true); |
| 166 | 180 |
| 167 // Focus the current collapse. | 181 // Focus the current collapse. |
| 168 if (this.opened) { | 182 if (this.opened) { |
| 169 this.focus(); | 183 this.focus(); |
| 170 } | 184 } |
| 171 if (this.noAnimation) { | |
| 172 this._transitionEnd(); | |
| 173 } | |
| 174 }, | 185 }, |
| 175 | 186 |
| 176 _transitionEnd: function() { | 187 _transitionEnd: function() { |
| 177 if (this.opened) { | 188 this.style[this._dimensionMax] = this._desiredSize; |
| 178 this.style[this._dimensionMax] = ''; | |
| 179 } | |
| 180 this.toggleClass('iron-collapse-closed', !this.opened); | 189 this.toggleClass('iron-collapse-closed', !this.opened); |
| 181 this.toggleClass('iron-collapse-opened', this.opened); | 190 this.toggleClass('iron-collapse-opened', this.opened); |
| 182 this._updateTransition(false); | 191 this._updateTransition(false); |
| 183 this.notifyResize(); | 192 this.notifyResize(); |
| 184 }, | 193 }, |
| 185 | 194 |
| 186 /** | 195 /** |
| 187 * Simplistic heuristic to detect if element has a parent with display: none | 196 * Simplistic heuristic to detect if element has a parent with display: none |
| 188 * | 197 * |
| 189 * @private | 198 * @private |
| 190 */ | 199 */ |
| 191 get _isDisplayed() { | 200 get _isDisplayed() { |
| 192 var rect = this.getBoundingClientRect(); | 201 var rect = this.getBoundingClientRect(); |
| 193 for (var prop in rect) { | 202 for (var prop in rect) { |
| 194 if (rect[prop] !== 0) return true; | 203 if (rect[prop] !== 0) return true; |
| 195 } | 204 } |
| 196 return false; | 205 return false; |
| 197 }, | 206 }, |
| 198 | 207 |
| 199 _calcSize: function() { | 208 _calcSize: function() { |
| 200 return this.getBoundingClientRect()[this.dimension] + 'px'; | 209 return this.getBoundingClientRect()[this.dimension] + 'px'; |
| 201 } | 210 } |
| 202 | 211 |
| 203 }); | 212 }); |
| OLD | NEW |