Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from PolymerElements/fix-inline-positioning-af…
Browse files Browse the repository at this point in the history
…ter-reset

Fix inline positioning after refit
  • Loading branch information
cdata committed Jun 23, 2015
2 parents 87dff23 + 726cca8 commit f552ead
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions iron-fit-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
var target = window.getComputedStyle(this);
var sizer = window.getComputedStyle(this.sizingTarget);
this._fitInfo = {
inlineStyle: {
top: this.style.top || '',
left: this.style.left || ''
},
positionedBy: {
vertically: target.top !== 'auto' ? 'top' : (target.bottom !== 'auto' ?
'bottom' : null),
Expand Down Expand Up @@ -149,11 +153,11 @@
resetFit: function() {
if (!this._fitInfo || !this._fitInfo.sizedBy.height) {
this.sizingTarget.style.maxHeight = '';
this.style.top = '';
this.style.top = this._fitInfo ? this._fitInfo.inlineStyle.top : '';
}
if (!this._fitInfo || !this._fitInfo.sizedBy.width) {
this.sizingTarget.style.maxWidth = '';
this.style.left = '';
this.style.left = this._fitInfo ? this._fitInfo.inlineStyle.left : '';
}
if (this._fitInfo) {
this.style.position = this._fitInfo.positionedBy.css;
Expand Down
17 changes: 12 additions & 5 deletions test/iron-fit-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@

<test-fixture id="inline-positioned-xy">
<template>
<test-fit auto-fit-on-attach class="sized-x sized-y" style="position:absolute;right:100px;bottom:100px;">
<test-fit auto-fit-on-attach class="sized-x sized-y" style="position:absolute;left:100px;top:100px;">
Sized (x/y), positioned/positioned
</test-fit>
</template>
Expand Down Expand Up @@ -170,6 +170,7 @@
var rect = el.getBoundingClientRect();
assert.equal(rect.top, 100, 'top is unset');
assert.equal(rect.left, 100, 'left is unset');

});

test('inline positioned element is not re-positioned', function() {
Expand All @@ -178,15 +179,21 @@
// need to measure document.body here because mocha sets a min-width on html,body, and
// the element is positioned wrt to that by css
var bodyRect = document.body.getBoundingClientRect();
assert.equal(rect.top, bodyRect.height - rect.height - 100, 'top is unset');
assert.equal(rect.left, bodyRect.width - rect.width - 100, 'left is unset');
assert.equal(rect.top, 100, 'top is unset');
assert.equal(rect.left, 100, 'left is unset');

el.refit();

rect = el.getBoundingClientRect();
assert.equal(rect.top, 100, 'top is unset after refit');
assert.equal(rect.left, 100, 'left is unset after refit');

});

test('position property is preserved after', function() {
var el = fixture('absolute');
assert.equal(getComputedStyle(el).position, 'absolute', 'position:absolute is preserved');
})

});
});

suite('fit to window', function() {
Expand Down

0 comments on commit f552ead

Please sign in to comment.