Skip to content

Commit

Permalink
INTEGRATE: Force reflow after resizing frame
Browse files Browse the repository at this point in the history
* dev:
  Update distribution files
  Tweak changelog
  Document reflow fix for 0.14.2 release
  Force reflow after resizing frame (fixes issue #52)
  • Loading branch information
jamesshore committed Apr 10, 2020
2 parents e11717f + f050d9d commit 76e2b77
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Changes are listed by minor version, from newest to oldest. Under each minor ver

*Patches:*

* *0.14.1, 9 Apr 2020:* Bugfix: No longer throw exception when `element.rendered` descriptor sees different values for `overflow-x` and `overflow-y`, or if a compound `overflow` parameter is used.
* *0.14.1, 9 Apr 2020:* Bugfix: No longer throw exception when `element.rendered` descriptor sees different values for `overflow-x` and `overflow-y`, or if a compound `overflow` parameter is used. ([Issue #57.](https://github.com/jamesshore/quixote/issues/57))
* *0.14.2, 9 Apr 2020:* Bugfix: Some browsers would report incorrect font sizes after resizing frame. This was fixed by forcing a reflow after resizing. ([Issue #52.](https://github.com/jamesshore/quixote/issues/52))

**Breaking changes:**

Expand Down
9 changes: 7 additions & 2 deletions dist/quixote.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions example/vendor/quixote.js

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions src/_q_frame_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,49 @@ describe("FOUNDATION: QFrame", function() {
assert.equal(frame.viewport().height.diff(reset.HEIGHT - 100), "", "height");
});

// WORKAROUND IE 11, Edge 18.18362.0
it("forces reflow after resizing frame so media queries take effect (issue #52)", function() {
try {
frame.add(
"<style type='text/css'>" +
".header { font-size: 20px; }" +
"@media (min-width: 640px) {" +
".header { font-size: 40px; }" +
"}" +
"</style>"
);
}
catch (err) {
// WORKAROUND IE 8: Can't add <style> tag, so we just don't run this test.
// Creating a new frame with media query in the CSS might be a better solution, but couldn't figure out
// how to make that work on any browser.
if (err.message.indexOf("Expected one element, but got 0") !== -1) return; // Only IE8 will give this error
else throw err;
}

var element = frame.add("<h1 class=header>hello</h1>");
frame.resize(200, 500);
assert.equal(element.getRawStyle("font-size"), "20px");

frame.resize(800, 500);
assert.equal(element.getRawStyle("font-size"), "40px");
});

// WORKAROUND Safari 13.1.0, Mobile Safari 13.0.4, Chrome Mobile 74.0.3729, Chrome 80.0.3987, IE 11, Edge 18.18362.0
// Works fine on Firefox 75 :-)
it("forces reflow after resizing frame so viewport-relative sizes catch up (issue #52)", function() {
var element = frame.add("<h1 style='font-size: 10vw'>hello</h1>");

// WORKAROUND IE 8: doesn't support viewport-relative sizes, so we don't run this test
if (element.getRawStyle("font-size") === "2em") return; // Only IE8 will say the size is 2em.

frame.resize(200, 500);
assert.equal(element.getRawStyle("font-size"), "20px");

frame.resize(800, 500);
assert.equal(element.getRawStyle("font-size"), "80px");
});

it("resets frame to original size", function() {
frame.resize(reset.WIDTH + 100, reset.HEIGHT + 100);
frame.reset();
Expand Down
2 changes: 1 addition & 1 deletion src/q_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Me.prototype.calculatePixelValue = function(sizeString) {

style.position = "absolute";
style.left = sizeString;
result = parseFloat(this.getRawStyle("left")); // parseInt strips of 'px' value
result = parseFloat(this.getRawStyle("left")); // parseInt strips off 'px' value

style.position = oldPosition;
style.left = oldLeft;
Expand Down
5 changes: 5 additions & 0 deletions src/q_frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,13 @@ Me.prototype.resize = function resize(width, height) {

this._domElement.setAttribute("width", "" + width);
this._domElement.setAttribute("height", "" + height);
forceReflow(this);
};

function forceReflow(self) {
self.body().toDomElement().offsetTop;
}

function ensureUsable(self) {
ensureLoaded(self);
ensureNotRemoved(self);
Expand Down

0 comments on commit 76e2b77

Please sign in to comment.