Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Use iframe height and width attributes instead offset height and width #88

Merged
merged 2 commits into from Feb 16, 2018
Merged

Use iframe height and width attributes instead offset height and width #88

merged 2 commits into from Feb 16, 2018

Conversation

deansimcox
Copy link
Contributor

This pull request solves an issue with Firefox that I've been having, but I'm guessing it could affect other browsers.

The issue is caused by the iframe having a height of "0" at the time when reframe.js is run. I initially solved this by running reframe on the onload event for the iframe, but this causes the iframe to essentially load twice when reframe does it's DOM manipulation.

This code change will make reframe use the height and with attributes on the iframe instead of getting the offsetHeight and offsetWidth.

@yowainwright
Copy link
Contributor

@deansimcox thanks for the explanation. I will look into this more ASAP!

Copy link
Contributor

@yowainwright yowainwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task before approval, then PR

  • implement ternary
  • update package.json w/ minor patch
  • celebrate!

src/reframe.js Outdated
@@ -18,8 +18,8 @@ export default function reframe(target, cName) {
if (hasClass) return;

// general targeted <element> sizes
const h = frame.offsetHeight;
const w = frame.offsetWidth;
const h = parseInt(frame.getAttribute('height'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a ternary might solve both, the issue you're having and your other note.

In example:

const h = frame.getAttribute('height') !== 'undefined' ? 
  parseInt(frame.getAttribute('height')) : 
  frame.offsetHeight

^ I'm not 100% that that is correct but what about something like that? 😁

@yowainwright
Copy link
Contributor

yowainwright commented Feb 14, 2018

@deansimcox what an awesome and thoughtful CR!

Please make the minor tweaks and then lets ship this! 🚢

@deansimcox
Copy link
Contributor Author

No worries @yowainwright and thanks for the feedback!

I just pushed another commit - I decided to use an if block to check that both height and width are not null.

@yowainwright
Copy link
Contributor

@deansimcox thank you!

Why did you choose statements over expressions?

@deansimcox
Copy link
Contributor Author

@yowainwright It just felt better to store frame.getAttribute('height') in a var then to repeat it twice, happy to change it though?

Copy link
Contributor

@yowainwright yowainwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deansimcox thanks!

I pasted some sample code. That's what I was thinking.

I see what you were saying about repeating getAttribute 2x—even 3x when we consider '%'.

@@ -17,9 +17,22 @@ export default function reframe(target, cName) {
const hasClass = frame.className.split(' ').indexOf(c) !== -1;
if (hasClass) return;

// get height width attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// try to use `offsetSize` if the size attribute is not defined or of it uses a percentage
const shouldUseSzAttr = (a) => !frame.getAttribute(a) || frame.getAttribute(a).toString('%')
const h = shouldUseSzAttr('height') ? frame.offsetHeight : parseInt(frame.getAttribute('height'))
const w = shouldUseSzAttr('width') ? frame.offsetWidth : parseInt(frame.getAttribute('width'))

@yowainwright
Copy link
Contributor

yowainwright commented Feb 16, 2018

@deansimcox thank you for your thoughtful insight. It is because of your insight that I'm going to make some small tweaks besides just your change.

I'm going to merge your PR. There will be a slight tweak very soon after! 🙌 🙏

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants