| OLD | NEW |
| 1 /** | 1 /** |
| 2 Polymer.IronFitBehavior fits an element in another element using `max-height` an
d `max-width`, and | 2 Polymer.IronFitBehavior fits an element in another element using `max-height` an
d `max-width`, and |
| 3 optionally centers it in the window or another element. | 3 optionally centers it in the window or another element. |
| 4 | 4 |
| 5 The element will only be sized and/or positioned if it has not already been size
d and/or positioned | 5 The element will only be sized and/or positioned if it has not already been size
d and/or positioned |
| 6 by CSS. | 6 by CSS. |
| 7 | 7 |
| 8 CSS properties | Action | 8 CSS properties | Action |
| 9 -----------------------------|------------------------------------------- | 9 -----------------------------|------------------------------------------- |
| 10 `position` set | Element is not centered horizontally or verticall
y | 10 `position` set | Element is not centered horizontally or verticall
y |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 left: parseInt(target.marginLeft, 10) || 0 | 150 left: parseInt(target.marginLeft, 10) || 0 |
| 151 } | 151 } |
| 152 }; | 152 }; |
| 153 }, | 153 }, |
| 154 | 154 |
| 155 /** | 155 /** |
| 156 * Resets the target element's position and size constraints, and clear | 156 * Resets the target element's position and size constraints, and clear |
| 157 * the memoized data. | 157 * the memoized data. |
| 158 */ | 158 */ |
| 159 resetFit: function() { | 159 resetFit: function() { |
| 160 if (!this._fitInfo || !this._fitInfo.sizedBy.width) { |
| 161 this.sizingTarget.style.maxWidth = ''; |
| 162 } |
| 160 if (!this._fitInfo || !this._fitInfo.sizedBy.height) { | 163 if (!this._fitInfo || !this._fitInfo.sizedBy.height) { |
| 161 this.sizingTarget.style.maxHeight = ''; | 164 this.sizingTarget.style.maxHeight = ''; |
| 162 this.style.top = this._fitInfo ? this._fitInfo.inlineStyle.top : ''; | |
| 163 } | 165 } |
| 164 if (!this._fitInfo || !this._fitInfo.sizedBy.width) { | 166 this.style.top = this._fitInfo ? this._fitInfo.inlineStyle.top : ''; |
| 165 this.sizingTarget.style.maxWidth = ''; | 167 this.style.left = this._fitInfo ? this._fitInfo.inlineStyle.left : ''; |
| 166 this.style.left = this._fitInfo ? this._fitInfo.inlineStyle.left : ''; | |
| 167 } | |
| 168 if (this._fitInfo) { | 168 if (this._fitInfo) { |
| 169 this.style.position = this._fitInfo.positionedBy.css; | 169 this.style.position = this._fitInfo.positionedBy.css; |
| 170 } | 170 } |
| 171 this._fitInfo = null; | 171 this._fitInfo = null; |
| 172 }, | 172 }, |
| 173 | 173 |
| 174 /** | 174 /** |
| 175 * Equivalent to calling `resetFit()` and `fit()`. Useful to call this after
the element, | 175 * Equivalent to calling `resetFit()` and `fit()`. Useful to call this after
the element, |
| 176 * the window, or the `fitInfo` element has been resized. | 176 * the window, or the `fitInfo` element has been resized. |
| 177 */ | 177 */ |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 var offsetExtent = 'offset' + extent; | 218 var offsetExtent = 'offset' + extent; |
| 219 var sizingOffset = this[offsetExtent] - this.sizingTarget[offsetExtent]; | 219 var sizingOffset = this[offsetExtent] - this.sizingTarget[offsetExtent]; |
| 220 this.sizingTarget.style['max' + extent] = (max - margin - offset - sizingO
ffset) + 'px'; | 220 this.sizingTarget.style['max' + extent] = (max - margin - offset - sizingO
ffset) + 'px'; |
| 221 }, | 221 }, |
| 222 | 222 |
| 223 /** | 223 /** |
| 224 * Centers horizontally and vertically if not already positioned. This also
sets | 224 * Centers horizontally and vertically if not already positioned. This also
sets |
| 225 * `position:fixed`. | 225 * `position:fixed`. |
| 226 */ | 226 */ |
| 227 center: function() { | 227 center: function() { |
| 228 if (!this._fitInfo.positionedBy.vertically || !this._fitInfo.positionedBy.
horizontally) { | 228 var positionedBy = this._fitInfo.positionedBy; |
| 229 // need position:fixed to center | 229 if (positionedBy.vertically && positionedBy.horizontally) { |
| 230 this.style.position = 'fixed'; | 230 // Already positioned. |
| 231 return; |
| 231 } | 232 } |
| 232 if (!this._fitInfo.positionedBy.vertically) { | 233 // Need position:fixed to center |
| 233 var top = (this._fitHeight - this.offsetHeight) / 2 + this._fitTop; | 234 this.style.position = 'fixed'; |
| 234 top -= this._fitInfo.margin.top; | 235 // Take into account the offset caused by parents that create stacking |
| 236 // contexts (e.g. with transform: translate3d). Translate to 0,0 and |
| 237 // measure the bounding rect. |
| 238 if (!positionedBy.vertically) { |
| 239 this.style.top = '0px'; |
| 240 } |
| 241 if (!positionedBy.horizontally) { |
| 242 this.style.left = '0px'; |
| 243 } |
| 244 // It will take in consideration margins and transforms |
| 245 var rect = this.getBoundingClientRect(); |
| 246 if (!positionedBy.vertically) { |
| 247 var top = this._fitTop - rect.top + (this._fitHeight - rect.height) / 2; |
| 235 this.style.top = top + 'px'; | 248 this.style.top = top + 'px'; |
| 236 } | 249 } |
| 237 if (!this._fitInfo.positionedBy.horizontally) { | 250 if (!positionedBy.horizontally) { |
| 238 var left = (this._fitWidth - this.offsetWidth) / 2 + this._fitLeft; | 251 var left = this._fitLeft - rect.left + (this._fitWidth - rect.width) / 2
; |
| 239 left -= this._fitInfo.margin.left; | |
| 240 this.style.left = left + 'px'; | 252 this.style.left = left + 'px'; |
| 241 } | 253 } |
| 242 } | 254 } |
| 243 | 255 |
| 244 }; | 256 }; |
| OLD | NEW |