| 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 28 matching lines...) Expand all Loading... |
| 39 noAnimation: { | 39 noAnimation: { |
| 40 type: Boolean | 40 type: Boolean |
| 41 }, | 41 }, |
| 42 | 42 |
| 43 }, | 43 }, |
| 44 | 44 |
| 45 get dimension() { | 45 get dimension() { |
| 46 return this.horizontal ? 'width' : 'height'; | 46 return this.horizontal ? 'width' : 'height'; |
| 47 }, | 47 }, |
| 48 | 48 |
| 49 /** |
| 50 * `maxWidth` or `maxHeight`. |
| 51 * @private |
| 52 */ |
| 53 get _dimensionMax() { |
| 54 return this.horizontal ? 'maxWidth' : 'maxHeight'; |
| 55 }, |
| 56 |
| 57 /** |
| 58 * `max-width` or `max-height`. |
| 59 * @private |
| 60 */ |
| 61 get _dimensionMaxCss() { |
| 62 return this.horizontal ? 'max-width' : 'max-height'; |
| 63 }, |
| 64 |
| 49 hostAttributes: { | 65 hostAttributes: { |
| 50 role: 'group', | 66 role: 'group', |
| 51 'aria-hidden': 'true', | 67 'aria-hidden': 'true', |
| 52 'aria-expanded': 'false' | 68 'aria-expanded': 'false' |
| 53 }, | 69 }, |
| 54 | 70 |
| 55 listeners: { | 71 listeners: { |
| 56 transitionend: '_transitionEnd' | 72 transitionend: '_transitionEnd' |
| 57 }, | 73 }, |
| 58 | 74 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 71 }, | 87 }, |
| 72 | 88 |
| 73 show: function() { | 89 show: function() { |
| 74 this.opened = true; | 90 this.opened = true; |
| 75 }, | 91 }, |
| 76 | 92 |
| 77 hide: function() { | 93 hide: function() { |
| 78 this.opened = false; | 94 this.opened = false; |
| 79 }, | 95 }, |
| 80 | 96 |
| 97 /** |
| 98 * 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`. |
| 100 * @param {boolean=} animated if `true` updates the size with an animation,
otherwise without. |
| 101 */ |
| 81 updateSize: function(size, animated) { | 102 updateSize: function(size, animated) { |
| 82 // No change! | 103 // No change! |
| 83 if (this.style[this.dimension] === size) { | 104 var curSize = this.style[this._dimensionMax]; |
| 105 if (curSize === size || (size === 'auto' && !curSize)) { |
| 84 return; | 106 return; |
| 85 } | 107 } |
| 86 | 108 |
| 87 this._updateTransition(false); | 109 this._updateTransition(false); |
| 88 // If we can animate, must do some prep work. | 110 // If we can animate, must do some prep work. |
| 89 if (animated && !this.noAnimation && this._isDisplayed) { | 111 if (animated && !this.noAnimation && this._isDisplayed) { |
| 90 // Animation will start at the current size. | 112 // Animation will start at the current size. |
| 91 var startSize = this._calcSize(); | 113 var startSize = this._calcSize(); |
| 92 // For `auto` we must calculate what is the final size for the animation
. | 114 // For `auto` we must calculate what is the final size for the animation
. |
| 93 // After the transition is done, _transitionEnd will set the size back t
o `auto`. | 115 // After the transition is done, _transitionEnd will set the size back t
o `auto`. |
| 94 if (size === 'auto') { | 116 if (size === 'auto') { |
| 95 this.style[this.dimension] = size; | 117 this.style[this._dimensionMax] = ''; |
| 96 size = this._calcSize(); | 118 size = this._calcSize(); |
| 97 } | 119 } |
| 98 // Go to startSize without animation. | 120 // Go to startSize without animation. |
| 99 this.style[this.dimension] = startSize; | 121 this.style[this._dimensionMax] = startSize; |
| 100 // Force layout to ensure transition will go. Set offsetHeight to itself | 122 // Force layout to ensure transition will go. Set offsetHeight to itself |
| 101 // so that compilers won't remove it. | 123 // so that compilers won't remove it. |
| 102 this.offsetHeight = this.offsetHeight; | 124 this.offsetHeight = this.offsetHeight; |
| 103 // Enable animation. | 125 // Enable animation. |
| 104 this._updateTransition(true); | 126 this._updateTransition(true); |
| 105 } | 127 } |
| 106 // Set the final size. | 128 // Set the final size. |
| 107 this.style[this.dimension] = size; | 129 if (size === 'auto') { |
| 130 this.style[this._dimensionMax] = ''; |
| 131 } else { |
| 132 this.style[this._dimensionMax] = size; |
| 133 } |
| 108 }, | 134 }, |
| 109 | 135 |
| 110 /** | 136 /** |
| 111 * enableTransition() is deprecated, but left over so it doesn't break exist
ing code. | 137 * enableTransition() is deprecated, but left over so it doesn't break exist
ing code. |
| 112 * Please use `noAnimation` property instead. | 138 * Please use `noAnimation` property instead. |
| 113 * | 139 * |
| 114 * @method enableTransition | 140 * @method enableTransition |
| 115 * @deprecated since version 1.0.4 | 141 * @deprecated since version 1.0.4 |
| 116 */ | 142 */ |
| 117 enableTransition: function(enabled) { | 143 enableTransition: function(enabled) { |
| 118 console.warn('`enableTransition()` is deprecated, use `noAnimation` instea
d.'); | 144 Polymer.Base._warn('`enableTransition()` is deprecated, use `noAnimation`
instead.'); |
| 119 this.noAnimation = !enabled; | 145 this.noAnimation = !enabled; |
| 120 }, | 146 }, |
| 121 | 147 |
| 122 _updateTransition: function(enabled) { | 148 _updateTransition: function(enabled) { |
| 123 this.style.transitionDuration = (enabled && !this.noAnimation) ? '' : '0s'
; | 149 this.style.transitionDuration = (enabled && !this.noAnimation) ? '' : '0s'
; |
| 124 }, | 150 }, |
| 125 | 151 |
| 126 _horizontalChanged: function() { | 152 _horizontalChanged: function() { |
| 127 this.style.transitionProperty = this.dimension; | 153 this.style.transitionProperty = this._dimensionMaxCss; |
| 128 var otherDimension = this.dimension === 'width' ? 'height' : 'width'; | 154 var otherDimension = this._dimensionMax === 'maxWidth' ? 'maxHeight' : 'ma
xWidth'; |
| 129 this.style[otherDimension] = ''; | 155 this.style[otherDimension] = ''; |
| 130 this.updateSize(this.opened ? 'auto' : '0px', false); | 156 this.updateSize(this.opened ? 'auto' : '0px', false); |
| 131 }, | 157 }, |
| 132 | 158 |
| 133 _openedChanged: function() { | 159 _openedChanged: function() { |
| 134 this.setAttribute('aria-expanded', this.opened); | 160 this.setAttribute('aria-expanded', this.opened); |
| 135 this.setAttribute('aria-hidden', !this.opened); | 161 this.setAttribute('aria-hidden', !this.opened); |
| 136 | 162 |
| 137 this.toggleClass('iron-collapse-closed', false); | 163 this.toggleClass('iron-collapse-closed', false); |
| 138 this.toggleClass('iron-collapse-opened', false); | 164 this.toggleClass('iron-collapse-opened', false); |
| 139 this.updateSize(this.opened ? 'auto' : '0px', true); | 165 this.updateSize(this.opened ? 'auto' : '0px', true); |
| 140 | 166 |
| 141 // Focus the current collapse. | 167 // Focus the current collapse. |
| 142 if (this.opened) { | 168 if (this.opened) { |
| 143 this.focus(); | 169 this.focus(); |
| 144 } | 170 } |
| 145 if (this.noAnimation) { | 171 if (this.noAnimation) { |
| 146 this._transitionEnd(); | 172 this._transitionEnd(); |
| 147 } | 173 } |
| 148 }, | 174 }, |
| 149 | 175 |
| 150 _transitionEnd: function() { | 176 _transitionEnd: function() { |
| 151 if (this.opened) { | 177 if (this.opened) { |
| 152 this.style[this.dimension] = 'auto'; | 178 this.style[this._dimensionMax] = ''; |
| 153 } | 179 } |
| 154 this.toggleClass('iron-collapse-closed', !this.opened); | 180 this.toggleClass('iron-collapse-closed', !this.opened); |
| 155 this.toggleClass('iron-collapse-opened', this.opened); | 181 this.toggleClass('iron-collapse-opened', this.opened); |
| 156 this._updateTransition(false); | 182 this._updateTransition(false); |
| 157 this.notifyResize(); | 183 this.notifyResize(); |
| 158 }, | 184 }, |
| 159 | 185 |
| 160 /** | 186 /** |
| 161 * Simplistic heuristic to detect if element has a parent with display: none | 187 * Simplistic heuristic to detect if element has a parent with display: none |
| 162 * | 188 * |
| 163 * @private | 189 * @private |
| 164 */ | 190 */ |
| 165 get _isDisplayed() { | 191 get _isDisplayed() { |
| 166 var rect = this.getBoundingClientRect(); | 192 var rect = this.getBoundingClientRect(); |
| 167 for (var prop in rect) { | 193 for (var prop in rect) { |
| 168 if (rect[prop] !== 0) return true; | 194 if (rect[prop] !== 0) return true; |
| 169 } | 195 } |
| 170 return false; | 196 return false; |
| 171 }, | 197 }, |
| 172 | 198 |
| 173 _calcSize: function() { | 199 _calcSize: function() { |
| 174 return this.getBoundingClientRect()[this.dimension] + 'px'; | 200 return this.getBoundingClientRect()[this.dimension] + 'px'; |
| 175 } | 201 } |
| 176 | 202 |
| 177 }); | 203 }); |
| OLD | NEW |