-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More robust implementation of readBreakpoints() #12
Conversation
At least in Firefox 53, the `body:after` content is updated with the JSON data once a matching media is found in CSS. However, when the viewport is resized and does no longer match *any* of the defined breakpoints, the `.content` reverts to `'none'`, a literal string value. This fails during JSON parsing, effectively leaving the `breakpoint` unchanged. I also had the same issue with IE 11. I did not examine any closer there, but that also disappeared with this change.
Although the symptoms are similar to #10, the cause is different. In FF 53, the |
First of all, thanks for this! If I understand correctly, |
We'd then have... function readBreakpoints() {
if (window.getComputedStyle && (window.getComputedStyle(element, '::after').content !== '')) {
var data = window.getComputedStyle(element, '::after').content;
try {
breakpoints = JSON.parse(removeQuotes(data));
} catch (err) {
breakpoints = false;
}
} else {
breakpoints = false;
}
} @eduardoboucas if you prefer that, I'll ask @megatronCGN to change it |
That would be great, thanks! |
@eduardoboucas done, you're welcome |
include-media.js
Outdated
} else { | ||
breakpoints = false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny detail, could you remove the trailing whitespace here?
Merged, thank you! I'll release to npm now. |
Will do, head over to #11. |
At least in Firefox 53, the
body:after
content is updated with the JSON data once a matching media is found in CSS. However, when the viewport is resized and does no longer match any of the defined breakpoints, the.content
reverts to'none'
, a literal string value. This fails during JSON parsing, effectively leaving thebreakpoint
unchanged.I also had the same issue with IE 11. I did not examine any closer there, but that also disappeared with this change.