Skip to content
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

Iframe not resized when using shadowDom on ResizeWindow Event #772

Closed
martinbelanger opened this issue Nov 6, 2019 · 3 comments
Closed

Comments

@martinbelanger
Copy link

I have an iframe in a shadow dom. (using stencil-js)

I create iFrameResize with the DOM object instead of "css selector" and everything works as expected, except when resizing the main window.

The problem is the use of document.getElementById instead of using the "iframe" object in the iFrameResize settings (iFrameReadyMsgReceived, sendTriggerMsg functions).

function iFrameReadyMsgReceived() {
  // eslint-disable-next-line no-restricted-syntax, guard-for-in
  for (var iframeId in settings) {
    trigger(
      'iFrame requested init',
      createOutgoingMsg(iframeId),
      document.getElementById(iframeId),
      iframeId
    )
  }
}

function sendTriggerMsg(eventName, event) {
    function isIFrameResizeEnabled(iframeId) {
      return (
        settings[iframeId] &&
        'parent' === settings[iframeId].resizeFrom &&
        settings[iframeId].autoResize &&
        !settings[iframeId].firstRun
      )
   }
    Object.keys(settings).forEach(function(iframeId) {
      if (isIFrameResizeEnabled(iframeId)) {
        trigger(eventName, event, document.getElementById(iframeId), iframeId)
      }
    })
}

My fix is to get the "iframe" object in the settings object instead of trying to get the DOM from the document.

var iframeObj = settings[iframeId].iframe;
if(iframeObj == null){
  iframeObj = document.getElementById(iframeId);
}

I'm going to create a pull request to fix it, but would there be any reasons to use getElementById?
If not we can always get it directly from settings[iframeId].iframe

@davidjbradshaw
Copy link
Owner

That sounds good to me, happy to have a look at a PR, could you add a shadow Dom example as part of the PR please

@martinbelanger
Copy link
Author

martinbelanger commented Nov 8, 2019

I create the pull request
#773

But like I wrote in the pull request comment... I spent the last day to try to test it with your automated tests. I don't push the compiled version (only the src modification)

@davidjbradshaw
Copy link
Owner

Released as v4.2.4 - Thanks for the PR

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

No branches or pull requests

2 participants