Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added enyo.dom.calcViewportPositionForNode helper function #185

merged 3 commits into from Dec 13, 2012


None yet
2 participants

onecrayon commented Nov 29, 2012

Here's my calcViewportPositionForNode addition to enyo.dom, as per the discussion here:


Although my use-case for this is pretty specific to my particular app, the function seemed generically useful enough to be worth submitting to Enyo core for consideration.

@onecrayon onecrayon Added enyo.dom.calcViewportPositionForNode as a helper function for l…
…ocating nodes within the viewport (to absolutely position a floating Popup near a particular DOM element, for instance)

Enyo-DCO-1.1-Signed-off-by: Ian Beck <ian@onecrayon.com>

unwiredben commented Dec 5, 2012

Any chance you want to write a test case for this to put into \enyo\tools\test\core\tests? Without it being used elsewhere in core, I'd be afraid it could break without us knowing it.

onecrayon added some commits Dec 12, 2012

@onecrayon onecrayon Modified viewport measuring logic to ensure that it works regardless …
…of whether body element is 100% height/width or has margins

Added enyo.dom.getWindowHeight to compliment getWindowWidth
Enyo-DCO-1.1-Signed-off-by: Ian Beck <ian@onecrayon.com>
@onecrayon onecrayon Added test suite for relative viewport position measuring method in e…

Enyo-DCO-1.1-Signed-off-by: Ian Beck <ian@onecrayon.com>

onecrayon commented Dec 12, 2012

I totally spaced on the request for a test case for some reason, but now here it is! Good thing you had me write that, too, since it caused me to discover an oversight in the measurement logic for pages where the body is not 100% width/height without a scrollbar. :-)


unwiredben commented Dec 12, 2012

Yeah, I find writing tests helps me find corner cases a lot easier than just fixing a problem.

@unwiredben unwiredben added a commit that referenced this pull request Dec 13, 2012

@unwiredben unwiredben Merge pull request #185 from onecrayon/viewport-positioning
Added enyo.dom.calcViewportPositionForNode helper function

Reviewed-By: Ben Combee (ben.combee@palm.com)

@unwiredben unwiredben merged commit 37b1a0c into enyojs:master Dec 13, 2012

@unwiredben unwiredben commented on the diff Dec 13, 2012

@@ -124,5 +138,38 @@ enyo.dom = {
//* Gets the calculated margin of a node.
calcMarginExtents: function(inNode) {
return this.calcBoxExtents(inNode, "margin");
+ },
+ //* Returns an object like `{top: 0, left: 0, bottom: 100, right: 100, height: 10, width: 10}` that represents the object's position within the viewport. Negative values mean part of the object is not visible.
+ calcViewportPositionForNode: function(inNode) {
+ // Parse upward and grab our positioning relative to the viewport
+ var left = top = 0,

unwiredben Dec 13, 2012


just fixed a bug here in master, but wanted to point it out to you -- this doesn't declare a local variable named top, but instead uses a global named top.


onecrayon Dec 13, 2012


Thanks for the FYI! I'm frankly unsure why I used that pattern at all; normally I separate everything into its own comma-delimited assignment. Good to know that the habit has a purpose behind it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment