Skip to content

Commit

Permalink
Add window.innerHeight and window.innerWidth to getPageInfo() (#686)
Browse files Browse the repository at this point in the history
* Added innerWidth / innerHeight to getPageInfo().

* Added build artifacts

* Deprecated clientWidth/clientHeight and added documentWidth/documentHeight instead.

* Fixed test
  • Loading branch information
nuschk authored and davidjbradshaw committed Mar 31, 2019
1 parent 4d18970 commit 69ca007
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
9 changes: 7 additions & 2 deletions docs/iframed_page/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ Ask the containing page for its positioning coordinates. You need to provide a c

* **iframeHeight** The height of the iframe in pixels
* **iframeWidth** The width of the iframe in pixels
* **clientHeight** The height of the viewport in pixels
* **clientWidth** The width of the viewport in pixels
* **offsetLeft** The number of pixels between the left edge of the containing page and the left edge of the iframe
* **offsetTop** The number of pixels between the top edge of the containing page and the top edge of the iframe
* **scrollLeft** The number of pixels between the left edge of the iframe and the left edge of the iframe viewport
* **scrollTop** The number of pixels between the top edge of the iframe and the top edge of the iframe viewport
* **documentHeight** The containing document's height in pixels (the equivalent of `document.documentElement.clientHeight` in the container)
* **documentWidth** The containing document's width in pixels (the equivalent of `document.documentElement.clientWidth` in the container)
* **windowHeight** The containing window's height in pixels (the equivalent of `window.innerHeight` in the container)
* **windowWidth** The containing window's width in pixels (the equivalent of `window.innerWidth` in the container)
* **clientHeight** (deprecated) The height of the containing document, considering the viewport, in pixels (`max(documentHeight, windowHeight)`).
* **clientWidth** (deprecated) The width of the containing document, considering the viewport, in pixels (`max(documentWidth, windowWidth)`).


Your callback function will be recalled when the parent page is scrolled or resized.

Expand Down
2 changes: 1 addition & 1 deletion js/iframeResizer.contentWindow.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion js/iframeResizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@
offsetTop: parseInt(iFramePosition.top - bodyPosition.top, 10),
offsetLeft: parseInt(iFramePosition.left - bodyPosition.left, 10),
scrollTop: window.pageYOffset,
scrollLeft: window.pageXOffset
scrollLeft: window.pageXOffset,
documentHeight: document.documentElement.clientHeight,
documentWidth: document.documentElement.clientWidth,
windowHeight: window.innerHeight,
windowWidth: window.innerWidth
})
}

Expand Down
2 changes: 1 addition & 1 deletion js/iframeResizer.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/iframeResizer.min.js

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions spec/childSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,16 @@ define(['iframeResizerContent', 'jquery'], function(mockMsgListener, $) {
win.parentIFrame.getPageInfo(function(pageInfo) {
expect(pageInfo.iframeHeight).toBe(500)
expect(pageInfo.iframeWidth).toBe(300)
expect(pageInfo.clientHeight).toBe(645)
expect(pageInfo.clientWidth).toBe(1295)
expect(pageInfo.offsetLeft).toBe(20)
expect(pageInfo.offsetTop).toBe(85)
expect(pageInfo.scrollTop).toBe(0)
expect(pageInfo.scrollLeft).toBe(0)
expect(pageInfo.documentHeight).toBe(645)
expect(pageInfo.documentWidth).toBe(1295)
expect(pageInfo.windowHeight).toBe(645)
expect(pageInfo.windowWidth).toBe(1295)
expect(pageInfo.clientHeight).toBe(645)
expect(pageInfo.clientWidth).toBe(1295)
done()
})
expect(msgObject.source.postMessage).toHaveBeenCalledWith(
Expand All @@ -161,7 +165,10 @@ define(['iframeResizerContent', 'jquery'], function(mockMsgListener, $) {
)
mockMsgListener(
createMsg(
'pageInfo:{"iframeHeight":500,"iframeWidth":300,"clientHeight":645,"clientWidth":1295,"offsetLeft":20,"offsetTop":85,"scrollLeft":0,"scrollTop":0}'
'pageInfo:{"iframeHeight":500,"iframeWidth":300,"clientHeight":645,' +
'"clientWidth":1295,"offsetLeft":20,"offsetTop":85,"scrollLeft":0,' +
'"scrollTop":0,"documentHeight":645,"documentWidth":1295,' +
'"windowHeight":645,"windowWidth":1295}'
)
)
})
Expand Down
6 changes: 5 additions & 1 deletion src/iframeResizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@
offsetTop: parseInt(iFramePosition.top - bodyPosition.top, 10),
offsetLeft: parseInt(iFramePosition.left - bodyPosition.left, 10),
scrollTop: window.pageYOffset,
scrollLeft: window.pageXOffset
scrollLeft: window.pageXOffset,
documentHeight: document.documentElement.clientHeight,
documentWidth: document.documentElement.clientWidth,
windowHeight: window.innerHeight,
windowWidth: window.innerWidth
})
}

Expand Down

0 comments on commit 69ca007

Please sign in to comment.